Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
record notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Zhang committed Oct 12, 2017
1 parent 923818c commit fc0921d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
40 changes: 37 additions & 3 deletions neo-cli/Shell/MainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
using Neo.Implementations.Blockchains.LevelDB;
using Neo.Implementations.Wallets.EntityFramework;
using Neo.IO;
using Neo.IO.Json;
using Neo.Network;
using Neo.Network.RPC;
using Neo.Services;
using Neo.SmartContract;
using Neo.VM;
using Neo.Wallets;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -738,11 +740,27 @@ protected internal override void OnStart(string[] args)
File.Delete(acc_zip_path);
}
LocalNode.Start(Settings.Default.NodePort, Settings.Default.WsPort);
if (args.Length >= 1 && args[0] == "/rpc")
bool recordNotifications = false;
for (int i = 0; i < args.Length; i++)
{
rpc = new RpcServerWithWallet(LocalNode);
rpc.Start(Settings.Default.UriPrefix.OfType<string>().ToArray(), Settings.Default.SslCert, Settings.Default.SslCertPassword);
switch (args[i])
{
case "/rpc":
case "--rpc":
case "-r":
if (rpc == null)
{
rpc = new RpcServerWithWallet(LocalNode);
rpc.Start(Settings.Default.UriPrefix.OfType<string>().ToArray(), Settings.Default.SslCert, Settings.Default.SslCertPassword);
}
break;
case "--record-notifications":
recordNotifications = true;
break;
}
}
if (recordNotifications)
Blockchain.Notify += Blockchain_Notify;
});
}

Expand Down Expand Up @@ -816,5 +834,21 @@ private bool OnUpgradeWalletCommand(string[] args)
Console.WriteLine($"Wallet file upgrade complete. Old file has been auto-saved at: {path_old}");
return true;
}

private void Blockchain_Notify(object sender, BlockNotifyEventArgs e)
{
JArray jArray = new JArray(e.Notifications.Select(p =>
{
JObject json = new JObject();
json["txid"] = ((Transaction)p.ScriptContainer).Hash.ToString();
json["contract"] = p.ScriptHash.ToString();
json["state"] = p.State.ToParameter().ToJson();
return json;
}));
string path = Path.Combine(AppContext.BaseDirectory, "Notifications");
Directory.CreateDirectory(path);
path = Path.Combine(path, $"block-{e.Block.Index}.json");
File.WriteAllText(path, jArray.ToString());
}
}
}
4 changes: 2 additions & 2 deletions neo-cli/neo-cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<Copyright>2016-2017 The Neo Project</Copyright>
<AssemblyTitle>Neo.CLI</AssemblyTitle>
<Version>2.3.3</Version>
<Version>2.3.4</Version>
<Authors>The Neo Project</Authors>
<TargetFramework>netcoreapp1.0</TargetFramework>
<AssemblyName>neo-cli</AssemblyName>
Expand Down Expand Up @@ -31,7 +31,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.0.2" />
<PackageReference Include="Neo" Version="2.3.3" />
<PackageReference Include="Neo" Version="2.3.4" />
</ItemGroup>

</Project>

0 comments on commit fc0921d

Please sign in to comment.