@@ -10,6 +10,7 @@ use log::{info, warn};
10
10
use protocol:: { bitcoin:: Txid , constants:: ChainAnchor , hasher:: { KeyHasher , SpaceKey } , script:: SpaceScript , slabel:: SLabel , FullSpaceOut , SpaceOut } ;
11
11
use serde:: { Deserialize , Serialize } ;
12
12
use serde_json:: json;
13
+ use tabled:: Tabled ;
13
14
use tokio:: {
14
15
select,
15
16
sync:: { broadcast, mpsc, mpsc:: Receiver , oneshot} ,
@@ -45,16 +46,37 @@ pub struct ListSpacesResponse {
45
46
pub owned : Vec < FullSpaceOut > ,
46
47
}
47
48
48
- #[ derive( Debug , Clone , Serialize , Deserialize ) ]
49
+
50
+ #[ derive( Tabled , Debug , Clone , Serialize , Deserialize ) ]
51
+ #[ tabled( rename_all = "UPPERCASE" ) ]
49
52
pub struct TxInfo {
50
53
pub txid : Txid ,
51
54
pub confirmed : bool ,
52
55
pub sent : Amount ,
53
56
pub received : Amount ,
57
+ #[ tabled( display_with = "display_fee" ) ]
54
58
pub fee : Option < Amount > ,
59
+ #[ tabled( rename = "DETAILS" , display_with = "display_events" ) ]
55
60
pub events : Vec < TxEvent > ,
56
61
}
57
62
63
+ fn display_fee ( fee : & Option < Amount > ) -> String {
64
+ match fee {
65
+ None => "--" . to_string ( ) ,
66
+ Some ( fee) => fee. to_string ( )
67
+ }
68
+ }
69
+
70
+ fn display_events ( events : & Vec < TxEvent > ) -> String {
71
+ events
72
+ . iter ( )
73
+ . map ( |e|
74
+ format ! ( "{} {}" ,
75
+ e. kind,
76
+ e. space. as_ref( ) . map( |s| s. clone( ) ) . unwrap_or( "" . to_string( ) ) ) )
77
+ . collect :: < Vec < String > > ( ) . join ( "\n " )
78
+ }
79
+
58
80
#[ derive( Debug , Clone , Serialize , Deserialize ) ]
59
81
pub struct WalletResponse {
60
82
pub result : Vec < TxResponse > ,
@@ -429,7 +451,7 @@ impl RpcWallet {
429
451
mut state : LiveSnapshot ,
430
452
mut wallet : SpacesWallet ,
431
453
mut commands : Receiver < WalletCommand > ,
432
- mut shutdown : broadcast:: Receiver < ( ) > ,
454
+ shutdown : broadcast:: Sender < ( ) > ,
433
455
num_workers : usize ,
434
456
) -> anyhow:: Result < ( ) > {
435
457
let ( fetcher, receiver) = BlockFetcher :: new ( source. clone ( ) , num_workers) ;
@@ -442,11 +464,12 @@ impl RpcWallet {
442
464
}
443
465
} ;
444
466
467
+ let mut shutdown_recv = shutdown. subscribe ( ) ;
445
468
fetcher. start ( wallet_tip) ;
446
469
let mut synced_at_least_once = false ;
447
470
let mut last_mempool_check = Instant :: now ( ) ;
448
471
loop {
449
- if shutdown . try_recv ( ) . is_ok ( ) {
472
+ if shutdown_recv . try_recv ( ) . is_ok ( ) {
450
473
info ! ( "Shutting down wallet sync" ) ;
451
474
break ;
452
475
}
@@ -542,7 +565,8 @@ impl RpcWallet {
542
565
}
543
566
BlockEvent :: Error ( e) => {
544
567
warn ! ( "Fetcher: {} - retrying in 1s" , e) ;
545
- std_wait ( || shutdown. try_recv ( ) . is_ok ( ) , Duration :: from_secs ( 1 ) ) ;
568
+ let mut wait_recv = shutdown. subscribe ( ) ;
569
+ std_wait ( || wait_recv. try_recv ( ) . is_ok ( ) , Duration :: from_secs ( 1 ) ) ;
546
570
fetcher. restart ( wallet_tip, & receiver) ;
547
571
}
548
572
}
@@ -1091,7 +1115,7 @@ impl RpcWallet {
1091
1115
let wallet_name = loaded. export. label. clone( ) ;
1092
1116
let wallet_chain = store. clone( ) ;
1093
1117
let rpc = rpc. clone( ) ;
1094
- let wallet_shutdown = shutdown. subscribe ( ) ;
1118
+ let wallet_shutdown = shutdown. clone ( ) ;
1095
1119
let ( tx, rx) = oneshot:: channel( ) ;
1096
1120
1097
1121
std:: thread:: spawn( move || {
0 commit comments