From 4e73a0da5ed9d82b3c4b0ddd5249a85c728e45dd Mon Sep 17 00:00:00 2001 From: spacebear Date: Mon, 25 Nov 2024 19:30:48 -0500 Subject: [PATCH 1/2] Upgrade `rust-bitcoin` to 0.32.4 --- Cargo-minimal.lock | 4 ++-- Cargo-recent.lock | 4 ++-- payjoin-directory/Cargo.toml | 2 +- payjoin/Cargo.toml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo-minimal.lock b/Cargo-minimal.lock index 054ef62c..adc611bd 100644 --- a/Cargo-minimal.lock +++ b/Cargo-minimal.lock @@ -217,9 +217,9 @@ dependencies = [ [[package]] name = "bitcoin" -version = "0.32.2" +version = "0.32.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea507acc1cd80fc084ace38544bbcf7ced7c2aa65b653b102de0ce718df668f6" +checksum = "788902099d47c8682efe6a7afb01c8d58b9794ba66c06affd81c3d6b560743eb" dependencies = [ "base58ck", "base64 0.21.7", diff --git a/Cargo-recent.lock b/Cargo-recent.lock index 054ef62c..adc611bd 100644 --- a/Cargo-recent.lock +++ b/Cargo-recent.lock @@ -217,9 +217,9 @@ dependencies = [ [[package]] name = "bitcoin" -version = "0.32.2" +version = "0.32.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea507acc1cd80fc084ace38544bbcf7ced7c2aa65b653b102de0ce718df668f6" +checksum = "788902099d47c8682efe6a7afb01c8d58b9794ba66c06affd81c3d6b560743eb" dependencies = [ "base58ck", "base64 0.21.7", diff --git a/payjoin-directory/Cargo.toml b/payjoin-directory/Cargo.toml index 051e8a65..0735fc15 100644 --- a/payjoin-directory/Cargo.toml +++ b/payjoin-directory/Cargo.toml @@ -18,7 +18,7 @@ danger-local-https = ["hyper-rustls", "rustls", "tokio-rustls"] [dependencies] anyhow = "1.0.71" -bitcoin = { version = "0.32.2", features = ["base64"] } +bitcoin = { version = "0.32.4", features = ["base64"] } bhttp = { version = "=0.5.1", features = ["http"] } futures = "0.3.17" http-body-util = "0.1.2" diff --git a/payjoin/Cargo.toml b/payjoin/Cargo.toml index 8412086b..ff503aa5 100644 --- a/payjoin/Cargo.toml +++ b/payjoin/Cargo.toml @@ -24,7 +24,7 @@ io = ["reqwest/rustls-tls"] danger-local-https = ["io", "reqwest/rustls-tls", "rustls"] [dependencies] -bitcoin = { version = "0.32.2", features = ["base64"] } +bitcoin = { version = "0.32.4", features = ["base64"] } bip21 = "0.5.0" hpke = { package = "bitcoin-hpke", version = "0.13.0", optional = true } log = { version = "0.4.14"} From a4a67ecb7abcc08a92f754db1a3f1c226b02508f Mon Sep 17 00:00:00 2001 From: spacebear Date: Mon, 25 Nov 2024 19:41:46 -0500 Subject: [PATCH 2/2] Use `Script::redeem_script` Upstream redeem_script getter. --- payjoin/src/psbt.rs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/payjoin/src/psbt.rs b/payjoin/src/psbt.rs index 46b6cdf1..a051fa80 100644 --- a/payjoin/src/psbt.rs +++ b/payjoin/src/psbt.rs @@ -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 { @@ -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: = 72, 33 bytes // https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#p2wpkh-nested-in-bip16-p2sh @@ -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())