Skip to content
Merged

Refuel #2444

Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 9 additions & 1 deletion src/neo/SmartContract/ApplicationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public partial class ApplicationEngine : ExecutionEngine

private static IApplicationEngineProvider applicationEngineProvider;
private static Dictionary<uint, InteropDescriptor> services;
private readonly long gas_amount;
private long gas_amount;
private List<NotifyEventArgs> notifications;
private List<IDisposable> disposables;
private readonly Dictionary<UInt160, int> invocationCounter = new();
Expand Down Expand Up @@ -147,6 +147,14 @@ protected internal void AddGas(long gas)
throw new InvalidOperationException("Insufficient GAS.");
}

internal void Refuel(long gas)
{
checked
{
gas_amount += gas;
}
}

protected override void OnFault(Exception ex)
{
FaultException = ex;
Expand Down
12 changes: 12 additions & 0 deletions src/neo/SmartContract/Native/GasToken.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#pragma warning disable IDE0051

using Neo.Cryptography.ECC;
using Neo.Network.P2P.Payloads;
using System;

namespace Neo.SmartContract.Native
{
Expand Down Expand Up @@ -33,5 +36,14 @@ internal override async ContractTask OnPersist(ApplicationEngine engine)
UInt160 primary = Contract.CreateSignatureRedeemScript(validators[engine.PersistingBlock.PrimaryIndex]).ToScriptHash();
await Mint(engine, primary, totalNetworkFee, false);
}

[ContractMethod(RequiredCallFlags = CallFlags.States | CallFlags.AllowNotify)]
private async ContractTask Refuel(ApplicationEngine engine, UInt160 account, long amount)
{
if (amount < 0_01000000) throw new ArgumentOutOfRangeException(nameof(amount));
if (!engine.CheckWitnessInternal(account)) throw new InvalidOperationException();
await Burn(engine, account, amount);
engine.Refuel(amount);
}
}
}