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

Change module command #187

Merged
merged 6 commits into from
Apr 10, 2020
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
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>