forked from neo-project/neo
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
66 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
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}"); | ||
} | ||
} | ||
} |
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,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> |
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