@@ -10,6 +10,7 @@ use log::{info, warn};
1010use protocol:: { bitcoin:: Txid , constants:: ChainAnchor , hasher:: { KeyHasher , SpaceKey } , script:: SpaceScript , slabel:: SLabel , FullSpaceOut , SpaceOut } ;
1111use serde:: { Deserialize , Serialize } ;
1212use serde_json:: json;
13+ use tabled:: Tabled ;
1314use tokio:: {
1415 select,
1516 sync:: { broadcast, mpsc, mpsc:: Receiver , oneshot} ,
@@ -45,16 +46,37 @@ pub struct ListSpacesResponse {
4546 pub owned : Vec < FullSpaceOut > ,
4647}
4748
48- #[ derive( Debug , Clone , Serialize , Deserialize ) ]
49+
50+ #[ derive( Tabled , Debug , Clone , Serialize , Deserialize ) ]
51+ #[ tabled( rename_all = "UPPERCASE" ) ]
4952pub struct TxInfo {
5053 pub txid : Txid ,
5154 pub confirmed : bool ,
5255 pub sent : Amount ,
5356 pub received : Amount ,
57+ #[ tabled( display_with = "display_fee" ) ]
5458 pub fee : Option < Amount > ,
59+ #[ tabled( rename = "DETAILS" , display_with = "display_events" ) ]
5560 pub events : Vec < TxEvent > ,
5661}
5762
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+
5880#[ derive( Debug , Clone , Serialize , Deserialize ) ]
5981pub struct WalletResponse {
6082 pub result : Vec < TxResponse > ,
@@ -429,7 +451,7 @@ impl RpcWallet {
429451 mut state : LiveSnapshot ,
430452 mut wallet : SpacesWallet ,
431453 mut commands : Receiver < WalletCommand > ,
432- mut shutdown : broadcast:: Receiver < ( ) > ,
454+ shutdown : broadcast:: Sender < ( ) > ,
433455 num_workers : usize ,
434456 ) -> anyhow:: Result < ( ) > {
435457 let ( fetcher, receiver) = BlockFetcher :: new ( source. clone ( ) , num_workers) ;
@@ -442,11 +464,12 @@ impl RpcWallet {
442464 }
443465 } ;
444466
467+ let mut shutdown_recv = shutdown. subscribe ( ) ;
445468 fetcher. start ( wallet_tip) ;
446469 let mut synced_at_least_once = false ;
447470 let mut last_mempool_check = Instant :: now ( ) ;
448471 loop {
449- if shutdown . try_recv ( ) . is_ok ( ) {
472+ if shutdown_recv . try_recv ( ) . is_ok ( ) {
450473 info ! ( "Shutting down wallet sync" ) ;
451474 break ;
452475 }
@@ -542,7 +565,8 @@ impl RpcWallet {
542565 }
543566 BlockEvent :: Error ( e) => {
544567 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 ) ) ;
546570 fetcher. restart ( wallet_tip, & receiver) ;
547571 }
548572 }
@@ -1091,7 +1115,7 @@ impl RpcWallet {
10911115 let wallet_name = loaded. export. label. clone( ) ;
10921116 let wallet_chain = store. clone( ) ;
10931117 let rpc = rpc. clone( ) ;
1094- let wallet_shutdown = shutdown. subscribe ( ) ;
1118+ let wallet_shutdown = shutdown. clone ( ) ;
10951119 let ( tx, rx) = oneshot:: channel( ) ;
10961120
10971121 std:: thread:: spawn( move || {
0 commit comments