Skip to content

Simplification of instruction iterators use by descriptors #133

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

Merged
merged 1 commit into from
Sep 18, 2020
Merged
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
10 changes: 5 additions & 5 deletions src/descriptor/create_descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ use ToPublicKey;
/// NOTE: Miniscript pushes should only be either boolean, 1 or 0, signatures, and hash preimages.
/// As per the current implementation, PUSH_NUM2 results in an error
fn instr_to_stackelem<'txin>(
ins: &Result<Instruction<'txin>, bitcoin::blockdata::script::Error>,
ins: Result<Instruction<'txin>, bitcoin::blockdata::script::Error>,
) -> Result<StackElement<'txin>, Error> {
match *ins {
match ins {
//Also covers the dissatisfied case as PushBytes0
Ok(Instruction::PushBytes(v)) => Ok(StackElement::from(v)),
Ok(Instruction::Op(opcodes::all::OP_PUSHNUM_1)) => Ok(StackElement::Satisfied),
Expand All @@ -42,7 +42,7 @@ fn parse_scriptsig_top<'txin>(
) -> Result<(Vec<u8>, Stack<'txin>), Error> {
let stack: Result<Vec<StackElement>, Error> = script_sig
.instructions_minimal()
.map(|instr| instr_to_stackelem(&instr))
.map(instr_to_stackelem)
.collect();
let mut stack = stack?;
if let Some(StackElement::Push(pk_bytes)) = stack.pop() {
Expand All @@ -64,7 +64,7 @@ fn verify_p2pk<'txin>(
if let Ok(pk) = bitcoin::PublicKey::from_slice(&pk_bytes[1..script_pubkey_len - 1]) {
let stack: Result<Vec<StackElement>, Error> = script_sig
.instructions_minimal()
.map(|instr| instr_to_stackelem(&instr))
.map(instr_to_stackelem)
.collect();
if !witness.is_empty() {
Err(Error::NonEmptyWitness)
Expand Down Expand Up @@ -228,7 +228,7 @@ pub fn from_txin_with_witness_stack<'txin>(
//bare
let stack: Result<Vec<StackElement>, Error> = script_sig
.instructions_minimal()
.map(|instr| instr_to_stackelem(&instr))
.map(instr_to_stackelem)
.collect();
if !witness.is_empty() {
return Err(Error::NonEmptyWitness);
Expand Down