From 75f4767b08b6f2291e0c202a2f4ce5c697fefc95 Mon Sep 17 00:00:00 2001 From: Luchuan Date: Wed, 24 Jun 2020 14:55:45 +0800 Subject: [PATCH 1/4] fix --- neo-cli/CLI/MainService.Contracts.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo-cli/CLI/MainService.Contracts.cs b/neo-cli/CLI/MainService.Contracts.cs index 9fd97c73f..fd17751b3 100644 --- a/neo-cli/CLI/MainService.Contracts.cs +++ b/neo-cli/CLI/MainService.Contracts.cs @@ -57,7 +57,7 @@ private void OnInvokeCommand(UInt160 scriptHash, string operation, JArray contra { using (SnapshotView snapshot = Blockchain.Singleton.GetSnapshot()) { - UInt160[] accounts = CurrentWallet.GetAccounts().Where(p => !p.Lock && !p.WatchOnly).Select(p => p.ScriptHash).Where(p => NativeContract.GAS.BalanceOf(snapshot, p).Sign > 0).ToArray(); + UInt160[] accounts = CurrentWallet.GetAccounts().Where(p => !p.Lock && !p.WatchOnly).Select(p => p.ScriptHash).ToArray(); foreach (var signAccount in accounts) { if (witnessAddress is null) From 870e4b07977df178cec61d69f4e906d67dc11b26 Mon Sep 17 00:00:00 2001 From: Luchuan Date: Wed, 24 Jun 2020 17:21:46 +0800 Subject: [PATCH 2/4] optimize --- neo-cli/CLI/MainService.Contracts.cs | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/neo-cli/CLI/MainService.Contracts.cs b/neo-cli/CLI/MainService.Contracts.cs index fd17751b3..6ffcf7839 100644 --- a/neo-cli/CLI/MainService.Contracts.cs +++ b/neo-cli/CLI/MainService.Contracts.cs @@ -51,35 +51,14 @@ private void OnDeployCommand(string filePath, string manifestPath = null) [ConsoleCommand("invoke", Category = "Contract Commands")] private void OnInvokeCommand(UInt160 scriptHash, string operation, JArray contractParameters = null, UInt160[] witnessAddress = null) { - List signCollection = new List(); - + Cosigner[] cosigners = new Cosigner[0]; if (witnessAddress != null && !NoWallet()) - { - using (SnapshotView snapshot = Blockchain.Singleton.GetSnapshot()) - { - UInt160[] accounts = CurrentWallet.GetAccounts().Where(p => !p.Lock && !p.WatchOnly).Select(p => p.ScriptHash).ToArray(); - foreach (var signAccount in accounts) - { - if (witnessAddress is null) - { - break; - } - foreach (var witness in witnessAddress) - { - if (witness.Equals(signAccount)) - { - signCollection.Add(new Cosigner() { Account = signAccount }); - break; - } - } - } - } - } + cosigners = CurrentWallet.GetAccounts().Where(p => !p.Lock && !p.WatchOnly && witnessAddress.Contains(p.ScriptHash)).Select(p => new Cosigner() { Account = p.ScriptHash }).ToArray(); Transaction tx = new Transaction { Sender = UInt160.Zero, - Attributes = signCollection.ToArray(), + Attributes = cosigners, Witnesses = Array.Empty(), }; From dcd844611e48b7eb08b675dc4544993df5a85b59 Mon Sep 17 00:00:00 2001 From: Luchuan Date: Tue, 30 Jun 2020 09:50:26 +0800 Subject: [PATCH 3/4] fix cosigner scope --- neo-cli/CLI/MainService.Contracts.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo-cli/CLI/MainService.Contracts.cs b/neo-cli/CLI/MainService.Contracts.cs index 6ffcf7839..f4f3463c7 100644 --- a/neo-cli/CLI/MainService.Contracts.cs +++ b/neo-cli/CLI/MainService.Contracts.cs @@ -53,7 +53,7 @@ private void OnInvokeCommand(UInt160 scriptHash, string operation, JArray contra { Cosigner[] cosigners = new Cosigner[0]; if (witnessAddress != null && !NoWallet()) - cosigners = CurrentWallet.GetAccounts().Where(p => !p.Lock && !p.WatchOnly && witnessAddress.Contains(p.ScriptHash)).Select(p => new Cosigner() { Account = p.ScriptHash }).ToArray(); + cosigners = CurrentWallet.GetAccounts().Where(p => !p.Lock && !p.WatchOnly && witnessAddress.Contains(p.ScriptHash)).Select(p => new Cosigner() { Account = p.ScriptHash, Scopes = WitnessScope.CalledByEntry }).ToArray(); Transaction tx = new Transaction { From 7499d6dff3af3a059e2753ea0ed1b8dc54d42246 Mon Sep 17 00:00:00 2001 From: Shargon Date: Fri, 3 Jul 2020 08:51:57 +0200 Subject: [PATCH 4/4] Clean code --- neo-cli/CLI/MainService.Contracts.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo-cli/CLI/MainService.Contracts.cs b/neo-cli/CLI/MainService.Contracts.cs index f4f3463c7..0972062f6 100644 --- a/neo-cli/CLI/MainService.Contracts.cs +++ b/neo-cli/CLI/MainService.Contracts.cs @@ -51,7 +51,7 @@ private void OnDeployCommand(string filePath, string manifestPath = null) [ConsoleCommand("invoke", Category = "Contract Commands")] private void OnInvokeCommand(UInt160 scriptHash, string operation, JArray contractParameters = null, UInt160[] witnessAddress = null) { - Cosigner[] cosigners = new Cosigner[0]; + Cosigner[] cosigners = Array.Empty(); if (witnessAddress != null && !NoWallet()) cosigners = CurrentWallet.GetAccounts().Where(p => !p.Lock && !p.WatchOnly && witnessAddress.Contains(p.ScriptHash)).Select(p => new Cosigner() { Account = p.ScriptHash, Scopes = WitnessScope.CalledByEntry }).ToArray();