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

master-2.x changes since April 22, 2019 #2

Open
wants to merge 13 commits into
base: last-known-2.x-update
Choose a base branch
from
4 changes: 2 additions & 2 deletions ApplicationLogs/ApplicationLogs.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>2.10.1</Version>
<Version>2.10.3</Version>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>Neo.Plugins</RootNamespace>
</PropertyGroup>
Expand All @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="2.10.1" />
<PackageReference Include="Neo" Version="2.10.3" />
</ItemGroup>

</Project>
22 changes: 9 additions & 13 deletions CoreMetrics/CoreMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ namespace Neo.Plugins
{
public class CoreMetrics : Plugin, IRpcPlugin
{
public override void Configure()
{
}
public override void Configure() { }

public void PreProcess(HttpContext context, string method, JArray _params)
{
}
public void PreProcess(HttpContext context, string method, JArray _params) { }

public JObject OnProcess(HttpContext context, string method, JArray _params)
{
Expand All @@ -32,9 +28,7 @@ public JObject OnProcess(HttpContext context, string method, JArray _params)
}
}

public void PostProcess(HttpContext context, string method, JArray _params, JObject result)
{
}
public void PostProcess(HttpContext context, string method, JArray _params, JObject result) { }

private JObject GetBlocksTime(uint nBlocks, uint lastHeight)
{
Expand Down Expand Up @@ -64,7 +58,7 @@ private JObject GetBlocksTime(uint nBlocks, uint lastHeight)
if (nBlocks >= Blockchain.Singleton.Height)
{
JObject json = new JObject();
return json["error"] = "Requested number of blocks timestamps exceeds quantity of known blocks " + Blockchain.Singleton.Height;
return json["error"] = "Requested number of blocks timestamps " + nBlocks + " exceeds quantity of known blocks " + Blockchain.Singleton.Height;
}

if (nBlocks <= 0)
Expand All @@ -74,11 +68,13 @@ private JObject GetBlocksTime(uint nBlocks, uint lastHeight)
}

JArray array = new JArray();
uint heightToBegin = lastHeight > 0 ? lastHeight - nBlocks : Blockchain.Singleton.Height - nBlocks;
for (uint i = heightToBegin; i <= Blockchain.Singleton.HeaderHeight; i++)
uint heightToBegin = lastHeight > 0 ? lastHeight - nBlocks : (Blockchain.Singleton.Height - 1) - nBlocks;
for (uint i = heightToBegin; i <= heightToBegin + nBlocks; i++)
{
JObject json = new JObject();
Header header = Blockchain.Singleton.Store.GetHeader(i);
if (header == null) break;

JObject json = new JObject();
json["timestamp"] = header.Timestamp;
json["height"] = i;
array.Add(json);
Expand Down
4 changes: 2 additions & 2 deletions CoreMetrics/CoreMetrics.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>2.10.1</Version>
<Version>2.10.3</Version>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>Neo.Plugins</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="2.10.1" />
<PackageReference Include="Neo" Version="2.10.3" />
</ItemGroup>

</Project>
100 changes: 49 additions & 51 deletions ImportBlocks/ImportBlocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,79 +19,77 @@ public override void Configure()

private bool OnExport(string[] args)
{
bool writeStart;
uint start, count;
string path;
if (args.Length < 2) return false;
if (!string.Equals(args[1], "block", StringComparison.OrdinalIgnoreCase)
&& !string.Equals(args[1], "blocks", StringComparison.OrdinalIgnoreCase))
return false;
if (args.Length >= 3 && uint.TryParse(args[2], out uint start))
if (args.Length >= 3 && uint.TryParse(args[2], out start))
{
if (start > Blockchain.Singleton.Height)
return true;
uint count = args.Length >= 4 ? uint.Parse(args[3]) : uint.MaxValue;
if (Blockchain.Singleton.Height < start) return true;
count = args.Length >= 4 ? uint.Parse(args[3]) : uint.MaxValue;
count = Math.Min(count, Blockchain.Singleton.Height - start + 1);
uint end = start + count - 1;
string path = $"chain.{start}.acc";
using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
path = $"chain.{start}.acc";
writeStart = true;
}
else
{
start = 0;
count = Blockchain.Singleton.Height - start + 1;
path = args.Length >= 3 ? args[2] : "chain.acc";
writeStart = false;
}

WriteBlocks(start, count, path, writeStart);

Console.WriteLine();
return true;
}

private void WriteBlocks(uint start, uint count, string path, bool writeStart)
{
uint end = start + count - 1;
using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, 4096, FileOptions.WriteThrough))
{
if (fs.Length > 0)
{
if (fs.Length > 0)
byte[] buffer = new byte[sizeof(uint)];
if (writeStart)
{
fs.Seek(sizeof(uint), SeekOrigin.Begin);
byte[] buffer = new byte[sizeof(uint)];
fs.Read(buffer, 0, buffer.Length);
start += BitConverter.ToUInt32(buffer, 0);
fs.Seek(sizeof(uint), SeekOrigin.Begin);
}
else
{
fs.Write(BitConverter.GetBytes(start), 0, sizeof(uint));
fs.Read(buffer, 0, buffer.Length);
start = BitConverter.ToUInt32(buffer, 0);
fs.Seek(0, SeekOrigin.Begin);
}
if (start <= end)
fs.Write(BitConverter.GetBytes(count), 0, sizeof(uint));
fs.Seek(0, SeekOrigin.End);
using (Snapshot snapshot = Blockchain.Singleton.GetSnapshot())
for (uint i = start; i <= end; i++)
{
Block block = snapshot.GetBlock(i);
byte[] array = block.ToArray();
fs.Write(BitConverter.GetBytes(array.Length), 0, sizeof(int));
fs.Write(array, 0, array.Length);
Console.SetCursorPosition(0, Console.CursorTop);
Console.Write($"[{i}/{end}]");
}
}
}
else
{
start = 0;
uint end = Blockchain.Singleton.Height;
uint count = end - start + 1;
string path = args.Length >= 3 ? args[2] : "chain.acc";
using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
else
{
if (fs.Length > 0)
if (writeStart)
{
byte[] buffer = new byte[sizeof(uint)];
fs.Read(buffer, 0, buffer.Length);
start = BitConverter.ToUInt32(buffer, 0);
fs.Seek(0, SeekOrigin.Begin);
fs.Write(BitConverter.GetBytes(start), 0, sizeof(uint));
}
if (start <= end)
fs.Write(BitConverter.GetBytes(count), 0, sizeof(uint));
fs.Seek(0, SeekOrigin.End);
using (Snapshot snapshot = Blockchain.Singleton.GetSnapshot())
for (uint i = start; i <= end; i++)
{
Block block = snapshot.GetBlock(i);
byte[] array = block.ToArray();
fs.Write(BitConverter.GetBytes(array.Length), 0, sizeof(int));
fs.Write(array, 0, array.Length);
Console.SetCursorPosition(0, Console.CursorTop);
Console.Write($"[{i}/{end}]");
}
}
if (start <= end)
fs.Write(BitConverter.GetBytes(count), 0, sizeof(uint));
fs.Seek(0, SeekOrigin.End);
for (uint i = start; i <= end; i++)
{
Block block = Blockchain.Singleton.Store.GetBlock(i);
byte[] array = block.ToArray();
fs.Write(BitConverter.GetBytes(array.Length), 0, sizeof(int));
fs.Write(array, 0, array.Length);
Console.SetCursorPosition(0, Console.CursorTop);
Console.Write($"[{i}/{end}]");
}
}
Console.WriteLine();
return true;
}

private bool OnHelp(string[] args)
Expand Down
4 changes: 2 additions & 2 deletions ImportBlocks/ImportBlocks.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>2.10.1</Version>
<Version>2.10.3</Version>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>Neo.Plugins</RootNamespace>
</PropertyGroup>
Expand All @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="2.10.1" />
<PackageReference Include="Neo" Version="2.10.3" />
</ItemGroup>

</Project>
22 changes: 13 additions & 9 deletions RpcNep5Tracker/RpcNep5Tracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Neo.Wallets;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
Expand All @@ -34,13 +35,14 @@ public class RpcNep5Tracker : Plugin, IPersistencePlugin, IRpcPlugin
private uint _maxResults;
private bool _shouldTrackNonStandardMintTokensEvent;
private Neo.IO.Data.LevelDB.Snapshot _levelDbSnapshot;
private static readonly Fixed8 maxGas = Fixed8.FromDecimal(1m);

public override void Configure()
{
if (_db == null)
{
var dbPath = GetConfiguration().GetSection("DBPath").Value ?? "Nep5BalanceData";
_db = DB.Open(dbPath, new Options { CreateIfMissing = true });
_db = DB.Open(Path.GetFullPath(dbPath), new Options { CreateIfMissing = true });
}
_shouldTrackHistory = (GetConfiguration().GetSection("TrackHistory").Value ?? true.ToString()) != false.ToString();
_recordNullAddressHistory = (GetConfiguration().GetSection("RecordNullAddressHistory").Value ?? false.ToString()) != false.ToString();
Expand All @@ -67,10 +69,10 @@ private void ResetBatch()
private void RecordTransferHistory(Snapshot snapshot, UInt160 scriptHash, UInt160 from, UInt160 to, BigInteger amount, UInt256 txHash, ref ushort transferIndex)
{
if (!_shouldTrackHistory) return;
Header header = snapshot.GetHeader(snapshot.Height);
if (_recordNullAddressHistory || from != UInt160.Zero)
{
_transfersSent.Add(new Nep5TransferKey(from,
snapshot.GetHeader(snapshot.Height).Timestamp, scriptHash, transferIndex),
_transfersSent.Add(new Nep5TransferKey(from, header.Timestamp, scriptHash, transferIndex),
new Nep5Transfer
{
Amount = amount,
Expand All @@ -82,8 +84,7 @@ private void RecordTransferHistory(Snapshot snapshot, UInt160 scriptHash, UInt16

if (_recordNullAddressHistory || to != UInt160.Zero)
{
_transfersReceived.Add(new Nep5TransferKey(to,
snapshot.GetHeader(snapshot.Height).Timestamp, scriptHash, transferIndex),
_transfersReceived.Add(new Nep5TransferKey(to, header.Timestamp, scriptHash, transferIndex),
new Nep5Transfer
{
Amount = amount,
Expand Down Expand Up @@ -191,10 +192,13 @@ public void OnPersist(Snapshot snapshot, IReadOnlyList<Blockchain.ApplicationExe
script = sb.ToArray();
}

ApplicationEngine engine = ApplicationEngine.Run(script, snapshot);
if (engine.State.HasFlag(VMState.FAULT)) continue;
if (engine.ResultStack.Count <= 0) continue;
nep5BalancePair.Value.Balance = engine.ResultStack.Pop().GetBigInteger();
using (ApplicationEngine engine = ApplicationEngine.Run(script, snapshot, extraGAS: maxGas))
{
if (engine.State.HasFlag(VMState.FAULT)) continue;
if (engine.ResultStack.Count <= 0) continue;
nep5BalancePair.Value.Balance = engine.ResultStack.Pop().GetBigInteger();
}

nep5BalancePair.Value.LastUpdatedBlock = snapshot.Height;
if (nep5BalancePair.Value.Balance == 0)
{
Expand Down
4 changes: 2 additions & 2 deletions RpcNep5Tracker/RpcNep5Tracker.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>2.10.1</Version>
<Version>2.10.3</Version>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>Neo.Plugins</RootNamespace>
<LangVersion>latest</LangVersion>
Expand All @@ -12,6 +12,6 @@
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Neo" Version="2.10.1" />
<PackageReference Include="Neo" Version="2.10.3" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions RpcSecurity/RpcSecurity.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>2.10.1</Version>
<Version>2.10.3</Version>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>Neo.Plugins</RootNamespace>
</PropertyGroup>
Expand All @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="2.10.1" />
<PackageReference Include="Neo" Version="2.10.3" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions RpcSystemAssetTracker/RpcSystemAssetTracker.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>2.10.1</Version>
<Version>2.10.3</Version>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<RootNamespace>Neo.Plugins</RootNamespace>
<LangVersion>latest</LangVersion>
Expand All @@ -12,6 +12,6 @@
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Neo" Version="2.10.1" />
<PackageReference Include="Neo" Version="2.10.3" />
</ItemGroup>
</Project>
3 changes: 2 additions & 1 deletion RpcSystemAssetTracker/RpcSystemAssetTrackerPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Neo.Ledger;
using Neo.Persistence;
using Snapshot = Neo.Persistence.Snapshot;
using System.IO;

namespace Neo.Plugins
{
Expand All @@ -33,7 +34,7 @@ public override void Configure()
if (_db == null)
{
var dbPath = GetConfiguration().GetSection("DBPath").Value ?? "SystemAssetBalanceData";
_db = DB.Open(dbPath, new Options { CreateIfMissing = true });
_db = DB.Open(Path.GetFullPath(dbPath), new Options { CreateIfMissing = true });
_shouldTrackUnclaimed = (GetConfiguration().GetSection("TrackUnclaimed").Value ?? true.ToString()) != false.ToString();
try
{
Expand Down
4 changes: 2 additions & 2 deletions RpcWallet/RpcWallet.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>2.10.1</Version>
<Version>2.10.3</Version>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>Neo.Plugins</RootNamespace>
</PropertyGroup>
Expand All @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="2.10.1" />
<PackageReference Include="Neo" Version="2.10.3" />
</ItemGroup>

</Project>
Loading