@@ -19,6 +19,8 @@ namespace Neo.Shell
19
19
{
20
20
internal class MainService : ConsoleServiceBase
21
21
{
22
+ private const string PeerStatePath = "peers.dat" ;
23
+
22
24
private RpcServerWithWallet rpc ;
23
25
private ConsensusWithPolicy consensus ;
24
26
@@ -265,10 +267,12 @@ private bool OnHelpCommand(string[] args)
265
267
"Wallet Commands:\n " +
266
268
"\t create wallet <path>\n " +
267
269
"\t open wallet <path>\n " +
270
+ "\t upgrade wallet <path>\n " +
268
271
"\t rebuild index\n " +
269
272
"\t list address\n " +
270
273
"\t list asset\n " +
271
274
"\t list key\n " +
275
+ "\t show utxo [id|alias]\n " +
272
276
"\t show gas\n " +
273
277
"\t claim gas\n " +
274
278
"\t create address [n=1]\n " +
@@ -279,8 +283,10 @@ private bool OnHelpCommand(string[] args)
279
283
"\t show state\n " +
280
284
"\t show node\n " +
281
285
"\t show pool\n " +
286
+ "\t export blocks [path=chain.acc]\n " +
282
287
"Advanced Commands:\n " +
283
- "\t start consensus\n " ) ;
288
+ "\t start consensus\n " +
289
+ "\t refresh policy\n " ) ;
284
290
return true ;
285
291
}
286
292
@@ -604,6 +610,8 @@ private bool OnShowCommand(string[] args)
604
610
return OnShowPoolCommand ( args ) ;
605
611
case "state" :
606
612
return OnShowStateCommand ( args ) ;
613
+ case "utxo" :
614
+ return OnShowUtxoCommand ( args ) ;
607
615
default :
608
616
return base . OnCommand ( args ) ;
609
617
}
@@ -634,9 +642,51 @@ private bool OnShowStateCommand(string[] args)
634
642
return true ;
635
643
}
636
644
645
+ private bool OnShowUtxoCommand ( string [ ] args )
646
+ {
647
+ if ( Program . Wallet == null )
648
+ {
649
+ Console . WriteLine ( "You have to open the wallet first." ) ;
650
+ return true ;
651
+ }
652
+ IEnumerable < Coin > coins = Program . Wallet . FindUnspentCoins ( ) ;
653
+ if ( args . Length >= 3 )
654
+ {
655
+ UInt256 assetId ;
656
+ switch ( args [ 2 ] . ToLower ( ) )
657
+ {
658
+ case "neo" :
659
+ case "ans" :
660
+ assetId = Blockchain . SystemShare . Hash ;
661
+ break ;
662
+ case "gas" :
663
+ case "anc" :
664
+ assetId = Blockchain . SystemCoin . Hash ;
665
+ break ;
666
+ default :
667
+ assetId = UInt256 . Parse ( args [ 2 ] ) ;
668
+ break ;
669
+ }
670
+ coins = coins . Where ( p => p . Output . AssetId . Equals ( assetId ) ) ;
671
+ }
672
+ Coin [ ] coins_array = coins . ToArray ( ) ;
673
+ const int MAX_SHOW = 100 ;
674
+ for ( int i = 0 ; i < coins_array . Length && i < MAX_SHOW ; i ++ )
675
+ Console . WriteLine ( $ "{ coins_array [ i ] . Reference . PrevHash } :{ coins_array [ i ] . Reference . PrevIndex } ") ;
676
+ if ( coins_array . Length > MAX_SHOW )
677
+ Console . WriteLine ( $ "({ coins_array . Length - MAX_SHOW } more)") ;
678
+ Console . WriteLine ( $ "total: { coins_array . Length } UTXOs") ;
679
+ return true ;
680
+ }
681
+
637
682
protected internal override void OnStart ( string [ ] args )
638
683
{
639
684
Blockchain . RegisterBlockchain ( new LevelDBBlockchain ( Settings . Default . DataDirectoryPath ) ) ;
685
+ if ( File . Exists ( PeerStatePath ) )
686
+ using ( FileStream fs = new FileStream ( PeerStatePath , FileMode . Open , FileAccess . Read , FileShare . Read ) )
687
+ {
688
+ LocalNode . LoadState ( fs ) ;
689
+ }
640
690
LocalNode = new LocalNode ( ) ;
641
691
Task . Run ( ( ) =>
642
692
{
@@ -700,6 +750,10 @@ protected internal override void OnStop()
700
750
if ( consensus != null ) consensus . Dispose ( ) ;
701
751
if ( rpc != null ) rpc . Dispose ( ) ;
702
752
LocalNode . Dispose ( ) ;
753
+ using ( FileStream fs = new FileStream ( PeerStatePath , FileMode . Create , FileAccess . Write , FileShare . None ) )
754
+ {
755
+ LocalNode . SaveState ( fs ) ;
756
+ }
703
757
Blockchain . Default . Dispose ( ) ;
704
758
}
705
759
0 commit comments