Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterate batching on TxScript #577

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions crypto/txscript/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ impl<'a, T: VerifiableTransaction> TxScriptEngine<'a, T> {
ScriptSource::StandAloneScripts(scripts) => (scripts.clone(), false),
};

// TODO: run all in same iterator?
// When both the signature script and public key script are empty the
// result is necessarily an error since the stack would end up being
// empty which is equivalent to a false top element. Thus, just return
Expand All @@ -281,12 +280,16 @@ impl<'a, T: VerifiableTransaction> TxScriptEngine<'a, T> {
return Err(TxScriptError::NoScripts);
}

if scripts.iter().all(|e| e.is_empty()) {
return Err(TxScriptError::EvalFalse);
}
if let Some(s) = scripts.iter().find(|e| e.len() > MAX_SCRIPTS_SIZE) {
return Err(TxScriptError::ScriptSize(s.len(), MAX_SCRIPTS_SIZE));
}
scripts.iter().try_for_each(|script| {
if script.is_empty() {
return Err(TxScriptError::EvalFalse);
}
if script.len() > MAX_SCRIPTS_SIZE {
return Err(TxScriptError::ScriptSize(script.len(), MAX_SCRIPTS_SIZE));
}
Ok(())
})?;


let mut saved_stack: Option<Vec<Vec<u8>>> = None;
// try_for_each quits only if an error occurred. So, we always run over all scripts if
Expand Down
Loading