-
Notifications
You must be signed in to change notification settings - Fork 1k
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
19 additions
and
16 deletions.
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
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 |
---|---|---|
@@ -1,27 +1,28 @@ | ||
using Microsoft.AspNetCore.Http; | ||
using Neo.IO.Data.LevelDB; | ||
using Neo.IO.Json; | ||
using Neo.Network.RPC; | ||
using System.IO; | ||
|
||
namespace Neo.Plugins | ||
{ | ||
public class LogReader : Plugin, IRpcPlugin | ||
{ | ||
private readonly DB db = DB.Open(Settings.Default.Path, new Options { CreateIfMissing = true }); | ||
|
||
public override string Name => "ApplicationLogs"; | ||
|
||
public LogReader() | ||
{ | ||
System.ActorSystem.ActorOf(Logger.Props(System.Blockchain)); | ||
System.ActorSystem.ActorOf(Logger.Props(System.Blockchain, db)); | ||
} | ||
|
||
public JObject OnProcess(HttpContext context, string method, JArray _params) | ||
{ | ||
if (method != "getapplicationlog") return null; | ||
UInt256 hash = UInt256.Parse(_params[0].AsString()); | ||
string path = Path.Combine(Settings.Default.Path, $"{hash}.json"); | ||
return File.Exists(path) | ||
? JObject.Parse(File.ReadAllText(path)) | ||
: throw new RpcException(-100, "Unknown transaction"); | ||
if (!db.TryGet(ReadOptions.Default, hash.ToArray(), out Slice value)) | ||
throw new RpcException(-100, "Unknown transaction"); | ||
return JObject.Parse(value.ToString()); | ||
} | ||
} | ||
} |
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