11use std:: {
2+ cmp:: Reverse ,
23 collections:: { BTreeSet , HashMap , HashSet } ,
34 convert:: TryFrom ,
45 fmt,
@@ -36,13 +37,14 @@ use witnet_data_structures::{
3637 versioning:: { ProtocolInfo , ProtocolVersion } ,
3738 ProtobufConvert ,
3839 } ,
40+ staking:: prelude:: StakeEntry ,
3941 transaction:: {
4042 DRTransaction , StakeTransaction , Transaction , UnstakeTransaction , VTTransaction ,
4143 } ,
4244 transaction_factory:: NodeBalance ,
4345 types:: SequentialId ,
4446 utxo_pool:: { UtxoInfo , UtxoSelectionStrategy } ,
45- wit:: Wit ,
47+ wit:: { Wit , WIT_DECIMAL_PLACES } ,
4648} ;
4749use witnet_node:: actors:: {
4850 chain_manager:: run_dr_locally,
@@ -1949,6 +1951,7 @@ pub fn query_stakes(
19491951 validator : Option < String > ,
19501952 withdrawer : Option < String > ,
19511953 all : bool ,
1954+ long : bool ,
19521955) -> Result < ( ) , failure:: Error > {
19531956 let mut stream = start_client ( addr) ?;
19541957 let params = if all {
@@ -1971,7 +1974,37 @@ pub fn query_stakes(
19711974 serde_json:: to_string( & params) . unwrap( )
19721975 ) ,
19731976 ) ?;
1974- log:: info!( "{}" , response) ;
1977+
1978+ let mut stakes: Vec < StakeEntry < WIT_DECIMAL_PLACES , PublicKeyHash , Wit , Epoch , u64 , u64 > > =
1979+ parse_response ( & response) ?;
1980+ stakes. sort_by_key ( |stake| Reverse ( stake. value . coins ) ) ;
1981+
1982+ let mut stakes_table = Table :: new ( ) ;
1983+ stakes_table. set_format ( * prettytable:: format:: consts:: FORMAT_NO_BORDER_LINE_SEPARATOR ) ;
1984+ if long {
1985+ stakes_table. set_titles ( row ! [ c->"Validator" , c->"Withdrawer" , c->"Staked" , c->"Mining Epoch" , c->"Witnessing Epoch" , c->"Nonce" ] ) ;
1986+ for stake in stakes {
1987+ stakes_table. add_row ( row ! [
1988+ stake. key. validator,
1989+ stake. key. withdrawer,
1990+ r->whole_wits( stake. value. coins. into( ) ) . to_formatted_string( & Locale :: en) ,
1991+ r->stake. value. epochs. mining. to_formatted_string( & Locale :: en) ,
1992+ r->stake. value. epochs. witnessing. to_formatted_string( & Locale :: en) ,
1993+ r->stake. value. nonce. to_formatted_string( & Locale :: en) ,
1994+ ] ) ;
1995+ }
1996+ } else {
1997+ stakes_table. set_titles ( row ! [ c->"Validator" , c->"Withdrawer" , c->"Staked" ] ) ;
1998+ for stake in stakes {
1999+ stakes_table. add_row ( row ! [
2000+ stake. key. validator,
2001+ stake. key. withdrawer,
2002+ r->whole_wits( stake. value. coins. into( ) ) . to_formatted_string( & Locale :: en) ,
2003+ ] ) ;
2004+ }
2005+ }
2006+ stakes_table. printstd ( ) ;
2007+ println ! ( ) ;
19752008
19762009 Ok ( ( ) )
19772010}
0 commit comments