Skip to content

Commit

Permalink
v1.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashuaidehao committed Dec 16, 2022
1 parent 26125d0 commit 5aa2afd
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 143 deletions.
2 changes: 1 addition & 1 deletion neo
Submodule neo updated 34 files
+1 −1 src/Directory.Build.props
+0 −12 src/Neo/Cryptography/Helper.cs
+2 −3 src/Neo/Neo.csproj
+4 −14 src/Neo/Plugins/Plugin.cs
+2 −0 src/Neo/SmartContract/ApplicationEngine.OpCodePrices.cs
+28 −0 src/Neo/SmartContract/ApplicationEngine.Runtime.cs
+38 −0 src/Neo/SmartContract/Native/ContractManagement.cs
+1 −1 src/Neo/SmartContract/Native/StdLib.cs
+1 −1 src/Neo/Wallets/IWalletFactory.cs
+2 −3 src/Neo/Wallets/NEP6/NEP6WalletFactory.cs
+0 −18 src/Neo/Wallets/SQLite/Account.cs
+0 −17 src/Neo/Wallets/SQLite/Address.cs
+0 −21 src/Neo/Wallets/SQLite/Contract.cs
+0 −18 src/Neo/Wallets/SQLite/Key.cs
+0 −35 src/Neo/Wallets/SQLite/SQLiteWalletFactory.cs
+0 −407 src/Neo/Wallets/SQLite/UserWallet.cs
+0 −29 src/Neo/Wallets/SQLite/UserWalletAccount.cs
+0 −59 src/Neo/Wallets/SQLite/VerificationContract.cs
+0 −64 src/Neo/Wallets/SQLite/WalletDataContext.cs
+2 −3 src/Neo/Wallets/Wallet.cs
+3 −3 tests/Directory.Build.props
+0 −9 tests/Neo.UnitTests/Cryptography/UT_Cryptography_Helper.cs
+2 −2 tests/Neo.UnitTests/Neo.UnitTests.csproj
+1 −1 tests/Neo.UnitTests/SmartContract/Native/UT_StdLib.cs
+4 −4 tests/Neo.UnitTests/VM/UT_Helper.cs
+3 −3 tests/Neo.UnitTests/Wallets/NEP6/UT_NEP6Wallet.cs
+0 −37 tests/Neo.UnitTests/Wallets/SQLite/UT_Account.cs
+0 −27 tests/Neo.UnitTests/Wallets/SQLite/UT_Address.cs
+0 −65 tests/Neo.UnitTests/Wallets/SQLite/UT_Contract.cs
+0 −37 tests/Neo.UnitTests/Wallets/SQLite/UT_Key.cs
+0 −174 tests/Neo.UnitTests/Wallets/SQLite/UT_UserWallet.cs
+0 −30 tests/Neo.UnitTests/Wallets/SQLite/UT_UserWalletAccount.cs
+0 −143 tests/Neo.UnitTests/Wallets/SQLite/UT_VerificationContract.cs
+1 −1 tests/Neo.UnitTests/Wallets/UT_Wallet.cs
4 changes: 2 additions & 2 deletions neo3-gui/neo3-gui/ClientApp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion neo3-gui/neo3-gui/ClientApp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "new-gui",
"version": "1.5.0",
"version": "1.5.1",
"private": true,
"main": "main.js",
"homepage": "./",
Expand Down
26 changes: 12 additions & 14 deletions neo3-gui/neo3-gui/Common/Analyzers/BlockAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Neo.SmartContract;
using Neo.SmartContract.Native;
using Neo.VM;
using Array = Neo.VM.Types.Array;

namespace Neo.Common.Analyzers
{
Expand Down Expand Up @@ -156,20 +155,19 @@ private void ProcessTransfer(NotifyEventArgs notification, Blockchain.Applicatio
Result.BalanceChangeAccounts.Add(new AccountAsset(transfer.To, transfer.Asset));
}

if (appExec.Trigger == TriggerType.Application)

var transferStorageItem = new TransferStorageItem()
{
var transferStorageItem = new TransferStorageItem()
{
From = transfer.From,
To = transfer.To,
Asset = transfer.Asset,
Amount = transfer.Amount,
TxId = appExec?.Transaction?.Hash,
Trigger = appExec.Trigger,
TokenId = transfer.TokenId?.ToHexString(),
};
Result.Transfers.Add(transferStorageItem);
}
From = transfer.From,
To = transfer.To,
Asset = transfer.Asset,
Amount = transfer.Amount,
TxId = appExec?.Transaction?.Hash,
Trigger = appExec.Trigger,
TokenId = transfer.TokenId?.ToHexString(),
};
Result.Transfers.Add(transferStorageItem);

}


Expand Down
20 changes: 3 additions & 17 deletions neo3-gui/neo3-gui/Common/Consoles/MainService.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
using Akka.Actor;
using Microsoft.Extensions.Configuration;
using Neo.IO;
using Neo.Ledger;
using Neo.Network.P2P;
using Neo.Network.P2P.Capabilities;
using Neo.Network.P2P.Payloads;
using Neo.Persistence;
using Neo.Plugins;
using Neo.Services;
using Neo.SmartContract;
using Neo.SmartContract.Manifest;
using Neo.SmartContract.Native;
using Neo.VM;
using Neo.Wallets;
using Neo.Wallets.NEP6;
using Neo.Wallets.SQLite;
using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -23,7 +16,6 @@
using System.Net;
using System.Numerics;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -708,15 +700,9 @@ public void OpenWallet(string path, string password)
throw new FileNotFoundException();
}

if (Path.GetExtension(path) == ".db3")
{
CurrentWallet = UserWallet.Open(path, password, CliSettings.Default.Protocol);
}
else
{
NEP6Wallet nep6wallet = new NEP6Wallet(path, password, CliSettings.Default.Protocol);
CurrentWallet = nep6wallet;
}
NEP6Wallet nep6wallet = new NEP6Wallet(path, password, CliSettings.Default.Protocol);
CurrentWallet = nep6wallet;

}


Expand Down
128 changes: 76 additions & 52 deletions neo3-gui/neo3-gui/Common/Scanners/ExecuteResultScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,59 +86,89 @@ public async Task<bool> Sync(uint blockHeight)
return true;
}


var block = blockHeight.GetBlock();
var blockTime = block.Timestamp.FromTimestampMS();
if (blockHeight == 0)
{
SyncNativeContracts(blockTime);
}

if (block.Transactions.Length == 0)
bool hasTxs = block.Transactions.Length > 0;
if (hasTxs)
{
_db.AddSyncIndex(blockHeight);
return true;
SyncContracts(blockHeight, blockTime);
foreach (var transaction in block.Transactions)
{
_db.AddTransaction(new TransactionInfo()
{
TxId = transaction.Hash,
BlockHeight = blockHeight,
Sender = transaction.Sender,
Time = blockTime,
});
}
var transfers = new List<TransferInfo>();
var transferItems = _levelDb.GetTransfers(blockHeight);
if (transferItems.NotEmpty())
{
foreach (var item in transferItems.Where(t => t.TxId != null))
{
transfers.Add(new TransferInfo()
{
BlockHeight = blockHeight,
TimeStamp = block.Timestamp,
TxId = item.TxId,
From = item.From,
To = item.To,
Amount = item.Amount,
Asset = item.Asset,
Trigger = item.Trigger,
TokenId = item.TokenId
});
}
}
foreach (var transferInfo in transfers)
{
_db.AddTransfer(transferInfo);
}
}
SyncBalanceChanges(blockHeight);

SyncContracts(blockHeight, blockTime);
_db.AddSyncIndex(blockHeight);

foreach (var transaction in block.Transactions)
CommitAndReset(hasTxs);
if (hasTxs)
{
_db.AddTransaction(new TransactionInfo()
{
TxId = transaction.Hash,
BlockHeight = blockHeight,
Sender = transaction.Sender,
Time = blockTime,
});
Console.WriteLine($"Synced:{_scanHeight}[{block.Transactions.Length}]");
}
return true;
}


var transfers = new List<TransferInfo>();
var transferItems = _levelDb.GetTransfers(blockHeight);
if (transferItems.NotEmpty())
private void CommitAndReset(bool immediate)
{
var deadline = _db.LiveTime.TotalSeconds > 15;
if (immediate || deadline)
{
foreach (var item in transferItems)
{
transfers.Add(new TransferInfo()
{
BlockHeight = blockHeight,
TimeStamp = block.Timestamp,
TxId = item.TxId,
From = item.From,
To = item.To,
Amount = item.Amount,
Asset = item.Asset,
Trigger = item.Trigger,
TokenId = item.TokenId
});
}
_db.Commit();
}

foreach (var transferInfo in transfers)
if (deadline)
{
_db.AddTransfer(transferInfo);
//release memory
_db.Dispose();
_db = new TrackDB();
}
}


/// <summary>
/// Should run after <see cref="SyncContracts"/> method
/// update record will save after call <see cref="_db.Commit()"/> method;
/// new record will save immediately
/// </summary>
/// <param name="blockHeight"></param>
private void SyncBalanceChanges(uint blockHeight)
{
var balanceChanges = _levelDb.GetBalancingAccounts(blockHeight);
if (balanceChanges.NotEmpty())
{
Expand All @@ -148,25 +178,13 @@ public async Task<bool> Sync(uint blockHeight)
UpdateBalance(balanceChange.Account, balanceChange.Asset, snapshot);
}
}

_db.AddSyncIndex(blockHeight);
_db.Commit();

if (block.Transactions.Length > 0)
{
//Console.WriteLine($"Synced:{_scanHeight}[{block.Transactions.Length}] cost:[{_sw.ElapsedMilliseconds}]");
Console.WriteLine($"Synced:{_scanHeight}[{block.Transactions.Length}]");
}
if (_db.LiveTime.TotalSeconds > 15)
{
//release memory
_db.Dispose();
_db = new TrackDB();
}
return true;
}


/// <summary>
/// sync native contracts state into sqldb immediately
/// </summary>
/// <param name="blockTime"></param>
private void SyncNativeContracts(DateTime blockTime)
{
foreach (var nativeContract in NativeContract.Contracts)
Expand Down Expand Up @@ -194,7 +212,7 @@ private void SyncNativeContracts(DateTime blockTime)
}

/// <summary>
/// sync contract create\update\delete state
/// sync contract create\update\delete state into sqldb immediately
/// </summary>
/// <param name="blockHeight"></param>
/// <param name="blockTime"></param>
Expand Down Expand Up @@ -294,7 +312,13 @@ private Dictionary<UInt160, HashSet<string>> GetInvokeMethods(Transaction tx)
}



/// <summary>
/// update record will save after call <see cref="_db.Commit()"/> method;
/// new record will save immediately
/// </summary>
/// <param name="account"></param>
/// <param name="asset"></param>
/// <param name="snapshot"></param>
private void UpdateBalance(UInt160 account, UInt160 asset, DataCache snapshot)
{
try
Expand Down
40 changes: 14 additions & 26 deletions neo3-gui/neo3-gui/Common/Storage/LevelDBModules/LevelDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class LevelDbContext : IDisposable
private string _dbPath;

private readonly byte[] ExecuteLogPrefix = { 0xff };
private readonly byte[] SyncIndexPrefix = { 0xfe };
//private readonly byte[] SyncIndexPrefix = { 0xfe };
private readonly byte[] MaxSyncIndexPrefix = { 0xfd };
private readonly byte[] AssetPrefix = { 0xfc };
private readonly byte[] BalancePrefix = { 0xfb };
Expand Down Expand Up @@ -237,19 +237,7 @@ public List<TransferStorageItem> GetTransfers(uint blockHeight)
//private byte[] SyncIndexKey(byte[] db, uint height) => SyncIndexPrefix.Append(db, BitConverter.GetBytes(height));
private byte[] MaxSyncIndexKey(byte[] db) => MaxSyncIndexPrefix.Append(db);

/// <summary>
/// save synced height after call <see cref="Commit"/> method
/// </summary>
/// <param name="dbPrefix"></param>
/// <param name="height"></param>
/// <returns></returns>
public bool AddSyncIndex(byte[] dbPrefix, uint height)
{
//writeBatch.Put(SyncIndexKey(dbPrefix, height), new Byte[] { 1 });
//_db.Put(WriteOptions.Default, SyncIndexKey(dbPrefix, height), new Byte[] { 1 });
SetMaxSyncIndex(dbPrefix, height);
return true;
}


/// <summary>
/// is this height synced? true:yes
Expand All @@ -261,8 +249,6 @@ public bool HasSyncIndex(byte[] dbPrefix, uint height)
{
var max = GetMaxSyncIndex(dbPrefix);
return max >= height;
//var value = _db.Get(ReadOptions.Default, SyncIndexKey(dbPrefix, height));
//return value != null;
}

/// <summary>
Expand All @@ -275,11 +261,21 @@ public void SetMaxSyncIndex(byte[] dbPrefix, uint height)
var max = GetMaxSyncIndex(dbPrefix);
if (max == null || max < height)
{
writeBatch.Put(MaxSyncIndexKey(dbPrefix), BitConverter.GetBytes(height));
SetMaxSyncIndexForce(dbPrefix, height);
//_db.Put(WriteOptions.Default, MaxSyncIndexKey(dbPrefix), BitConverter.GetBytes(height));
}
}

/// <summary>
/// save synced max height after call <see cref="Commit"/> method
/// </summary>
/// <param name="dbPrefix"></param>
/// <param name="height"></param>
public void SetMaxSyncIndexForce(byte[] dbPrefix, uint height)
{
writeBatch.Put(MaxSyncIndexKey(dbPrefix), BitConverter.GetBytes(height));
}

public uint? GetMaxSyncIndex(byte[] dbPrefix)
{
var max = _db.Get(ReadOptions.Default, MaxSyncIndexKey(dbPrefix));
Expand All @@ -290,15 +286,7 @@ public void SetMaxSyncIndex(byte[] dbPrefix, uint height)
return BitConverter.ToUInt32(max);
}


public List<uint> ListSyncIndex(byte[] dbPrefix)
{
var result = _db.Find(ReadOptions.Default, SyncIndexPrefix.Concat(dbPrefix).ToArray(), (key, value) => key.Skip(17)).ToList();

return result.Select(r => BitConverter.ToUInt32(r.ToArray())).ToList();
}



public void Commit()
{
_db.Write(WriteOptions.Default, writeBatch);
Expand Down
Loading

0 comments on commit 5aa2afd

Please sign in to comment.