@@ -41,7 +41,7 @@ use bitcoin::{
41
41
secp256k1:: Secp256k1 ,
42
42
sighash:: { EcdsaSighashType , TapSighashType } ,
43
43
transaction, Address , Amount , Block , BlockHash , FeeRate , Network , OutPoint , Psbt , ScriptBuf ,
44
- Sequence , Transaction , TxOut , Txid , Weight , Witness ,
44
+ Sequence , SignedAmount , Transaction , TxOut , Txid , Weight , Witness ,
45
45
} ;
46
46
use miniscript:: {
47
47
descriptor:: KeyMap ,
@@ -72,7 +72,7 @@ use crate::wallet::{
72
72
error:: { BuildFeeBumpError , CreateTxError , MiniscriptPsbtError } ,
73
73
signer:: { SignOptions , SignerError , SignerOrdering , SignersContainer , TransactionSigner } ,
74
74
tx_builder:: { FeePolicy , TxBuilder , TxParams } ,
75
- utils:: { check_nsequence_rbf, After , Older , SecpCtx } ,
75
+ utils:: { check_nsequence_rbf, After , Older , SecpCtx , TxDetails } ,
76
76
} ;
77
77
78
78
// re-exports
@@ -822,6 +822,33 @@ impl Wallet {
822
822
. map ( |( ( k, i) , full_txo) | new_local_utxo ( k, i, full_txo) )
823
823
}
824
824
825
+ /// Build a [`TxDetails`] struct for a given transaction.
826
+ ///
827
+ /// If the transaction with txid [`Txid`] cannot be found in the wallet's transaction graph,
828
+ /// `None` is returned.
829
+ pub fn get_tx_details ( & self , txid : Txid ) -> Option < TxDetails > {
830
+ let tx: WalletTx = self . transactions ( ) . find ( |c| c. tx_node . txid == txid) ?;
831
+
832
+ let ( sent, received) = self . sent_and_received ( & tx. tx_node . tx ) ;
833
+ let fee: Option < Amount > = self . calculate_fee ( & tx. tx_node . tx ) . ok ( ) ;
834
+ let fee_rate: Option < FeeRate > = self . calculate_fee_rate ( & tx. tx_node . tx ) . ok ( ) ;
835
+ let balance_delta: SignedAmount = self . indexed_graph . index . net_value ( & tx. tx_node . tx , ..) ;
836
+ let chain_position = tx. chain_position ;
837
+
838
+ let tx_details: TxDetails = TxDetails {
839
+ txid,
840
+ received,
841
+ sent,
842
+ fee,
843
+ fee_rate,
844
+ balance_delta,
845
+ chain_position,
846
+ tx : tx. tx_node . tx ,
847
+ } ;
848
+
849
+ Some ( tx_details)
850
+ }
851
+
825
852
/// List all relevant outputs (includes both spent and unspent, confirmed and unconfirmed).
826
853
///
827
854
/// To list only unspent outputs (UTXOs), use [`Wallet::list_unspent`] instead.
0 commit comments