diff --git a/neo b/neo index 28ab45a..a985eb3 160000 --- a/neo +++ b/neo @@ -1 +1 @@ -Subproject commit 28ab45a6eca51bacadfa2b84c27f445b40e50a24 +Subproject commit a985eb356e5ef9a1111e68db228b222b972bfcc2 diff --git a/neo3-gui/neo3-gui/ClientApp/package-lock.json b/neo3-gui/neo3-gui/ClientApp/package-lock.json index 61c48ee..8fb16ae 100644 --- a/neo3-gui/neo3-gui/ClientApp/package-lock.json +++ b/neo3-gui/neo3-gui/ClientApp/package-lock.json @@ -1,12 +1,12 @@ { "name": "new-gui", - "version": "1.5.0", + "version": "1.5.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "new-gui", - "version": "1.5.0", + "version": "1.5.1", "dependencies": { "@babel/core": "^7.16.0", "@electron/asar": "^3.2.1", diff --git a/neo3-gui/neo3-gui/ClientApp/package.json b/neo3-gui/neo3-gui/ClientApp/package.json index 5c39f85..2bf79d3 100644 --- a/neo3-gui/neo3-gui/ClientApp/package.json +++ b/neo3-gui/neo3-gui/ClientApp/package.json @@ -1,6 +1,6 @@ { "name": "new-gui", - "version": "1.5.0", + "version": "1.5.1", "private": true, "main": "main.js", "homepage": "./", diff --git a/neo3-gui/neo3-gui/ClientApp/src/neonode.js b/neo3-gui/neo3-gui/ClientApp/src/neonode.js index 1d5b751..1765325 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/neonode.js +++ b/neo3-gui/neo3-gui/ClientApp/src/neonode.js @@ -28,7 +28,13 @@ class NeoNode { } start(env, errorCallback) { - this.node = this.runCommand("dotnet neo3-gui.dll", env, errorCallback); + if (isWin) { + this.node = this.runCommand("./neo3-gui.exe", env, errorCallback); + + } else { + this.node = this.runCommand("./neo3-gui", env, errorCallback); + } + // this.node = this.runCommand("dotnet neo3-gui.dll", env, errorCallback); } startNode(network, port, errorCallback) { @@ -40,7 +46,7 @@ class NeoNode { * force restart node after 1 second (using config file) */ switchNode(network) { - console.log("switche to:", network); + console.log("switch to:", network); if (network) { Config.changeNetwork(network); } @@ -82,7 +88,7 @@ class NeoNode { } const ps = spawn(command, [], { - shell: true, + shell: false, encoding: "utf8", cwd: path.join(startPath, "build-neo-node"), env: childEnv, diff --git a/neo3-gui/neo3-gui/Common/Analyzers/BlockAnalyzer.cs b/neo3-gui/neo3-gui/Common/Analyzers/BlockAnalyzer.cs index 0c6b870..cb53c35 100644 --- a/neo3-gui/neo3-gui/Common/Analyzers/BlockAnalyzer.cs +++ b/neo3-gui/neo3-gui/Common/Analyzers/BlockAnalyzer.cs @@ -11,7 +11,6 @@ using Neo.SmartContract; using Neo.SmartContract.Native; using Neo.VM; -using Array = Neo.VM.Types.Array; namespace Neo.Common.Analyzers { @@ -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); + } diff --git a/neo3-gui/neo3-gui/Common/Consoles/MainService.cs b/neo3-gui/neo3-gui/Common/Consoles/MainService.cs index 70f049f..3a582f9 100644 --- a/neo3-gui/neo3-gui/Common/Consoles/MainService.cs +++ b/neo3-gui/neo3-gui/Common/Consoles/MainService.cs @@ -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; @@ -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; @@ -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; + } diff --git a/neo3-gui/neo3-gui/Common/Scanners/ExecuteResultScanner.cs b/neo3-gui/neo3-gui/Common/Scanners/ExecuteResultScanner.cs index 01d30b9..d2dd837 100644 --- a/neo3-gui/neo3-gui/Common/Scanners/ExecuteResultScanner.cs +++ b/neo3-gui/neo3-gui/Common/Scanners/ExecuteResultScanner.cs @@ -86,7 +86,6 @@ public async Task Sync(uint blockHeight) return true; } - var block = blockHeight.GetBlock(); var blockTime = block.Timestamp.FromTimestampMS(); if (blockHeight == 0) @@ -94,51 +93,82 @@ public async Task Sync(uint blockHeight) 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(); + 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(); - 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(); } + } + + /// + /// Should run after method + /// update record will save after call method; + /// new record will save immediately + /// + /// + private void SyncBalanceChanges(uint blockHeight) + { var balanceChanges = _levelDb.GetBalancingAccounts(blockHeight); if (balanceChanges.NotEmpty()) { @@ -148,25 +178,13 @@ public async Task 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; } + /// + /// sync native contracts state into sqldb immediately + /// + /// private void SyncNativeContracts(DateTime blockTime) { foreach (var nativeContract in NativeContract.Contracts) @@ -194,7 +212,7 @@ private void SyncNativeContracts(DateTime blockTime) } /// - /// sync contract create\update\delete state + /// sync contract create\update\delete state into sqldb immediately /// /// /// @@ -294,7 +312,13 @@ private Dictionary> GetInvokeMethods(Transaction tx) } - + /// + /// update record will save after call method; + /// new record will save immediately + /// + /// + /// + /// private void UpdateBalance(UInt160 account, UInt160 asset, DataCache snapshot) { try diff --git a/neo3-gui/neo3-gui/Common/Storage/LevelDBModules/LevelDbContext.cs b/neo3-gui/neo3-gui/Common/Storage/LevelDBModules/LevelDbContext.cs index 69048fe..8c98848 100644 --- a/neo3-gui/neo3-gui/Common/Storage/LevelDBModules/LevelDbContext.cs +++ b/neo3-gui/neo3-gui/Common/Storage/LevelDBModules/LevelDbContext.cs @@ -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 }; @@ -237,19 +237,7 @@ public List GetTransfers(uint blockHeight) //private byte[] SyncIndexKey(byte[] db, uint height) => SyncIndexPrefix.Append(db, BitConverter.GetBytes(height)); private byte[] MaxSyncIndexKey(byte[] db) => MaxSyncIndexPrefix.Append(db); - /// - /// save synced height after call method - /// - /// - /// - /// - 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; - } + /// /// is this height synced? true:yes @@ -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; } /// @@ -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)); } } + /// + /// save synced max height after call method + /// + /// + /// + 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)); @@ -290,15 +286,7 @@ public void SetMaxSyncIndex(byte[] dbPrefix, uint height) return BitConverter.ToUInt32(max); } - - public List 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); diff --git a/neo3-gui/neo3-gui/Common/Storage/SQLiteModules/IRepository.cs b/neo3-gui/neo3-gui/Common/Storage/SQLiteModules/IRepository.cs new file mode 100644 index 0000000..ad28491 --- /dev/null +++ b/neo3-gui/neo3-gui/Common/Storage/SQLiteModules/IRepository.cs @@ -0,0 +1,146 @@ +using System; +using System.Collections.Generic; +using System.Numerics; +using Neo; +using Neo.Common.Storage; +using Neo.Common.Storage.SQLiteModules; +using Neo.Models; + +interface IRepository +{ + byte[] Identity { get; } + uint? GetMaxSyncIndex(); + void AddSyncIndex(uint index); + //void SetMaxSyncIndex(uint height); + + void AddTransfer(TransferInfo transfer); + void AddTransaction(TransactionInfo transaction); + + + void UpdateBalance(UInt160 addressHash, UInt160 assetHash, BigInteger balance, uint height); + + PageList QueryTransactions(TransactionFilter filter, bool includeTransfers = false); + IEnumerable FindAssetBalance(BalanceFilter filter); + + void CreateContract(ContractEntity newContract); + void DeleteContract(UInt160 contractHash, UInt256 txId, DateTime time); + void MigrateContract(ContractEntity migrateContract); + IEnumerable GetAllContracts(); + + ContractEntity GetActiveContract(UInt160 contract); + ContractEntity GetActiveContract(string contractHash); + ContractEntity GetContract(long id); + AddressEntity GetAddress(long id); + void Commit(); +} + +public class SQLiteRepository : IRepository +{ + private SQLiteContext _db; + + public SQLiteRepository(string path) + { + _db = new SQLiteContext(path); + } + public byte[] Identity => _db.Identity; + public uint? GetMaxSyncIndex() + { + return _db.GetMaxSyncIndex(); + } + + public void AddSyncIndex(uint index) + { + _db.Add(new SyncIndex() { BlockHeight = index }); + } + + //public void SetMaxSyncIndex(uint height) + //{ + // throw new NotImplementedException(); + //} + + public void AddTransfer(TransferInfo transfer) + { + //var from = GetOrCreateAddress(transfer.From); + //var to = GetOrCreateAddress(transfer.To); + //var asset = GetActiveContract(transfer.Asset); + + //var tran = new TransferEntity + //{ + // BlockHeight = transfer.BlockHeight, + // TxId = transfer.TxId?.ToBigEndianHex(), + // FromId = from?.Id, + // ToId = to?.Id, + // Amount = transfer.Amount.ToByteArray(), + // AssetId = asset.Id, + // Time = transfer.TimeStamp.FromTimestampMS(), + // Trigger = transfer.Trigger, + // TokenId = transfer.TokenId, + //}; + //_db.Transfers.Add(tran); + } + + public void AddTransaction(TransactionInfo transaction) + { + throw new NotImplementedException(); + } + + public void UpdateBalance(UInt160 addressHash, UInt160 assetHash, BigInteger balance, uint height) + { + throw new NotImplementedException(); + } + + public PageList QueryTransactions(TransactionFilter filter, bool includeTransfers = false) + { + throw new NotImplementedException(); + } + + public IEnumerable FindAssetBalance(BalanceFilter filter) + { + throw new NotImplementedException(); + } + + public void CreateContract(ContractEntity newContract) + { + throw new NotImplementedException(); + } + + public void DeleteContract(UInt160 contractHash, UInt256 txId, DateTime time) + { + throw new NotImplementedException(); + } + + public void MigrateContract(ContractEntity migrateContract) + { + throw new NotImplementedException(); + } + + public IEnumerable GetAllContracts() + { + throw new NotImplementedException(); + } + + public ContractEntity GetActiveContract(UInt160 contract) + { + throw new NotImplementedException(); + } + + public ContractEntity GetActiveContract(string contractHash) + { + throw new NotImplementedException(); + } + + public ContractEntity GetContract(long id) + { + throw new NotImplementedException(); + } + + public AddressEntity GetAddress(long id) + { + throw new NotImplementedException(); + } + + public void Commit() + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/neo3-gui/neo3-gui/Common/Storage/TrackDB.cs b/neo3-gui/neo3-gui/Common/Storage/TrackDB.cs index 5fd5746..31e3f0a 100644 --- a/neo3-gui/neo3-gui/Common/Storage/TrackDB.cs +++ b/neo3-gui/neo3-gui/Common/Storage/TrackDB.cs @@ -79,11 +79,13 @@ public void InitConsistencyCheck() { return; } - if ((levelMax == null && sqlMax == 0) || levelMax < sqlMax) + //if ((levelMax == null && sqlMax == 0) || levelMax < sqlMax) + if (sqlMax.HasValue) { // try repair sync height - // when last sync: sqldb save successfully, but leveldb fails - _leveldb.AddSyncIndex(_sqldb.Identity, sqlMax.Value); + // when last sync: sqldb save successfully, set leveldb with same sqldb index + Console.WriteLine($"Warning height:level[{levelMax}]-sql[{sqlMax}]"); + _leveldb.SetMaxSyncIndexForce(_sqldb.Identity, sqlMax.Value); _leveldb.Commit(); return; } @@ -100,7 +102,7 @@ public void Commit() public void AddSyncIndex(uint index) { - _leveldb.AddSyncIndex(_sqldb.Identity, index); + _leveldb.SetMaxSyncIndex(_sqldb.Identity, index); _sqldb.SyncIndexes.Add(new SyncIndex() { BlockHeight = index }); } @@ -115,10 +117,6 @@ public bool HasSyncIndex(uint index) return _leveldb.GetMaxSyncIndex(_sqldb.Identity); } - public void SetMaxSyncIndex(uint index) - { - _leveldb.SetMaxSyncIndex(_sqldb.Identity, index); - } #endregion diff --git a/neo3-gui/neo3-gui/Services/ApiServices/WalletApiService.cs b/neo3-gui/neo3-gui/Services/ApiServices/WalletApiService.cs index c760e57..cc8c9e3 100644 --- a/neo3-gui/neo3-gui/Services/ApiServices/WalletApiService.cs +++ b/neo3-gui/neo3-gui/Services/ApiServices/WalletApiService.cs @@ -21,7 +21,6 @@ using Neo.VM; using Neo.Wallets; using Neo.Wallets.NEP6; -using Neo.Wallets.SQLite; using ECCurve = Neo.Cryptography.ECC.ECCurve; using ECPoint = Neo.Cryptography.ECC.ECPoint; @@ -86,20 +85,20 @@ public async Task CreateWallet(string path, string password, string priv { switch (Path.GetExtension(path)) { - case ".db3": - { - UserWallet wallet = UserWallet.Create(path, password, CliSettings.Default.Protocol); - var account = hexPrivateKey.NotEmpty() ? wallet.CreateAccount(hexPrivateKey) : wallet.CreateAccount(); - result.Accounts.Add(new AccountModel() - { - AccountType = AccountType.Standard, - Address = account.Address, - ScriptHash = account.ScriptHash, - - }); - Program.Starter.CurrentWallet = wallet; - } - break; + //case ".db3": + // { + // UserWallet wallet = UserWallet.Create(path, password, CliSettings.Default.Protocol); + // var account = hexPrivateKey.NotEmpty() ? wallet.CreateAccount(hexPrivateKey) : wallet.CreateAccount(); + // result.Accounts.Add(new AccountModel() + // { + // AccountType = AccountType.Standard, + // Address = account.Address, + // ScriptHash = account.ScriptHash, + + // }); + // Program.Starter.CurrentWallet = wallet; + // } + // break; case ".json": { NEP6Wallet wallet = new NEP6Wallet(path, password, CliSettings.Default.Protocol); diff --git a/neo3-gui/neo3-gui/neo3-gui.csproj b/neo3-gui/neo3-gui/neo3-gui.csproj index 5f7d456..e83a22c 100644 --- a/neo3-gui/neo3-gui/neo3-gui.csproj +++ b/neo3-gui/neo3-gui/neo3-gui.csproj @@ -23,17 +23,17 @@ - - + + - - - Always - - + + + + + Always diff --git a/neo3-gui/neo3-gui/publish.macos.sh b/neo3-gui/neo3-gui/publish.macos.sh new file mode 100644 index 0000000..ff4a6cd --- /dev/null +++ b/neo3-gui/neo3-gui/publish.macos.sh @@ -0,0 +1,4 @@ +dotnet publish -r osx-x64 --sc -c Release -o ClientApp/build-neo-node +cd ClientApp +npm install +npm run publish \ No newline at end of file