Skip to content

Commit

Permalink
Use Script::redeem_script
Browse files Browse the repository at this point in the history
Upstream redeem_script getter.
  • Loading branch information
spacebear21 committed Nov 26, 2024
1 parent 4e73a0d commit a4a67ec
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions payjoin/src/psbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ use std::collections::BTreeMap;
use std::fmt;

use bitcoin::address::FromScriptError;
use bitcoin::blockdata::script::Instruction;
use bitcoin::psbt::Psbt;
use bitcoin::transaction::InputWeightPrediction;
use bitcoin::{bip32, psbt, Address, AddressType, Network, Script, TxIn, TxOut, Weight};
use bitcoin::{bip32, psbt, Address, AddressType, Network, TxIn, TxOut, Weight};

#[derive(Debug)]
pub(crate) enum InconsistentPsbt {
Expand Down Expand Up @@ -93,14 +92,6 @@ impl PsbtExt for Psbt {
}
}

/// Gets redeemScript from the script_sig following BIP16 rules regarding P2SH spending.
fn redeem_script(script_sig: &Script) -> Option<&Script> {
match script_sig.instructions().last()?.ok()? {
Instruction::PushBytes(bytes) => Some(Script::from_bytes(bytes.as_bytes())),
Instruction::Op(_) => None,
}
}

// input script: 0x160014{20-byte-key-hash} = 23 bytes
// witness: <signature> <pubkey> = 72, 33 bytes
// https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#p2wpkh-nested-in-bip16-p2sh
Expand Down Expand Up @@ -202,7 +193,7 @@ impl InternalInputPair<'_> {
P2sh => {
// redeemScript can be extracted from scriptSig for signed P2SH inputs
let redeem_script = if let Some(ref script_sig) = self.psbtin.final_script_sig {
redeem_script(script_sig)
script_sig.redeem_script()
// try the PSBT redeem_script field for unsigned inputs.
} else {
self.psbtin.redeem_script.as_ref().map(|script| script.as_ref())
Expand Down

0 comments on commit a4a67ec

Please sign in to comment.