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

Fix applog reinstall #761

Merged
merged 1 commit into from
Sep 16, 2022
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
1 change: 0 additions & 1 deletion src/ApplicationLogs/ApplicationLogs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\LevelDBStore\LevelDBStore.csproj" />
<ProjectReference Include="..\RpcServer\RpcServer.csproj" AdditionalProperties="IncludeSettingsFileOutput=False"/>
</ItemGroup>

Expand Down
18 changes: 9 additions & 9 deletions src/ApplicationLogs/LogReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// modifications are permitted.

using Neo.IO;
using Neo.IO.Data.LevelDB;
using Neo.Json;
using Neo.Ledger;
using Neo.Network.P2P.Payloads;
Expand All @@ -25,8 +24,8 @@ namespace Neo.Plugins
{
public class LogReader : Plugin
{
private DB db;
private WriteBatch _writeBatch;
private IStore _db;
private ISnapshot _snapshot;

public override string Name => "ApplicationLogs";
public override string Description => "Synchronizes the smart contract log with the NativeContract log (Notify)";
Expand All @@ -46,21 +45,21 @@ public override void Dispose()
protected override void Configure()
{
Settings.Load(GetConfiguration());
string path = string.Format(Settings.Default.Path, Settings.Default.Network.ToString("X8"));
db = DB.Open(GetFullPath(path), new Options { CreateIfMissing = true });
}

protected override void OnSystemLoaded(NeoSystem system)
{
if (system.Settings.Network != Settings.Default.Network) return;
string path = string.Format(Settings.Default.Path, Settings.Default.Network.ToString("X8"));
_db = system.LoadStore(GetFullPath(path));
RpcServerPlugin.RegisterMethods(this, Settings.Default.Network);
}

[RpcMethod]
public JToken GetApplicationLog(JArray _params)
{
UInt256 hash = UInt256.Parse(_params[0].AsString());
byte[] value = db.Get(ReadOptions.Default, hash.ToArray());
byte[] value = _db.TryGet(hash.ToArray());
if (value is null)
throw new RpcException(-100, "Unknown transaction/blockhash");

Expand Down Expand Up @@ -190,7 +189,7 @@ private void OnCommitting(NeoSystem system, Block block, DataCache snapshot, IRe
private void OnCommitted(NeoSystem system, Block block)
{
if (system.Settings.Network != Settings.Default.Network) return;
db.Write(WriteOptions.Default, _writeBatch);
_snapshot?.Commit();
}

static string GetExceptionMessage(Exception exception)
Expand All @@ -200,12 +199,13 @@ static string GetExceptionMessage(Exception exception)

private void ResetBatch()
{
_writeBatch = new WriteBatch();
_snapshot?.Dispose();
_snapshot = _db.GetSnapshot();
}

private void Put(byte[] key, byte[] value)
{
_writeBatch.Put(key, value);
_snapshot.Put(key, value);
}
}
}