@@ -56,6 +56,15 @@ pub struct TxResponse {
5656 pub raw : Option < String > ,
5757}
5858
59+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
60+ pub struct TxInfo {
61+ pub txid : Txid ,
62+ pub confirmed : bool ,
63+ pub sent : Amount ,
64+ pub received : Amount ,
65+ pub fee : Option < Amount > ,
66+ }
67+
5968#[ derive( Debug , Clone , Serialize , Deserialize ) ]
6069pub struct WalletResponse {
6170 pub result : Vec < TxResponse > ,
@@ -86,6 +95,11 @@ pub enum WalletCommand {
8695 fee_rate : FeeRate ,
8796 resp : crate :: rpc:: Responder < anyhow:: Result < Vec < TxResponse > > > ,
8897 } ,
98+ ListTransactions {
99+ count : usize ,
100+ skip : usize ,
101+ resp : crate :: rpc:: Responder < anyhow:: Result < Vec < TxInfo > > > ,
102+ } ,
89103 ListSpaces {
90104 resp : crate :: rpc:: Responder < anyhow:: Result < Vec < WalletOutput > > > ,
91105 } ,
@@ -291,6 +305,10 @@ impl RpcWallet {
291305 WalletCommand :: ListUnspent { resp } => {
292306 _ = resp. send ( Self :: list_unspent ( wallet, state) ) ;
293307 }
308+ WalletCommand :: ListTransactions { count, skip, resp } => {
309+ let transactions = Self :: list_transactions ( wallet, count, skip) ;
310+ _ = resp. send ( transactions) ;
311+ }
294312 WalletCommand :: ListSpaces { resp } => {
295313 let result = Self :: list_unspent ( wallet, state) ;
296314 match result {
@@ -448,6 +466,36 @@ impl RpcWallet {
448466 Ok ( SpacesAwareCoinSelection :: new ( excluded, confirmed_only) )
449467 }
450468
469+ fn list_transactions (
470+ wallet : & mut SpacesWallet ,
471+ count : usize ,
472+ skip : usize ,
473+ ) -> anyhow:: Result < Vec < TxInfo > > {
474+ let mut transactions: Vec < _ > = wallet. spaces . transactions ( ) . collect ( ) ;
475+ transactions. sort ( ) ;
476+
477+ Ok ( transactions
478+ . iter ( )
479+ . rev ( )
480+ . skip ( skip)
481+ . take ( count)
482+ . map ( |ctx| {
483+ let tx = ctx. tx_node . tx . clone ( ) ;
484+ let txid = ctx. tx_node . txid . clone ( ) ;
485+ let confirmed = ctx. chain_position . is_confirmed ( ) ;
486+ let ( sent, received) = wallet. spaces . sent_and_received ( & tx) ;
487+ let fee = wallet. spaces . calculate_fee ( & tx) . ok ( ) ;
488+ TxInfo {
489+ txid,
490+ confirmed,
491+ sent,
492+ received,
493+ fee,
494+ }
495+ } )
496+ . collect ( ) )
497+ }
498+
451499 fn list_unspent (
452500 wallet : & mut SpacesWallet ,
453501 store : & mut LiveSnapshot ,
@@ -884,6 +932,18 @@ impl RpcWallet {
884932 resp_rx. await ?
885933 }
886934
935+ pub async fn send_list_transactions (
936+ & self ,
937+ count : usize ,
938+ skip : usize ,
939+ ) -> anyhow:: Result < Vec < TxInfo > > {
940+ let ( resp, resp_rx) = oneshot:: channel ( ) ;
941+ self . sender
942+ . send ( WalletCommand :: ListTransactions { count, skip, resp } )
943+ . await ?;
944+ resp_rx. await ?
945+ }
946+
887947 pub async fn send_force_spend (
888948 & self ,
889949 outpoint : OutPoint ,
0 commit comments