From b3188bbac3c64d5bb0277aa1544201475c2cc9b9 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Mon, 6 Feb 2023 12:01:10 +0100 Subject: [PATCH] Add `Transaction` accessors to `SighashCache` It may be useful to access the transaction stored in `SighashCache` during signing or afterwards, especially when the transaction is stored without indirection (to enable long-lived storage). This change adds the appropriate accessors. --- bitcoin/src/sighash.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bitcoin/src/sighash.rs b/bitcoin/src/sighash.rs index b1e842cb..72926d0e 100644 --- a/bitcoin/src/sighash.rs +++ b/bitcoin/src/sighash.rs @@ -499,6 +499,16 @@ impl> SighashCache { SighashCache { tx, common_cache: None, taproot_cache: None, segwit_cache: None } } + /// Returns the reference to the cached transaction. + pub fn transaction(&self) -> &Transaction { + self.tx.borrow() + } + + /// Destroys the cache and recovers the stored transaction. + pub fn into_transaction(self) -> R { + self.tx + } + /// Encodes the BIP341 signing data for any flag type into a given object implementing a /// [`io::Write`] trait. pub fn taproot_encode_signing_data_to>(