Skip to content

Commit

Permalink
add StatesDumper
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzhang committed Sep 1, 2018
1 parent 568e966 commit 6f66abe
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
46 changes: 46 additions & 0 deletions StatesDumper/StatesDumper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Neo.IO;
using Neo.IO.Json;
using Neo.Ledger;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Neo.Plugins
{
public class StatesDumper : Plugin
{
protected override bool OnMessage(object message)
{
if (!(message is string[] args)) return false;
if (args.Length < 2) return false;
if (args[0] != "dump") return false;
switch (args[1])
{
case "storage":
Dump(args.Length >= 3
? Blockchain.Singleton.Store.GetStorages().Find(UInt160.Parse(args[2]).ToArray())
: Blockchain.Singleton.Store.GetStorages().Find());
return true;
default:
return false;
}
}

private static void Dump<TKey, TValue>(IEnumerable<KeyValuePair<TKey, TValue>> states)
where TKey : ISerializable
where TValue : ISerializable
{
const string path = "dump.json";
JArray array = new JArray(states.Select(p =>
{
JObject state = new JObject();
state["key"] = p.Key.ToArray().ToHexString();
state["value"] = p.Value.ToArray().ToHexString();
return state;
}));
File.WriteAllText(path, array.ToString());
Console.WriteLine($"States have been dumped into file {path}");
}
}
}
13 changes: 13 additions & 0 deletions StatesDumper/StatesDumper.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>3.0.0-preview2-11</Version>
<TargetFrameworks>netstandard2.0;net47</TargetFrameworks>
<RootNamespace>Neo.Plugins</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="3.0.0-preview2-11" />
</ItemGroup>

</Project>
8 changes: 7 additions & 1 deletion neo-plugins.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimplePolicy", "SimplePolic
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApplicationLogs", "ApplicationLogs\ApplicationLogs.csproj", "{84DA8EA6-EF60-4FCD-B1C6-65C1A8323B3F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RpcDisabled", "RpcDisabled\RpcDisabled.csproj", "{6800D782-8EC0-49E9-98C4-195C8F781A1F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RpcDisabled", "RpcDisabled\RpcDisabled.csproj", "{6800D782-8EC0-49E9-98C4-195C8F781A1F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StatesDumper", "StatesDumper\StatesDumper.csproj", "{86531DB1-A231-46C4-823F-BE60972F7523}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -27,6 +29,10 @@ Global
{6800D782-8EC0-49E9-98C4-195C8F781A1F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6800D782-8EC0-49E9-98C4-195C8F781A1F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6800D782-8EC0-49E9-98C4-195C8F781A1F}.Release|Any CPU.Build.0 = Release|Any CPU
{86531DB1-A231-46C4-823F-BE60972F7523}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{86531DB1-A231-46C4-823F-BE60972F7523}.Debug|Any CPU.Build.0 = Debug|Any CPU
{86531DB1-A231-46C4-823F-BE60972F7523}.Release|Any CPU.ActiveCfg = Release|Any CPU
{86531DB1-A231-46C4-823F-BE60972F7523}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 6f66abe

Please sign in to comment.