Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method: show state #463

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading