Skip to content

Commit

Permalink
Change module command (neo-project#187)
Browse files Browse the repository at this point in the history
* change command

* Change comment

* Add nuget

* Update StatesDumper.cs
  • Loading branch information
shargon authored and 陈志同 committed Oct 13, 2020
1 parent 9d1b7f3 commit b0ff063
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 33 deletions.
42 changes: 9 additions & 33 deletions src/StatesDumper/StatesDumper.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Neo.ConsoleService;
using Neo.IO;
using Neo.IO.Caching;
using Neo.IO.Json;
Expand Down Expand Up @@ -35,40 +36,15 @@ private static void Dump<TKey, TValue>(IEnumerable<(TKey Key, TValue Value)> sta
Console.WriteLine($"States ({array.Count}) have been dumped into file {path}");
}

protected override bool OnMessage(object message)
/// <summary>
/// Process "dump storage" command
/// </summary>
[ConsoleCommand("dump storage", Category = "Storage", Description = "You can specify the key or use null to get the corresponding information from the storage")]
private void OnDumpStorage(UInt160 key = null)
{
if (!(message is string[] args)) return false;
if (args.Length == 0) return false;
return (args[0].ToLower()) switch
{
"help" => OnHelp(args),
"dump" => OnDump(args),
_ => false,
};
}

private bool OnDump(string[] args)
{
if (args.Length < 2) return false;
switch (args[1].ToLower())
{
case "storage":
Dump(args.Length >= 3
? Blockchain.Singleton.View.Storages.Find(UInt160.Parse(args[2]).ToArray())
: Blockchain.Singleton.View.Storages.Find());
return true;
default:
return false;
}
}

private bool OnHelp(string[] args)
{
if (args.Length < 2) return false;
if (!string.Equals(args[1], Name, StringComparison.OrdinalIgnoreCase))
return false;
Console.Write($"{Name} Commands:\n" + "\tdump storage <key>\n");
return true;
Dump(key != null
? Blockchain.Singleton.View.Storages.Find(key.ToArray())
: Blockchain.Singleton.View.Storages.Find());
}

public void OnPersist(StoreView snapshot, IReadOnlyList<Blockchain.ApplicationExecuted> applicationExecutedList)
Expand Down
1 change: 1 addition & 0 deletions src/StatesDumper/StatesDumper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

<ItemGroup>
<PackageReference Include="Neo" Version="3.0.0-CI00863" />
<PackageReference Include="Neo.ConsoleService" Version="1.0.0" />
</ItemGroup>

</Project>

0 comments on commit b0ff063

Please sign in to comment.