Skip to content

Commit

Permalink
Upgrade dependencies and target frameworks (neo-project#147)
Browse files Browse the repository at this point in the history
* Upgrade dependencies and target frameworks

* Update .travis.yml

* IStorage (neo-project#148)

* Fix UT (neo-project#149)

* Update RpcNep5Tracker/RpcNep5Tracker.cs

Co-Authored-By: Erik Zhang <[email protected]>

* Update RpcNep5Tracker/RpcNep5Tracker.cs

Co-Authored-By: Erik Zhang <[email protected]>

* Update RpcNep5Tracker/RpcNep5Tracker.cs

Co-Authored-By: Erik Zhang <[email protected]>
  • Loading branch information
erikzhang authored and 陈志同 committed Oct 13, 2020
1 parent 1a951bb commit 83bba5a
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 65 deletions.
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ language: csharp

os:
- linux
- osx

dist: bionic
osx_image: xcode9.1

mono: none
dotnet: 2.1.300
dotnet: 3.0.100

script:
- dotnet restore
4 changes: 2 additions & 2 deletions ApplicationLogs/ApplicationLogs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Version>3.0.0-preview1</Version>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>Neo.Plugins</RootNamespace>
</PropertyGroup>

Expand All @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="3.0.0-preview1" />
<PackageReference Include="Neo" Version="3.0.0-CI00804" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions ApplicationLogs/LogReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
using Neo.IO.Json;
using Neo.Ledger;
using Neo.Network.RPC;
using Neo.Persistence;
using Neo.VM;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Snapshot = Neo.Persistence.Snapshot;

namespace Neo.Plugins
{
Expand Down Expand Up @@ -45,7 +45,7 @@ public void PostProcess(HttpContext context, string method, JArray _params, JObj
{
}

public void OnPersist(Snapshot snapshot, IReadOnlyList<Blockchain.ApplicationExecuted> applicationExecutedList)
public void OnPersist(StoreView snapshot, IReadOnlyList<Blockchain.ApplicationExecuted> applicationExecutedList)
{
WriteBatch writeBatch = new WriteBatch();

Expand Down Expand Up @@ -83,7 +83,7 @@ public void OnPersist(Snapshot snapshot, IReadOnlyList<Blockchain.ApplicationExe
db.Write(WriteOptions.Default, writeBatch);
}

public void OnCommit(Snapshot snapshot)
public void OnCommit(StoreView snapshot)
{
}

Expand Down
10 changes: 4 additions & 6 deletions CoreMetrics/CoreMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Neo.IO.Json;
using Neo.Ledger;
using Neo.Network.P2P.Payloads;
using Neo.Persistence;

namespace Neo.Plugins
{
Expand All @@ -18,9 +17,8 @@ public JObject OnProcess(HttpContext context, string method, JArray _params)
{
case "getmetricblocktimestamp":
{

uint nBlocks = (uint)_params[0].AsNumber();
uint lastHeight = _params.Count >= 2 ? lastHeight = (uint)_params[1].AsNumber() : 0;
uint lastHeight = _params.Count >= 2 ? (uint)_params[1].AsNumber() : 0;
return GetBlocksTime(nBlocks, lastHeight);
}
default:
Expand Down Expand Up @@ -60,18 +58,18 @@ private JObject GetBlocksTime(uint nBlocks, uint lastHeight)
JObject json = new JObject();
return json["error"] = "Requested number of blocks timestamps " + nBlocks + " exceeds quantity of known blocks " + Blockchain.Singleton.Height;
}

if (nBlocks == 0)
{
JObject json = new JObject();
return json["error"] = "Requested number of block times can not be = 0";
}

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

JObject json = new JObject();
Expand Down
4 changes: 2 additions & 2 deletions CoreMetrics/CoreMetrics.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

<PropertyGroup>
<Version>3.0.0-preview1</Version>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>Neo.Plugins</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="3.0.0-preview1" />
<PackageReference Include="Neo" Version="3.0.0-CI00804" />
</ItemGroup>

</Project>
3 changes: 1 addition & 2 deletions ImportBlocks/ImportBlocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Neo.IO;
using Neo.Ledger;
using Neo.Network.P2P.Payloads;
using Neo.Persistence;
using System;
using System.IO;

Expand Down Expand Up @@ -82,7 +81,7 @@ private void WriteBlocks(uint start, uint count, string path, bool writeStart)
fs.Seek(0, SeekOrigin.End);
for (uint i = start; i <= end; i++)
{
Block block = Blockchain.Singleton.Store.GetBlock(i);
Block block = Blockchain.Singleton.GetBlock(i);
byte[] array = block.ToArray();
fs.Write(BitConverter.GetBytes(array.Length), 0, sizeof(int));
fs.Write(array, 0, array.Length);
Expand Down
4 changes: 2 additions & 2 deletions ImportBlocks/ImportBlocks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Version>3.0.0-preview1</Version>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>Neo.Plugins</RootNamespace>
</PropertyGroup>

Expand All @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="3.0.0-preview1" />
<PackageReference Include="Neo" Version="3.0.0-CI00804" />
</ItemGroup>

</Project>
56 changes: 56 additions & 0 deletions RpcNep5Tracker/DbCache.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Neo.IO;
using Neo.IO.Caching;
using Neo.IO.Data.LevelDB;
using System;
using System.Collections.Generic;

namespace Neo.Plugins
{
public class DbCache<TKey, TValue> : DataCache<TKey, TValue>
where TKey : IEquatable<TKey>, ISerializable, new()
where TValue : class, ICloneable<TValue>, ISerializable, new()
{
private readonly DB db;
private readonly ReadOptions options;
private readonly WriteBatch batch;
private readonly byte prefix;

public DbCache(DB db, ReadOptions options, WriteBatch batch, byte prefix)
{
this.db = db;
this.options = options ?? ReadOptions.Default;
this.batch = batch;
this.prefix = prefix;
}

protected override void AddInternal(TKey key, TValue value)
{
batch?.Put(prefix, key, value);
}

protected override void DeleteInternal(TKey key)
{
batch?.Delete(prefix, key);
}

protected override IEnumerable<(TKey, TValue)> FindInternal(byte[] key_prefix)
{
return db.Find(options, SliceBuilder.Begin(prefix).Add(key_prefix), (k, v) => (k.ToArray().AsSerializable<TKey>(1), v.ToArray().AsSerializable<TValue>()));
}

protected override TValue GetInternal(TKey key)
{
return db.Get<TValue>(options, prefix, key);
}

protected override TValue TryGetInternal(TKey key)
{
return db.TryGet<TValue>(options, prefix, key);
}

protected override void UpdateInternal(TKey key, TValue value)
{
batch?.Put(prefix, key, value);
}
}
}
31 changes: 14 additions & 17 deletions RpcNep5Tracker/RpcNep5Tracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Neo.Network.P2P.Payloads;
using Neo.Network.RPC;
using Neo.Persistence;
using Neo.Persistence.LevelDB;
using Neo.SmartContract;
using Neo.VM;
using Neo.Wallets;
Expand All @@ -15,8 +14,6 @@
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using Snapshot = Neo.Persistence.Snapshot;

namespace Neo.Plugins
{
Expand Down Expand Up @@ -63,11 +60,11 @@ private void ResetBatch()
}
}

private void RecordTransferHistory(Snapshot snapshot, UInt160 scriptHash, UInt160 from, UInt160 to, BigInteger amount, UInt256 txHash, ref ushort transferIndex)
private void RecordTransferHistory(StoreView snapshot, UInt160 scriptHash, UInt160 from, UInt160 to, BigInteger amount, UInt256 txHash, ref ushort transferIndex)
{
if (!_shouldTrackHistory) return;

Header header = snapshot.GetHeader(snapshot.Height);
Header header = snapshot.GetHeader(snapshot.CurrentBlockHash);

if (_recordNullAddressHistory || from != UInt160.Zero)
{
Expand Down Expand Up @@ -95,14 +92,14 @@ private void RecordTransferHistory(Snapshot snapshot, UInt160 scriptHash, UInt16
transferIndex++;
}

private void HandleNotification(Snapshot snapshot, Transaction transaction, UInt160 scriptHash,
private void HandleNotification(StoreView snapshot, Transaction transaction, UInt160 scriptHash,
VM.Types.Array stateItems,
Dictionary<Nep5BalanceKey, Nep5Balance> nep5BalancesChanged, ref ushort transferIndex)
{
if (stateItems.Count == 0) return;
// Event name should be encoded as a byte array.
if (!(stateItems[0] is VM.Types.ByteArray)) return;
var eventName = Encoding.UTF8.GetString(stateItems[0].GetByteArray());
var eventName = stateItems[0].GetString();
if (eventName != "Transfer") return;
if (stateItems.Count < 4) return;

Expand All @@ -113,9 +110,9 @@ private void HandleNotification(Snapshot snapshot, Transaction transaction, UInt
var amountItem = stateItems[3];
if (!(amountItem is VM.Types.ByteArray || amountItem is VM.Types.Integer))
return;
byte[] fromBytes = stateItems[1]?.GetByteArray();
byte[] fromBytes = stateItems[1]?.GetSpan().ToArray();
if (fromBytes?.Length != 20) fromBytes = null;
byte[] toBytes = stateItems[2]?.GetByteArray();
byte[] toBytes = stateItems[2]?.GetSpan().ToArray();
if (toBytes?.Length != 20) toBytes = null;
if (fromBytes == null && toBytes == null) return;
var from = new UInt160(fromBytes);
Expand All @@ -135,7 +132,7 @@ private void HandleNotification(Snapshot snapshot, Transaction transaction, UInt
RecordTransferHistory(snapshot, scriptHash, from, to, amountItem.GetBigInteger(), transaction.Hash, ref transferIndex);
}

public void OnPersist(Snapshot snapshot, IReadOnlyList<Blockchain.ApplicationExecuted> applicationExecutedList)
public void OnPersist(StoreView snapshot, IReadOnlyList<Blockchain.ApplicationExecuted> applicationExecutedList)
{
// Start freshly with a new DBCache for each block.
ResetBatch();
Expand Down Expand Up @@ -183,7 +180,7 @@ public void OnPersist(Snapshot snapshot, IReadOnlyList<Blockchain.ApplicationExe
}
}

public void OnCommit(Snapshot snapshot)
public void OnCommit(StoreView snapshot)
{
_balances.Commit();
if (_shouldTrackHistory)
Expand Down Expand Up @@ -222,12 +219,12 @@ private void AddTransfers(byte dbPrefix, UInt160 userScriptHash, ulong startTime
if (++resultCount > _maxResults) break;
JObject transfer = new JObject();
transfer["timestamp"] = transferPair.Key.TimestampMS;
transfer["asset_hash"] = transferPair.Key.AssetScriptHash.ToArray().Reverse().ToHexString();
transfer["asset_hash"] = transferPair.Key.AssetScriptHash.ToString();
transfer["transfer_address"] = transferPair.Value.UserScriptHash.ToAddress();
transfer["amount"] = transferPair.Value.Amount.ToString();
transfer["block_index"] = transferPair.Value.BlockIndex;
transfer["transfer_notify_index"] = transferPair.Key.BlockXferNotificationIndex;
transfer["tx_hash"] = transferPair.Value.TxHash.ToArray().Reverse().ToHexString();
transfer["tx_hash"] = transferPair.Value.TxHash.ToString();
parentJArray.Add(transfer);
}
}
Expand Down Expand Up @@ -268,12 +265,12 @@ private JObject GetNep5Balances(JArray _params)
json["address"] = userScriptHash.ToAddress();
var dbCache = new DbCache<Nep5BalanceKey, Nep5Balance>(_db, null, null, Nep5BalancePrefix);
byte[] prefix = userScriptHash.ToArray();
foreach (var storageKeyValuePair in dbCache.Find(prefix))
foreach (var (key, value) in dbCache.Find(prefix))
{
JObject balance = new JObject();
balance["asset_hash"] = storageKeyValuePair.Key.AssetScriptHash.ToArray().Reverse().ToHexString();
balance["amount"] = storageKeyValuePair.Value.Balance.ToString();
balance["last_updated_block"] = storageKeyValuePair.Value.LastUpdatedBlock;
balance["asset_hash"] = key.AssetScriptHash.ToString();
balance["amount"] = value.Balance.ToString();
balance["last_updated_block"] = value.LastUpdatedBlock;
balances.Add(balance);
}
return json;
Expand Down
5 changes: 2 additions & 3 deletions RpcNep5Tracker/RpcNep5Tracker.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>3.0.0-preview1</Version>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>Neo.Plugins</RootNamespace>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<None Update="RpcNep5Tracker\config.json">
Expand All @@ -12,6 +11,6 @@
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Neo" Version="3.0.0-preview1" />
<PackageReference Include="Neo" Version="3.0.0-CI00804" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions RpcSecurity/RpcSecurity.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Version>3.0.0-preview1</Version>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>Neo.Plugins</RootNamespace>
</PropertyGroup>

Expand All @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="3.0.0-preview1" />
<PackageReference Include="Neo" Version="3.0.0-CI00804" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion RpcWallet/RpcWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private JObject GetUnclaimedGas()
{
CheckWallet();
BigInteger gas = BigInteger.Zero;
using (Snapshot snapshot = Blockchain.Singleton.GetSnapshot())
using (SnapshotView snapshot = Blockchain.Singleton.GetSnapshot())
foreach (UInt160 account in Wallet.GetAccounts().Select(p => p.ScriptHash))
{
gas += NativeContract.NEO.UnclaimedGas(snapshot, account, snapshot.Height + 1);
Expand Down
4 changes: 2 additions & 2 deletions RpcWallet/RpcWallet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Version>3.0.0-preview1</Version>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>Neo.Plugins</RootNamespace>
</PropertyGroup>

Expand All @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="3.0.0-preview1" />
<PackageReference Include="Neo" Version="3.0.0-CI00804" />
</ItemGroup>

</Project>
Loading

0 comments on commit 83bba5a

Please sign in to comment.