Skip to content
This repository was archived by the owner on Dec 7, 2023. It is now read-only.

apply signers #622

Merged
merged 7 commits into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions neo-cli/CLI/MainService.Contracts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,15 @@ private void OnDeployCommand(string filePath, string manifestPath = null)
/// <param name="contractParameters">Contract parameters</param>
/// <param name="witnessAddress">Witness address</param>
[ConsoleCommand("invoke", Category = "Contract Commands")]
private void OnInvokeCommand(UInt160 scriptHash, string operation, JArray contractParameters = null, UInt160[] witnessAddress = null)
private void OnInvokeCommand(UInt160 scriptHash, string operation, JArray contractParameters = null, UInt160[] signerAccounts = null)
{
Cosigner[] cosigners = Array.Empty<Cosigner>();
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();
Signer[] signers = Array.Empty<Signer>();
if (signerAccounts != null && !NoWallet())
signers = CurrentWallet.GetAccounts().Where(p => !p.Lock && !p.WatchOnly && signerAccounts.Contains(p.ScriptHash)).Select(p => new Signer() { Account = p.ScriptHash, Scopes = WitnessScope.CalledByEntry }).ToArray();

Transaction tx = new Transaction
{
Sender = UInt160.Zero,
Attributes = cosigners,
Signers = signers,
Witnesses = Array.Empty<Witness>(),
};

Expand All @@ -67,7 +66,7 @@ private void OnInvokeCommand(UInt160 scriptHash, string operation, JArray contra
if (NoWallet()) return;
try
{
tx = CurrentWallet.MakeTransaction(tx.Script, null, tx.Attributes);
tx = CurrentWallet.MakeTransaction(tx.Script, signers.Length > 0 ? signers[0].Account : null, signers);
}
catch (InvalidOperationException)
{
Expand Down
18 changes: 9 additions & 9 deletions neo-cli/CLI/MainService.Vote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,49 @@ partial class MainService
/// <summary>
/// Process "register candidate" command
/// </summary>
/// <param name="senderAccount">Sender account</param>
/// <param name="senderPublicKey">Register publicKey</param>
/// <param name="account">register account scriptHash</param>
[ConsoleCommand("register candidate", Category = "Vote Commands")]
private void OnRegisterCandidateCommand(UInt160 senderAccount, ECPoint senderPublicKey)
private void OnRegisterCandidateCommand(UInt160 account)
{
if (NoWallet())
{
Console.WriteLine("Need open wallet!");
return;
}

ECPoint publicKey = CurrentWallet.GetAccount(account)?.GetKey()?.PublicKey;
byte[] script;
using (ScriptBuilder scriptBuilder = new ScriptBuilder())
{
scriptBuilder.EmitAppCall(NativeContract.NEO.Hash, "registerCandidate", senderPublicKey);
scriptBuilder.EmitAppCall(NativeContract.NEO.Hash, "registerCandidate", publicKey);
script = scriptBuilder.ToArray();
}

SendTransaction(script, senderAccount);
SendTransaction(script, account);
}

/// <summary>
/// Process "unregister candidate" command
/// </summary>
/// <param name="senderAccount">Sender account</param>
/// <param name="publicKey">Unregister publicKey</param>
/// <param name="account">unregister account scriptHash</param>
[ConsoleCommand("unregister candidate", Category = "Vote Commands")]
private void OnUnregisterCandidateCommand(UInt160 senderAccount, ECPoint publicKey)
private void OnUnregisterCandidateCommand(UInt160 account)
{
if (NoWallet())
{
Console.WriteLine("Need open wallet!");
return;
}

ECPoint publicKey = CurrentWallet.GetAccount(account)?.GetKey()?.PublicKey;
byte[] script;
using (ScriptBuilder scriptBuilder = new ScriptBuilder())
{
scriptBuilder.EmitAppCall(NativeContract.NEO.Hash, "unregisterCandidate", publicKey);
script = scriptBuilder.ToArray();
}

SendTransaction(script, senderAccount);
SendTransaction(script, account);
}

/// <summary>
Expand Down
19 changes: 7 additions & 12 deletions neo-cli/CLI/MainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ private byte[] LoadDeploymentScript(string nefFilePath, string manifestFilePath,

// Basic script checks

using (var engine = new ApplicationEngine(TriggerType.Application, null, null, 0, true))
using (var engine = ApplicationEngine.Create(TriggerType.Application, null, null, 0, true))
{
var context = engine.LoadScript(file.Script);

Expand Down Expand Up @@ -474,27 +474,22 @@ private static void WriteLineWithoutFlicker(string message = "", int maxWidth =
/// <param name="account">sender</param>
private void SendTransaction(byte[] script, UInt160 account = null)
{
List<Cosigner> signCollection = new List<Cosigner>();
Signer[] signers = System.Array.Empty<Signer>();

if (account != null)
{
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();
foreach (var signAccount in accounts)
{
if (account.Equals(signAccount))
{
signCollection.Add(new Cosigner() { Account = signAccount });
break;
}
}
signers = CurrentWallet.GetAccounts()
.Where(p => !p.Lock && !p.WatchOnly && p.ScriptHash == account && NativeContract.GAS.BalanceOf(snapshot, p.ScriptHash).Sign > 0)
.Select(p => new Signer() { Account = p.ScriptHash, Scopes = WitnessScope.CalledByEntry })
.ToArray();
}
}

try
{
Transaction tx = CurrentWallet.MakeTransaction(script, account, signCollection?.ToArray());
Transaction tx = CurrentWallet.MakeTransaction(script, account, signers);
Console.WriteLine($"Invoking script with: '{tx.Script.ToHexString()}'");

using (ApplicationEngine engine = ApplicationEngine.Run(tx.Script, tx, null, testMode: true))
Expand Down
2 changes: 1 addition & 1 deletion neo-cli/neo-cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="3.0.0-CI00968" />
<PackageReference Include="Neo" Version="3.0.0-CI00970" />
</ItemGroup>

<ItemGroup>
Expand Down