From 4f29adf1632087439fca0a4c79bdba0f2513c364 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 23 May 2024 13:02:12 +1000 Subject: [PATCH 1/2] Enable getting the witness program from an address We have getters for the pubkey hash and script hash but we forgot one for the witness program - add it. --- bitcoin/src/address/mod.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bitcoin/src/address/mod.rs b/bitcoin/src/address/mod.rs index 89658144b..c2cdb9ccd 100644 --- a/bitcoin/src/address/mod.rs +++ b/bitcoin/src/address/mod.rs @@ -490,6 +490,16 @@ impl Address { } } + /// Gets the witness program for this address if this is a segwit address. + pub fn witness_program(&self) -> Option { + use AddressInner::*; + + match self.0 { + Segwit { ref program, hrp: _ } => Some(*program), + _ => None, + } + } + /// Checks whether or not the address is following Bitcoin standardness rules when /// *spending* from this address. *NOT* to be called by senders. /// From 7f29313d360c3d0f2cc145a12b20a62af6f5613c Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 23 May 2024 13:04:22 +1000 Subject: [PATCH 2/2] Update API --- api/bitcoin/all-features.txt | 1 + api/bitcoin/default-features.txt | 1 + api/bitcoin/no-features.txt | 1 + 3 files changed, 3 insertions(+) diff --git a/api/bitcoin/all-features.txt b/api/bitcoin/all-features.txt index 95a72b91d..31b4d1e65 100644 --- a/api/bitcoin/all-features.txt +++ b/api/bitcoin/all-features.txt @@ -7129,6 +7129,7 @@ pub fn bitcoin::address::Address::pubkey_hash(&self) -> core::option::Option core::option::Option pub fn bitcoin::address::Address::script_pubkey(&self) -> bitcoin::blockdata::script::ScriptBuf pub fn bitcoin::address::Address::to_qr_uri(&self) -> alloc::string::String +pub fn bitcoin::address::Address::witness_program(&self) -> core::option::Option pub fn bitcoin::address::Address::serialize(&self, serializer: S) -> core::result::Result<::Ok, ::Error> where S: serde::ser::Serializer pub fn bitcoin::address::Address::as_unchecked(&self) -> &bitcoin::address::Address pub fn bitcoin::address::Address::clone(&self) -> bitcoin::address::Address diff --git a/api/bitcoin/default-features.txt b/api/bitcoin/default-features.txt index 1d4fab2bc..5e7768fb8 100644 --- a/api/bitcoin/default-features.txt +++ b/api/bitcoin/default-features.txt @@ -6797,6 +6797,7 @@ pub fn bitcoin::address::Address::pubkey_hash(&self) -> core::option::Option core::option::Option pub fn bitcoin::address::Address::script_pubkey(&self) -> bitcoin::blockdata::script::ScriptBuf pub fn bitcoin::address::Address::to_qr_uri(&self) -> alloc::string::String +pub fn bitcoin::address::Address::witness_program(&self) -> core::option::Option pub fn bitcoin::address::Address::as_unchecked(&self) -> &bitcoin::address::Address pub fn bitcoin::address::Address::clone(&self) -> bitcoin::address::Address pub fn bitcoin::address::Address::cmp(&self, other: &bitcoin::address::Address) -> core::cmp::Ordering diff --git a/api/bitcoin/no-features.txt b/api/bitcoin/no-features.txt index 3e1e22a3c..6ed164072 100644 --- a/api/bitcoin/no-features.txt +++ b/api/bitcoin/no-features.txt @@ -6164,6 +6164,7 @@ pub fn bitcoin::address::Address::pubkey_hash(&self) -> core::option::Option core::option::Option pub fn bitcoin::address::Address::script_pubkey(&self) -> bitcoin::blockdata::script::ScriptBuf pub fn bitcoin::address::Address::to_qr_uri(&self) -> alloc::string::String +pub fn bitcoin::address::Address::witness_program(&self) -> core::option::Option pub fn bitcoin::address::Address::as_unchecked(&self) -> &bitcoin::address::Address pub fn bitcoin::address::Address::clone(&self) -> bitcoin::address::Address pub fn bitcoin::address::Address::cmp(&self, other: &bitcoin::address::Address) -> core::cmp::Ordering