diff --git a/neo b/neo index 26e9b6d..7d7c595 160000 --- a/neo +++ b/neo @@ -1 +1 @@ -Subproject commit 26e9b6df252678aefdb8ab625b0817a96dfa9732 +Subproject commit 7d7c59554466e7ee6bdbc09f478ba4c0cbeb604f diff --git a/neo3-gui/neo3-gui/Common/Analyzers/ExecuteResultLogTracker.cs b/neo3-gui/neo3-gui/Common/Analyzers/ExecuteResultLogTracker.cs index c856f1b..6c26957 100644 --- a/neo3-gui/neo3-gui/Common/Analyzers/ExecuteResultLogTracker.cs +++ b/neo3-gui/neo3-gui/Common/Analyzers/ExecuteResultLogTracker.cs @@ -11,13 +11,25 @@ namespace Neo.Common.Analyzers { - public class ExecuteResultLogTracker : Plugin, IPersistencePlugin + public class ExecuteResultLogTracker : Plugin { private readonly LevelDbContext _levelDb = new LevelDbContext(); private readonly HashSet _cachedAssets = new HashSet(); - void IPersistencePlugin.OnPersist(NeoSystem system, Block block, DataCache snapshot, IReadOnlyList applicationExecutedList) + public ExecuteResultLogTracker() + { + Blockchain.Committing += OnCommitting; + Blockchain.Committed += OnCommitted; + } + + public override void Dispose() + { + Blockchain.Committing -= OnCommitting; + Blockchain.Committed -= OnCommitted; + } + + void OnCommitting(NeoSystem system, Block block, DataCache snapshot, IReadOnlyList applicationExecutedList) { Header header = snapshot.GetCurrentHeader(); var analyzer = new BlockAnalyzer(snapshot, header, applicationExecutedList); @@ -59,7 +71,7 @@ void IPersistencePlugin.OnPersist(NeoSystem system, Block block, DataCache snaps } - void IPersistencePlugin.OnCommit(NeoSystem system, Block block, DataCache snapshot) + void OnCommitted(NeoSystem system, Block block) { _levelDb.Commit(); } diff --git a/neo3-gui/neo3-gui/Common/Consoles/MainService.cs b/neo3-gui/neo3-gui/Common/Consoles/MainService.cs index 6bcc07d..f129bea 100644 --- a/neo3-gui/neo3-gui/Common/Consoles/MainService.cs +++ b/neo3-gui/neo3-gui/Common/Consoles/MainService.cs @@ -148,8 +148,7 @@ public void CreateWallet(string path, string password) break; case ".json": { - NEP6Wallet wallet = new NEP6Wallet(path, CliSettings.Default.Protocol); - wallet.Unlock(password); + NEP6Wallet wallet = new NEP6Wallet(path, password, CliSettings.Default.Protocol); WalletAccount account = wallet.CreateAccount(); wallet.Save(); Console.WriteLine($"address: {account.Address}"); @@ -306,7 +305,7 @@ private bool OnInvokeCommand(string[] args) { scriptBuilder.EmitDynamicCall(scriptHash, args[2], contractParameters.ToArray()); tx.Script = scriptBuilder.ToArray(); - Console.WriteLine($"Invoking script with: '{tx.Script.ToHexString()}'"); + Console.WriteLine($"Invoking script with: '{tx.Script.ToArray().ToHexString()}'"); } using (ApplicationEngine engine = tx.Script.RunTestMode(null, tx)) @@ -1261,8 +1260,7 @@ public void OpenWallet(string path, string password) } else { - NEP6Wallet nep6wallet = new NEP6Wallet(path, CliSettings.Default.Protocol); - nep6wallet.Unlock(password); + NEP6Wallet nep6wallet = new NEP6Wallet(path, password, CliSettings.Default.Protocol); CurrentWallet = nep6wallet; } } diff --git a/neo3-gui/neo3-gui/Common/Utility/OpCodeConverter.cs b/neo3-gui/neo3-gui/Common/Utility/OpCodeConverter.cs index 4fa70ac..1ba8519 100644 --- a/neo3-gui/neo3-gui/Common/Utility/OpCodeConverter.cs +++ b/neo3-gui/neo3-gui/Common/Utility/OpCodeConverter.cs @@ -22,7 +22,7 @@ public class OpCodeConverter static OpCodeConverter() { //初始化所有 InteropService Method - _interopServiceMap = ApplicationEngine.Services.ToDictionary(s=>s.Key,s=>s.Value.Name); + _interopServiceMap = ApplicationEngine.Services.ToDictionary(s => s.Key, s => s.Value.Name); //初始化所有 OpCode OperandSize foreach (FieldInfo field in typeof(OpCode).GetFields(BindingFlags.Public | BindingFlags.Static)) { @@ -39,6 +39,13 @@ public static string ToAsciiString(byte[] byteArray) if (output.Any(p => p < '0' || p > 'z')) return byteArray.ToHexString(); return output; } + + + public static List Parse(ReadOnlyMemory scripts) + { + return Parse(scripts.ToArray()); + } + public static List Parse(byte[] scripts) { var result = new List(); @@ -50,7 +57,7 @@ public static List Parse(byte[] scripts) var instruction = s.GetInstruction(ip); var instructionInfo = new InstructionInfo() - {OpCode = instruction.OpCode, Position = ip, OpData = instruction.Operand.ToArray()}; + { OpCode = instruction.OpCode, Position = ip, OpData = instruction.Operand.ToArray() }; if (instruction.OpCode == OpCode.SYSCALL) { @@ -68,7 +75,7 @@ public static List Parse(byte[] scripts) { Console.WriteLine($"{scripts.ToHexString()}:{e}"); } - + return result; } diff --git a/neo3-gui/neo3-gui/Helpers.cs b/neo3-gui/neo3-gui/Helpers.cs index f961be9..0fe4159 100644 --- a/neo3-gui/neo3-gui/Helpers.cs +++ b/neo3-gui/neo3-gui/Helpers.cs @@ -46,6 +46,7 @@ using VmArray = Neo.VM.Types.Array; using JsonSerializer = System.Text.Json.JsonSerializer; using Pointer = Neo.VM.Types.Pointer; +using Neo.SmartContract.Iterators; namespace Neo { @@ -55,7 +56,7 @@ public static class Helpers public static readonly JsonSerializerOptions SerializeOptions = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, - IgnoreNullValues = true, + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, PropertyNameCaseInsensitive = true, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, Converters = @@ -628,7 +629,7 @@ public static AccountType GetAccountType(this WalletAccount account, DataCache s { if (account.Contract != null) { - if (account.Contract.Script.IsMultiSigContract(out _, out int _)) + if (account.Contract.Script.IsMultiSigContract()) { return AccountType.MultiSignature; } @@ -1179,6 +1180,12 @@ public static NotificationInfo ToNotificationInfo(this NotifyEventArgs notify) return notification; } + public static ApplicationEngine RunTestMode(this ReadOnlyMemory script, DataCache snapshot, IVerifiable container = null) + { + return ApplicationEngine.Run(script, snapshot ?? GetDefaultSnapshot(), container, settings: CliSettings.Default.Protocol, gas: Constant.TestMode); + } + + public static ApplicationEngine RunTestMode(this byte[] script, DataCache snapshot, IVerifiable container = null) { return ApplicationEngine.Run(script, snapshot ?? GetDefaultSnapshot(), container, settings: CliSettings.Default.Protocol, gas: Constant.TestMode); @@ -1427,5 +1434,46 @@ public static string ToBase64String(this ReadOnlySpan data) { return data.ToArray().ToBase64String(); } + + public static string ToBase64String(this Memory data) + { + return data.ToArray().ToBase64String(); + } + + + public static bool IsSignatureContract(this byte[] script) + { + return Neo.SmartContract.Helper.IsSignatureContract(script); + } + + public static bool IsMultiSigContract(this byte[] script) + { + return Neo.SmartContract.Helper.IsMultiSigContract(script); + } + + + public static (ECPoint PublicKey, BigInteger Votes)[] GetCandidates(this DataCache snapshot) + { + var sb = new ScriptBuilder(); + sb.EmitDynamicCall(NativeContract.NEO.Hash, "getCandidates"); + var engine = sb.ToArray().RunTestMode(snapshot); + var array = engine.ResultStack.Pop() as VmArray; + var list = new List<(ECPoint PublicKey, BigInteger Votes)>(); + if (array.Count > 0) + { + foreach (Struct item in array) + { + list.Add((ECPoint.FromBytes(item[0].GetSpan().ToArray(), ECCurve.Secp256r1), item[1].GetInteger())); + } + + } + //var iterator = iop.GetInterface(); + //var first = iterator.Value; + //while (iterator.Next()) + //{ + // var val = iterator.Value; + //} + return list.ToArray(); + } } } diff --git a/neo3-gui/neo3-gui/Models/Contracts/ContractModel.cs b/neo3-gui/neo3-gui/Models/Contracts/ContractModel.cs index 57c732c..d53de2e 100644 --- a/neo3-gui/neo3-gui/Models/Contracts/ContractModel.cs +++ b/neo3-gui/neo3-gui/Models/Contracts/ContractModel.cs @@ -12,7 +12,7 @@ public class ContractModel public ContractModel(ContractState contract) { ContractId = contract.Id; - Script = contract.Script; + Script = contract.Script.ToArray(); Manifest = new ManifestModel(contract.Manifest); } diff --git a/neo3-gui/neo3-gui/Models/Transactions/TransactionModel.cs b/neo3-gui/neo3-gui/Models/Transactions/TransactionModel.cs index 29245e8..ee300ab 100644 --- a/neo3-gui/neo3-gui/Models/Transactions/TransactionModel.cs +++ b/neo3-gui/neo3-gui/Models/Transactions/TransactionModel.cs @@ -19,8 +19,8 @@ public TransactionModel(Transaction tx) TxId = tx.Hash; NetworkFee = new BigDecimal((BigInteger)tx.NetworkFee, NativeContract.GAS.Decimals); Nonce = tx.Nonce; - Script = tx.Script; - + Script = tx.Script.ToArray(); + Sender = tx.Sender; SystemFee = new BigDecimal((BigInteger)tx.SystemFee, NativeContract.GAS.Decimals); ValidUntilBlock = tx.ValidUntilBlock; @@ -34,7 +34,7 @@ public TransactionModel(Transaction tx) Witnesses = tx.Witnesses?.Select(w => new WitnessModel(w) ).ToList(); - if (tx.Script != null) + if (tx.Script.Length > 0) { ScriptCode = OpCodeConverter.Parse(tx.Script); } diff --git a/neo3-gui/neo3-gui/Models/Transactions/WitnessModel.cs b/neo3-gui/neo3-gui/Models/Transactions/WitnessModel.cs index fbbe637..4c9f450 100644 --- a/neo3-gui/neo3-gui/Models/Transactions/WitnessModel.cs +++ b/neo3-gui/neo3-gui/Models/Transactions/WitnessModel.cs @@ -12,8 +12,8 @@ public WitnessModel(Witness witness) { if (witness != null) { - InvocationScript = witness.InvocationScript; - VerificationScript = witness.VerificationScript; + InvocationScript = witness.InvocationScript.ToArray(); + VerificationScript = witness.VerificationScript.ToArray(); ScriptHash = witness.ScriptHash; InvocationOpCode = OpCodeConverter.Parse(witness.InvocationScript); VerificationOpCode = OpCodeConverter.Parse(witness.VerificationScript); diff --git a/neo3-gui/neo3-gui/Plugins/LevelDBStore.dll b/neo3-gui/neo3-gui/Plugins/LevelDBStore.dll index 2e1a4e6..be67fdd 100644 Binary files a/neo3-gui/neo3-gui/Plugins/LevelDBStore.dll and b/neo3-gui/neo3-gui/Plugins/LevelDBStore.dll differ diff --git a/neo3-gui/neo3-gui/Services/ApiServices/ContractApiService.cs b/neo3-gui/neo3-gui/Services/ApiServices/ContractApiService.cs index e468dcb..d3c513a 100644 --- a/neo3-gui/neo3-gui/Services/ApiServices/ContractApiService.cs +++ b/neo3-gui/neo3-gui/Services/ApiServices/ContractApiService.cs @@ -95,7 +95,7 @@ public async Task DeployContract(string nefPath, string manifestPath = n // Read manifest ContractManifest manifest = ReadManifestFile(manifestPath); // Basic script checks - await CheckBadOpcode(nefFile.Script); + await CheckBadOpcode(nefFile.Script.ToArray()); // Build script using ScriptBuilder sb = new ScriptBuilder(); @@ -168,7 +168,7 @@ public async Task UpdateContract(UInt160 contractHash, string nefPath, s // Read manifest ContractManifest manifest = ReadManifestFile(manifestPath); // Basic script checks - await CheckBadOpcode(nefFile.Script); + await CheckBadOpcode(nefFile.Script.ToArray()); // Build script using ScriptBuilder sb = new ScriptBuilder(); @@ -456,7 +456,8 @@ public async Task GetValidators() { var snapshot = Helpers.GetDefaultSnapshot(); var validators = NativeContract.NEO.GetCommittee(snapshot); - var candidates = NativeContract.NEO.GetCandidates(snapshot); + //var candidates = NativeContract.NEO.GetCandidates(snapshot); + var candidates = snapshot.GetCandidates(); return candidates.OrderByDescending(v => v.Votes).Select(p => new ValidatorModel { Publickey = p.PublicKey.ToString(), @@ -468,6 +469,7 @@ public async Task GetValidators() + /// /// apply for new validator /// @@ -493,7 +495,8 @@ public async Task ApplyForValidator(string pubkey) return Error(ErrorCode.InvalidPara); } var snapshot = Helpers.GetDefaultSnapshot(); - var candidates = NativeContract.NEO.GetCandidates(snapshot); + //var candidates = NativeContract.NEO.GetCandidates(snapshot); + var candidates = snapshot.GetCandidates(); if (candidates.Any(v => v.PublicKey.Equals(publicKey))) { return Error(ErrorCode.ValidatorAlreadyExist); @@ -573,7 +576,7 @@ private NefFile ReadNefFile(string nefPath) { throw new WsException(ErrorCode.ExceedMaxTransactionSize); } - using var stream = new BinaryReader(File.OpenRead(nefPath), Encoding.UTF8, false); + var stream = new MemoryReader(File.ReadAllBytes(nefPath)); try { return stream.ReadSerializable(); diff --git a/neo3-gui/neo3-gui/Services/ApiServices/WalletApiService.cs b/neo3-gui/neo3-gui/Services/ApiServices/WalletApiService.cs index 3ccd53f..8f09227 100644 --- a/neo3-gui/neo3-gui/Services/ApiServices/WalletApiService.cs +++ b/neo3-gui/neo3-gui/Services/ApiServices/WalletApiService.cs @@ -108,8 +108,7 @@ public async Task CreateWallet(string path, string password, string priv break; case ".json": { - NEP6Wallet wallet = new NEP6Wallet(path, CliSettings.Default.Protocol); - wallet.Unlock(password); + NEP6Wallet wallet = new NEP6Wallet(path, password, CliSettings.Default.Protocol); var account = hexPrivateKey.NotEmpty() ? wallet.CreateAccount(hexPrivateKey) : wallet.CreateAccount(); wallet.Save(); result.Accounts.Add(new AccountModel() diff --git a/neo3-gui/neo3-gui/config.private.json b/neo3-gui/neo3-gui/config.private.json index b0c24ae..f885d35 100644 --- a/neo3-gui/neo3-gui/config.private.json +++ b/neo3-gui/neo3-gui/config.private.json @@ -7,7 +7,7 @@ }, "Storage": { "Engine": "LevelDBStore", - "Path": "Data_LevelDB_4444" + "Path": "Data_LevelDB_330" }, "P2P": { "Port": 30333, @@ -16,7 +16,7 @@ "PluginURL": "https://github.com/neo-project/neo-modules/releases/download/v{1}/{0}.zip" }, "ProtocolConfiguration": { - "Network": 4444, + "Network": 330, "MillisecondsPerBlock": 15000, "MaxTraceableBlocks": 2102400, "ValidatorsCount": 1, diff --git a/neo3-gui/neo3-gui/neo3-gui.csproj b/neo3-gui/neo3-gui/neo3-gui.csproj index 06795cb..74bde1b 100644 --- a/neo3-gui/neo3-gui/neo3-gui.csproj +++ b/neo3-gui/neo3-gui/neo3-gui.csproj @@ -24,13 +24,13 @@ - + - +