From 4f29adf1632087439fca0a4c79bdba0f2513c364 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 23 May 2024 13:02:12 +1000 Subject: [PATCH] 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. ///