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

Add test mode gas when invoking #727

Merged
merged 24 commits into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7ac584b
add test mode gas
bettybao1209 Jan 25, 2021
4995de0
register type long
bettybao1209 Jan 25, 2021
fa76d8e
Merge branch 'master' into add-testgas
bettybao1209 Jan 25, 2021
1159bc0
add comments
bettybao1209 Jan 25, 2021
5e86b95
Merge branch 'add-testgas' of https://github.com/bettybao1209/neo-nod…
bettybao1209 Jan 25, 2021
a85b767
add more comments
bettybao1209 Jan 26, 2021
912624a
add test gas for registerCandidate and redefine gas
bettybao1209 Jan 26, 2021
2fd4e81
format
bettybao1209 Jan 26, 2021
509a5c5
Merge branch 'master' of https://github.com/neo-project/neo-node into…
bettybao1209 Jan 29, 2021
cb8e021
enable null and use decimal type
bettybao1209 Jan 30, 2021
5eefb1f
fix ut
bettybao1209 Jan 30, 2021
bef9ea2
Merge branch 'master' into add-testgas
Tommo-L Jan 31, 2021
29ab4ef
Merge branch 'master' of https://github.com/neo-project/neo-node into…
bettybao1209 Jan 31, 2021
c3ef784
format
bettybao1209 Jan 31, 2021
66fec2b
Merge branch 'add-testgas' of https://github.com/bettybao1209/neo-nod…
bettybao1209 Jan 31, 2021
e8b8eaa
Update neo-cli/CLI/MainService.Vote.cs
shargon Jan 31, 2021
b9a205b
revert
bettybao1209 Jan 31, 2021
c4cc828
Merge branch 'add-testgas' of https://github.com/bettybao1209/neo-nod…
bettybao1209 Jan 31, 2021
9bc18dd
use bigdecimal constructor
bettybao1209 Feb 1, 2021
acdb99e
Remove using
erikzhang Feb 1, 2021
c17b2a6
uniformly use long type
bettybao1209 Feb 1, 2021
bb936f1
Merge branch 'add-testgas' of https://github.com/bettybao1209/neo-nod…
bettybao1209 Feb 1, 2021
69278ca
revert to use decimal
bettybao1209 Feb 1, 2021
c32f869
Update neo-cli/CLI/MainService.Contracts.cs
shargon Feb 1, 2021
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
1 change: 0 additions & 1 deletion Neo.ConsoleService/ConsoleServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ protected ConsoleServiceBase()
RegisterCommandHander<string, bool>(false, (str) => str == "1" || str == "yes" || str == "y" || bool.Parse(str));
RegisterCommandHander<string, ushort>(false, (str) => ushort.Parse(str));
RegisterCommandHander<string, uint>(false, (str) => uint.Parse(str));
RegisterCommandHander<string, long>(false, (str) => long.Parse(str));
RegisterCommandHander<string, IPAddress>(false, (str) => IPAddress.Parse(str));
}

Expand Down
18 changes: 15 additions & 3 deletions neo-cli/CLI/MainService.Contracts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Linq;
using System.Numerics;
using Neo.Wallets;

namespace Neo.CLI
{
Expand Down Expand Up @@ -50,8 +51,19 @@ private void OnDeployCommand(string filePath, string manifestPath = null)
/// <param name="signerAccounts">Signer's accounts</param>
/// <param name="gas">Max fee for running the script</param>
bettybao1209 marked this conversation as resolved.
Show resolved Hide resolved
[ConsoleCommand("invoke", Category = "Contract Commands")]
private void OnInvokeCommand(UInt160 scriptHash, string operation, JArray contractParameters = null, UInt160 sender = null, UInt160[] signerAccounts = null, long gas = TestModeGas)
private void OnInvokeCommand(UInt160 scriptHash, string operation, JArray contractParameters = null, UInt160 sender = null, UInt160[] signerAccounts = null, string gas = null)
bettybao1209 marked this conversation as resolved.
Show resolved Hide resolved
{
long gasAmount = TestModeGas;
if (!string.IsNullOrEmpty(gas))
{
AssetDescriptor descriptor = new AssetDescriptor(NativeContract.GAS.Hash);
if (!BigDecimal.TryParse(gas, descriptor.Decimals, out BigDecimal decimalAmount) || decimalAmount.Sign <= 0)
{
Console.WriteLine("Incorrect Amount Format");
return;
}
gasAmount = (long)decimalAmount.Value;
}
Signer[] signers = Array.Empty<Signer>();
if (signerAccounts != null && !NoWallet())
{
Expand All @@ -78,12 +90,12 @@ private void OnInvokeCommand(UInt160 scriptHash, string operation, JArray contra
Witnesses = Array.Empty<Witness>(),
};

if (!OnInvokeWithResult(scriptHash, operation, out _, tx, contractParameters, gas: gas)) return;
if (!OnInvokeWithResult(scriptHash, operation, out _, tx, contractParameters, gas: gasAmount)) return;

if (NoWallet()) return;
try
{
tx = CurrentWallet.MakeTransaction(tx.Script, sender, signers);
tx = CurrentWallet.MakeTransaction(tx.Script, sender, signers, gas: gasAmount);
}
catch (InvalidOperationException e)
{
Expand Down
20 changes: 17 additions & 3 deletions neo-cli/CLI/MainService.Vote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,27 @@ namespace Neo.CLI
{
partial class MainService
{
public const long RegisterGas = 1010_00000000;
/// <summary>
/// Process "register candidate" command
/// </summary>
/// <param name="account">register account scriptHash</param>
/// <param name="account">register account scriptHash</param>
/// <param name="gas">Max fee for running the script</param>
[ConsoleCommand("register candidate", Category = "Vote Commands")]
private void OnRegisterCandidateCommand(UInt160 account)
private void OnRegisterCandidateCommand(UInt160 account, string gas = null)
{
long gasAmount = RegisterGas;
if (!string.IsNullOrEmpty(gas))
{
AssetDescriptor descriptor = new AssetDescriptor(NativeContract.GAS.Hash);
if (!BigDecimal.TryParse(gas, descriptor.Decimals, out BigDecimal decimalAmount) || decimalAmount.Sign <= 0)
{
Console.WriteLine("Incorrect Amount Format");
return;
}
gasAmount = (long)decimalAmount.Value;
}

if (NoWallet())
{
Console.WriteLine("Need open wallet!");
Expand Down Expand Up @@ -47,7 +61,7 @@ private void OnRegisterCandidateCommand(UInt160 account)
script = scriptBuilder.ToArray();
}

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

/// <summary>
Expand Down
10 changes: 6 additions & 4 deletions neo-cli/CLI/MainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,10 @@ private static void WriteLineWithoutFlicker(string message = "", int maxWidth =
/// </summary>
/// <param name="script">script</param>
/// <param name="account">sender</param>
private void SendTransaction(byte[] script, UInt160 account = null)
/// <param name="gas">Max fee for running the script</param>
private void SendTransaction(byte[] script, UInt160 account = null, long gas = TestModeGas)
bettybao1209 marked this conversation as resolved.
Show resolved Hide resolved
{

bettybao1209 marked this conversation as resolved.
Show resolved Hide resolved
Signer[] signers = System.Array.Empty<Signer>();

if (account != null)
Expand All @@ -482,11 +484,11 @@ private void SendTransaction(byte[] script, UInt160 account = null)

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

using (ApplicationEngine engine = ApplicationEngine.Run(tx.Script, container: tx))
{
using (ApplicationEngine engine = ApplicationEngine.Run(tx.Script, container: tx, gas: gas))
{
PrintExecutionOutput(engine, true);
if (engine.State == VMState.FAULT) return;
}
Expand Down