Skip to content

Commit

Permalink
Add method: show state (#463)
Browse files Browse the repository at this point in the history
* show state

* Update ShowCommand.State.cs

* Update command-reference.md
  • Loading branch information
chenzhitong authored Aug 14, 2024
1 parent ab186c3 commit 958adc5
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
14 changes: 14 additions & 0 deletions docs/command-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,20 @@ The `show transaction` displays the contents of a transaction specified by hash

`show tx` is an alias for `show transaction`

### neoxp show state

```
Usage: neoxp show state
```

Outputs the current block height, running status, and configuration file location. Example:

```
Block height: 111
IsRunning: False
Config file: C:\Users\bitco\.neo-express\default.neo-express
```

## neoxp candidate

The `candidate` command has a series of subcommands for managing candidates election in the Neo-Express blockchain.
Expand Down
54 changes: 54 additions & 0 deletions src/neoxp/Commands/ShowCommand.State.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (C) 2015-2024 The Neo Project.
//
// ShowCommand.State.cs file belongs to neo-express project and is free
// software distributed under the MIT software license, see the
// accompanying file LICENSE in the main directory of the
// repository or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using McMaster.Extensions.CommandLineUtils;

namespace NeoExpress.Commands
{
partial class ShowCommand
{
[Command("state", Description = "Show state")]
internal class State
{
readonly ExpressChainManagerFactory chainManagerFactory;

public State(ExpressChainManagerFactory chainManagerFactory)
{
this.chainManagerFactory = chainManagerFactory;
}

[Argument(0, Description = "Optional block hash or index. Show most recent block if unspecified")]
internal string BlockHash { get; init; } = string.Empty;

[Option(Description = "Path to neo-express data file")]
internal string Input { get; init; } = string.Empty;

internal async Task<int> OnExecuteAsync(CommandLineApplication app, IConsole console)
{
try
{
var (chainManager, config) = chainManagerFactory.LoadChain(Input);
using var expressNode = chainManager.GetExpressNode();
var blockHeight = (await expressNode.GetLatestBlockAsync().ConfigureAwait(false)).Index;
console.WriteLine($"Block height: {blockHeight}");
console.WriteLine($"IsRunning: {chainManager.IsRunning(null)}");
console.WriteLine($"Config file: {config}");
return 0;
}
catch (Exception ex)
{
app.WriteException(ex);
return 1;
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/neoxp/Commands/ShowCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace NeoExpress.Commands
{
[Command("show", Description = "Show information")]
[Subcommand(typeof(Balance), typeof(Balances), typeof(Block), typeof(Notifications), typeof(Transaction), typeof(NFT))]
[Subcommand(typeof(Balance), typeof(Balances), typeof(Block), typeof(Notifications), typeof(Transaction), typeof(NFT), typeof(State))]
partial class ShowCommand
{
internal int OnExecute(CommandLineApplication app, IConsole console)
Expand Down

0 comments on commit 958adc5

Please sign in to comment.