@@ -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
@@ -821,6 +821,45 @@ impl Wallet {
821
821
. map ( |( ( k, i) , full_txo) | new_local_utxo ( k, i, full_txo) )
822
822
}
823
823
824
+ /// Build a [`TxDetails`] struct for a given transaction.
825
+ ///
826
+ /// If the transaction with txid [`Txid`] cannot be found in the wallet's transaction graph,
827
+ /// None is returned.
828
+ // #[cfg(feature = "std")]
829
+ pub fn get_tx_details ( & self , txid : Txid ) -> Option < TxDetails > {
830
+ let tx_graph = self . indexed_graph . graph ( ) ;
831
+ let tx_index = & self . indexed_graph . index ;
832
+
833
+ // It should be impossible to have more than 1 right? In which case I can use the `find()`
834
+ // method on the collection instead of collecting into a vector.
835
+
836
+ // This relies on the impossibility of having 2 transactions with the same Txid in the list
837
+ // canonical transactions but let me know if this is wrong!
838
+ let optional_tx: Option < CanonicalTx < Arc < Transaction > , ConfirmationBlockTime > > = tx_graph
839
+ . list_canonical_txs ( & self . chain , self . chain . tip ( ) . block_id ( ) )
840
+ . filter ( |c_tx| tx_index. is_tx_relevant ( & c_tx. tx_node . tx ) )
841
+ . find ( |tx| tx. tx_node . compute_txid ( ) == txid) ;
842
+
843
+ let tx = optional_tx?;
844
+
845
+ let ( sent, received) = self . sent_and_received ( & tx. tx_node . tx ) ;
846
+ let fee = self . calculate_fee ( & tx. tx_node . tx ) . unwrap ( ) ;
847
+ let fee_rate = self . calculate_fee_rate ( & tx. tx_node . tx ) . unwrap ( ) ;
848
+ let chain_position = tx. chain_position ;
849
+
850
+ let tx_details: TxDetails = TxDetails {
851
+ txid,
852
+ received,
853
+ sent,
854
+ fee,
855
+ fee_rate,
856
+ chain_position,
857
+ tx : tx. tx_node . tx ,
858
+ } ;
859
+
860
+ Some ( tx_details)
861
+ }
862
+
824
863
/// List all relevant outputs (includes both spent and unspent, confirmed and unconfirmed).
825
864
///
826
865
/// To list only unspent outputs (UTXOs), use [`Wallet::list_unspent`] instead.
0 commit comments