-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* show state * Update ShowCommand.State.cs * Update command-reference.md
- Loading branch information
1 parent
ab186c3
commit 958adc5
Showing
3 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters