Skip to content
Closed
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
5 changes: 5 additions & 0 deletions src/neo/SmartContract/ApplicationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public partial class ApplicationEngine : ExecutionEngine
/// The maximum cost that can be spent when a contract is executed in test mode.
/// </summary>
public const long TestModeGas = 20_00000000;
public const long GasRefueledLimit = 1_00000000;

/// <summary>
/// Triggered when a contract calls System.Runtime.Notify.
Expand Down Expand Up @@ -85,6 +86,7 @@ public partial class ApplicationEngine : ExecutionEngine
/// GAS spent to execute.
/// </summary>
public long GasConsumed { get; private set; } = 0;
public long GasRefueledSummary { get; private set; } = 0;

/// <summary>
/// The remaining GAS that can be spent in order to complete the execution.
Expand Down Expand Up @@ -160,6 +162,9 @@ internal void Refuel(long gas)
{
checked
{
GasRefueledSummary += gas;
if (GasRefueledLimit < GasRefueledSummary)
throw new InvalidOperationException("Exceed gas refuel limit");
gas_amount += gas;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/neo/SmartContract/Native/GasToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ internal override async ContractTask OnPersist(ApplicationEngine engine)
[ContractMethod(CpuFee = 1 << 15, RequiredCallFlags = CallFlags.States | CallFlags.AllowNotify)]
private async ContractTask Refuel(ApplicationEngine engine, UInt160 account, long amount)
{
if (amount < 0) throw new ArgumentOutOfRangeException(nameof(amount));
if (amount <= 0) throw new ArgumentOutOfRangeException(nameof(amount));
if (!engine.CheckWitnessInternal(account)) throw new InvalidOperationException();
await Burn(engine, account, amount);
engine.Refuel(amount);
await Burn(engine, account, amount);
}
}
}