@@ -20,13 +20,12 @@ use tokio::{
20
20
} ;
21
21
use wallet:: {
22
22
address:: SpaceAddress ,
23
- bdk_wallet,
24
23
bdk_wallet:: {
24
+ self ,
25
25
chain:: { local_chain:: CheckPoint , BlockId } ,
26
26
KeychainKind , LocalOutput ,
27
27
} ,
28
- bitcoin,
29
- bitcoin:: { Address , Amount , FeeRate } ,
28
+ bitcoin:: { self , Address , Amount , FeeRate } ,
30
29
builder:: {
31
30
CoinTransfer , SpaceTransfer , SpacesAwareCoinSelection , TransactionTag , TransferRequest ,
32
31
} ,
@@ -51,6 +50,12 @@ pub struct TxResponse {
51
50
pub error : Option < BTreeMap < String , String > > ,
52
51
}
53
52
53
+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
54
+ pub struct TxInfo {
55
+ pub txid : Txid ,
56
+ pub confirmed : bool ,
57
+ }
58
+
54
59
#[ derive( Debug , Clone , Serialize , Deserialize ) ]
55
60
pub struct WalletResponse {
56
61
pub sent : Vec < TxResponse > ,
@@ -83,6 +88,11 @@ pub enum WalletCommand {
83
88
fee_rate : FeeRate ,
84
89
resp : crate :: rpc:: Responder < anyhow:: Result < Vec < TxResponse > > > ,
85
90
} ,
91
+ ListTransactions {
92
+ count : usize ,
93
+ skip : usize ,
94
+ resp : crate :: rpc:: Responder < anyhow:: Result < Vec < TxInfo > > > ,
95
+ } ,
86
96
ListSpaces {
87
97
resp : crate :: rpc:: Responder < anyhow:: Result < Vec < WalletOutput > > > ,
88
98
} ,
@@ -154,8 +164,10 @@ impl RpcWallet {
154
164
balance,
155
165
dust : unspent
156
166
. into_iter ( )
157
- . filter ( |output| output. is_spaceout ||
158
- output. output . txout . value <= SpacesAwareCoinSelection :: DUST_THRESHOLD )
167
+ . filter ( |output| {
168
+ output. is_spaceout
169
+ || output. output . txout . value <= SpacesAwareCoinSelection :: DUST_THRESHOLD
170
+ } )
159
171
. map ( |output| output. output . txout . value )
160
172
. sum ( ) ,
161
173
} ;
@@ -224,6 +236,10 @@ impl RpcWallet {
224
236
WalletCommand :: ListUnspent { resp } => {
225
237
_ = resp. send ( Self :: list_unspent ( wallet, state) ) ;
226
238
}
239
+ WalletCommand :: ListTransactions { count, skip, resp } => {
240
+ let transactions = Self :: list_transactions ( wallet, count, skip) ;
241
+ _ = resp. send ( transactions) ;
242
+ }
227
243
WalletCommand :: ListSpaces { resp } => {
228
244
let result = Self :: list_unspent ( wallet, state) ;
229
245
match result {
@@ -375,6 +391,26 @@ impl RpcWallet {
375
391
Ok ( SpacesAwareCoinSelection :: new ( excluded) )
376
392
}
377
393
394
+ fn list_transactions (
395
+ wallet : & mut SpacesWallet ,
396
+ count : usize ,
397
+ skip : usize ,
398
+ ) -> anyhow:: Result < Vec < TxInfo > > {
399
+ let transactions = wallet
400
+ . spaces
401
+ . transactions ( )
402
+ . into_iter ( )
403
+ . skip ( skip)
404
+ . take ( count)
405
+ . map ( |tx| {
406
+ let txid = tx. tx_node . txid . clone ( ) ;
407
+ let confirmed = tx. chain_position . is_confirmed ( ) ;
408
+ TxInfo { txid, confirmed }
409
+ } )
410
+ . collect ( ) ;
411
+ Ok ( transactions)
412
+ }
413
+
378
414
fn list_unspent (
379
415
wallet : & mut SpacesWallet ,
380
416
store : & mut LiveSnapshot ,
@@ -446,8 +482,10 @@ impl RpcWallet {
446
482
if dust > SpacesAwareCoinSelection :: DUST_THRESHOLD {
447
483
// Allowing higher dust may space outs to be accidentally
448
484
// spent during coin selection
449
- return Err ( anyhow ! ( "dust cannot be higher than {}" ,
450
- SpacesAwareCoinSelection :: DUST_THRESHOLD ) ) ;
485
+ return Err ( anyhow ! (
486
+ "dust cannot be higher than {}" ,
487
+ SpacesAwareCoinSelection :: DUST_THRESHOLD
488
+ ) ) ;
451
489
}
452
490
}
453
491
@@ -789,6 +827,18 @@ impl RpcWallet {
789
827
resp_rx. await ?
790
828
}
791
829
830
+ pub async fn send_list_transactions (
831
+ & self ,
832
+ count : usize ,
833
+ skip : usize ,
834
+ ) -> anyhow:: Result < Vec < TxInfo > > {
835
+ let ( resp, resp_rx) = oneshot:: channel ( ) ;
836
+ self . sender
837
+ . send ( WalletCommand :: ListTransactions { count, skip, resp } )
838
+ . await ?;
839
+ resp_rx. await ?
840
+ }
841
+
792
842
pub async fn send_list_spaces ( & self ) -> anyhow:: Result < Vec < WalletOutput > > {
793
843
let ( resp, resp_rx) = oneshot:: channel ( ) ;
794
844
self . sender . send ( WalletCommand :: ListSpaces { resp } ) . await ?;
0 commit comments