Skip to content

Commit

Permalink
Add Async to async method's name (#3206)
Browse files Browse the repository at this point in the history
* Add Async

* Add more
  • Loading branch information
shargon authored May 2, 2024
1 parent 629baf8 commit 429a081
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 39 deletions.
16 changes: 8 additions & 8 deletions src/Neo/SmartContract/ApplicationEngine.Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ partial class ApplicationEngine
/// The <see cref="InteropDescriptor"/> of System.Contract.NativeOnPersist.
/// </summary>
/// <remarks>Note: It is for internal use only. Do not use it directly in smart contracts.</remarks>
public static readonly InteropDescriptor System_Contract_NativeOnPersist = Register("System.Contract.NativeOnPersist", nameof(NativeOnPersist), 0, CallFlags.States);
public static readonly InteropDescriptor System_Contract_NativeOnPersist = Register("System.Contract.NativeOnPersist", nameof(NativeOnPersistAsync), 0, CallFlags.States);

/// <summary>
/// The <see cref="InteropDescriptor"/> of System.Contract.NativePostPersist.
/// </summary>
/// <remarks>Note: It is for internal use only. Do not use it directly in smart contracts.</remarks>
public static readonly InteropDescriptor System_Contract_NativePostPersist = Register("System.Contract.NativePostPersist", nameof(NativePostPersist), 0, CallFlags.States);
public static readonly InteropDescriptor System_Contract_NativePostPersist = Register("System.Contract.NativePostPersist", nameof(NativePostPersistAsync), 0, CallFlags.States);

/// <summary>
/// The implementation of System.Contract.Call.
Expand Down Expand Up @@ -145,9 +145,9 @@ internal protected UInt160 CreateMultisigAccount(int m, ECPoint[] pubKeys)

/// <summary>
/// The implementation of System.Contract.NativeOnPersist.
/// Calls to the <see cref="NativeContract.OnPersist"/> of all native contracts.
/// Calls to the <see cref="NativeContract.OnPersistAsync"/> of all native contracts.
/// </summary>
protected internal async void NativeOnPersist()
protected internal async void NativeOnPersistAsync()
{
try
{
Expand All @@ -156,7 +156,7 @@ protected internal async void NativeOnPersist()
foreach (NativeContract contract in NativeContract.Contracts)
{
if (contract.IsActive(ProtocolSettings, PersistingBlock.Index))
await contract.OnPersist(this);
await contract.OnPersistAsync(this);
}
}
catch (Exception ex)
Expand All @@ -167,9 +167,9 @@ protected internal async void NativeOnPersist()

/// <summary>
/// The implementation of System.Contract.NativePostPersist.
/// Calls to the <see cref="NativeContract.PostPersist"/> of all native contracts.
/// Calls to the <see cref="NativeContract.PostPersistAsync"/> of all native contracts.
/// </summary>
protected internal async void NativePostPersist()
protected internal async void NativePostPersistAsync()
{
try
{
Expand All @@ -178,7 +178,7 @@ protected internal async void NativePostPersist()
foreach (NativeContract contract in NativeContract.Contracts)
{
if (contract.IsActive(ProtocolSettings, PersistingBlock.Index))
await contract.PostPersist(this);
await contract.PostPersistAsync(this);
}
}
catch (Exception ex)
Expand Down
4 changes: 2 additions & 2 deletions src/Neo/SmartContract/ApplicationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ private ExecutionContext CallContractInternal(ContractState contract, ContractMe
return context_new;
}

internal ContractTask CallFromNativeContract(UInt160 callingScriptHash, UInt160 hash, string method, params StackItem[] args)
internal ContractTask CallFromNativeContractAsync(UInt160 callingScriptHash, UInt160 hash, string method, params StackItem[] args)
{
ExecutionContext context_new = CallContractInternal(hash, method, CallFlags.All, false, args);
ExecutionContextState state = context_new.GetState<ExecutionContextState>();
Expand All @@ -317,7 +317,7 @@ internal ContractTask CallFromNativeContract(UInt160 callingScriptHash, UInt160
return task;
}

internal ContractTask<T> CallFromNativeContract<T>(UInt160 callingScriptHash, UInt160 hash, string method, params StackItem[] args)
internal ContractTask<T> CallFromNativeContractAsync<T>(UInt160 callingScriptHash, UInt160 hash, string method, params StackItem[] args)
{
ExecutionContext context_new = CallContractInternal(hash, method, CallFlags.All, true, args);
ExecutionContextState state = context_new.GetState<ExecutionContextState>();
Expand Down
14 changes: 7 additions & 7 deletions src/Neo/SmartContract/Native/ContractManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private int GetNextAvailableId(DataCache snapshot)
return value;
}

internal override ContractTask Initialize(ApplicationEngine engine, Hardfork? hardfork)
internal override ContractTask InitializeAsync(ApplicationEngine engine, Hardfork? hardfork)
{
if (hardfork == ActiveIn)
{
Expand All @@ -58,15 +58,15 @@ internal override ContractTask Initialize(ApplicationEngine engine, Hardfork? ha
return ContractTask.CompletedTask;
}

private async ContractTask OnDeploy(ApplicationEngine engine, ContractState contract, StackItem data, bool update)
private async ContractTask OnDeployAsync(ApplicationEngine engine, ContractState contract, StackItem data, bool update)
{
ContractMethodDescriptor md = contract.Manifest.Abi.GetMethod("_deploy", 2);
if (md is not null)
await engine.CallFromNativeContract(Hash, contract.Hash, md.Name, data, update);
await engine.CallFromNativeContractAsync(Hash, contract.Hash, md.Name, data, update);
engine.SendNotification(Hash, update ? "Update" : "Deploy", new VM.Types.Array(engine.ReferenceCounter) { contract.Hash.ToArray() });
}

internal override async ContractTask OnPersist(ApplicationEngine engine)
internal override async ContractTask OnPersistAsync(ApplicationEngine engine)
{
foreach (NativeContract contract in Contracts)
{
Expand All @@ -92,7 +92,7 @@ internal override async ContractTask OnPersist(ApplicationEngine engine)
oldContract.Manifest = contractState.Manifest;
}

await contract.Initialize(engine, hf);
await contract.InitializeAsync(engine, hf);
// Emit native contract notification
engine.SendNotification(Hash, state is null ? "Deploy" : "Update", new VM.Types.Array(engine.ReferenceCounter) { contract.Hash.ToArray() });
}
Expand Down Expand Up @@ -232,7 +232,7 @@ private async ContractTask<ContractState> Deploy(ApplicationEngine engine, byte[
engine.Snapshot.Add(key, new StorageItem(contract));
engine.Snapshot.Add(CreateStorageKey(Prefix_ContractHash).AddBigEndian(contract.Id), new StorageItem(hash.ToArray()));

await OnDeploy(engine, contract, data, false);
await OnDeployAsync(engine, contract, data, false);

return contract;
}
Expand Down Expand Up @@ -275,7 +275,7 @@ private ContractTask Update(ApplicationEngine engine, byte[] nefFile, byte[] man
}
Helper.Check(new VM.Script(contract.Nef.Script, engine.IsHardforkEnabled(Hardfork.HF_Basilisk)), contract.Manifest.Abi);
contract.UpdateCounter++; // Increase update counter
return OnDeploy(engine, contract, data, true);
return OnDeployAsync(engine, contract, data, true);
}

[ContractMethod(CpuFee = 1 << 15, RequiredCallFlags = CallFlags.States | CallFlags.AllowNotify)]
Expand Down
10 changes: 5 additions & 5 deletions src/Neo/SmartContract/Native/FungibleToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ internal async ContractTask Mint(ApplicationEngine engine, UInt160 account, BigI
state.Balance += amount;
storage = engine.Snapshot.GetAndChange(CreateStorageKey(Prefix_TotalSupply), () => new StorageItem(BigInteger.Zero));
storage.Add(amount);
await PostTransfer(engine, null, account, amount, StackItem.Null, callOnPayment);
await PostTransferAsync(engine, null, account, amount, StackItem.Null, callOnPayment);
}

internal async ContractTask Burn(ApplicationEngine engine, UInt160 account, BigInteger amount)
Expand All @@ -98,7 +98,7 @@ internal async ContractTask Burn(ApplicationEngine engine, UInt160 account, BigI
state.Balance -= amount;
storage = engine.Snapshot.GetAndChange(CreateStorageKey(Prefix_TotalSupply));
storage.Add(-amount);
await PostTransfer(engine, account, null, amount, StackItem.Null, false);
await PostTransferAsync(engine, account, null, amount, StackItem.Null, false);
}

/// <summary>
Expand Down Expand Up @@ -169,15 +169,15 @@ private protected async ContractTask<bool> Transfer(ApplicationEngine engine, UI
state_to.Balance += amount;
}
}
await PostTransfer(engine, from, to, amount, data, true);
await PostTransferAsync(engine, from, to, amount, data, true);
return true;
}

internal virtual void OnBalanceChanging(ApplicationEngine engine, UInt160 account, TState state, BigInteger amount)
{
}

private protected virtual async ContractTask PostTransfer(ApplicationEngine engine, UInt160 from, UInt160 to, BigInteger amount, StackItem data, bool callOnPayment)
private protected virtual async ContractTask PostTransferAsync(ApplicationEngine engine, UInt160 from, UInt160 to, BigInteger amount, StackItem data, bool callOnPayment)
{
// Send notification

Expand All @@ -190,7 +190,7 @@ private protected virtual async ContractTask PostTransfer(ApplicationEngine engi

// Call onNEP17Payment method

await engine.CallFromNativeContract(Hash, to, "onNEP17Payment", from?.ToArray() ?? StackItem.Null, amount, data);
await engine.CallFromNativeContractAsync(Hash, to, "onNEP17Payment", from?.ToArray() ?? StackItem.Null, amount, data);
}
}
}
4 changes: 2 additions & 2 deletions src/Neo/SmartContract/Native/GasToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal GasToken()
{
}

internal override ContractTask Initialize(ApplicationEngine engine, Hardfork? hardfork)
internal override ContractTask InitializeAsync(ApplicationEngine engine, Hardfork? hardfork)
{
if (hardfork == ActiveIn)
{
Expand All @@ -36,7 +36,7 @@ internal override ContractTask Initialize(ApplicationEngine engine, Hardfork? ha
return ContractTask.CompletedTask;
}

internal override async ContractTask OnPersist(ApplicationEngine engine)
internal override async ContractTask OnPersistAsync(ApplicationEngine engine)
{
long totalNetworkFee = 0;
foreach (Transaction tx in engine.PersistingBlock.Transactions)
Expand Down
4 changes: 2 additions & 2 deletions src/Neo/SmartContract/Native/LedgerContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public sealed class LedgerContract : NativeContract

internal LedgerContract() : base() { }

internal override ContractTask OnPersist(ApplicationEngine engine)
internal override ContractTask OnPersistAsync(ApplicationEngine engine)
{
TransactionState[] transactions = engine.PersistingBlock.Transactions.Select(p => new TransactionState
{
Expand Down Expand Up @@ -65,7 +65,7 @@ internal override ContractTask OnPersist(ApplicationEngine engine)
return ContractTask.CompletedTask;
}

internal override ContractTask PostPersist(ApplicationEngine engine)
internal override ContractTask PostPersistAsync(ApplicationEngine engine)
{
HashIndexState state = engine.Snapshot.GetAndChange(CreateStorageKey(Prefix_CurrentBlock), () => new StorageItem(new HashIndexState())).GetInteroperable<HashIndexState>();
state.Hash = engine.PersistingBlock.Hash;
Expand Down
6 changes: 3 additions & 3 deletions src/Neo/SmartContract/Native/NativeContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,17 +398,17 @@ public static bool IsNative(UInt160 hash)
return contractsDictionary.ContainsKey(hash);
}

internal virtual ContractTask Initialize(ApplicationEngine engine, Hardfork? hardFork)
internal virtual ContractTask InitializeAsync(ApplicationEngine engine, Hardfork? hardFork)
{
return ContractTask.CompletedTask;
}

internal virtual ContractTask OnPersist(ApplicationEngine engine)
internal virtual ContractTask OnPersistAsync(ApplicationEngine engine)
{
return ContractTask.CompletedTask;
}

internal virtual ContractTask PostPersist(ApplicationEngine engine)
internal virtual ContractTask PostPersistAsync(ApplicationEngine engine)
{
return ContractTask.CompletedTask;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Neo/SmartContract/Native/NeoToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ internal override void OnBalanceChanging(ApplicationEngine engine, UInt160 accou
CheckCandidate(engine.Snapshot, state.VoteTo, candidate);
}

private protected override async ContractTask PostTransfer(ApplicationEngine engine, UInt160 from, UInt160 to, BigInteger amount, StackItem data, bool callOnPayment)
private protected override async ContractTask PostTransferAsync(ApplicationEngine engine, UInt160 from, UInt160 to, BigInteger amount, StackItem data, bool callOnPayment)
{
await base.PostTransfer(engine, from, to, amount, data, callOnPayment);
await base.PostTransferAsync(engine, from, to, amount, data, callOnPayment);
var list = engine.CurrentContext.GetState<List<GasDistribution>>();
foreach (var distribution in list)
await GAS.Mint(engine, distribution.Account, distribution.Amount, callOnPayment);
Expand Down Expand Up @@ -176,7 +176,7 @@ private void CheckCandidate(DataCache snapshot, ECPoint pubkey, CandidateState c
/// <returns><see langword="true"/> if the votes should be recounted; otherwise, <see langword="false"/>.</returns>
public static bool ShouldRefreshCommittee(uint height, int committeeMembersCount) => height % committeeMembersCount == 0;

internal override ContractTask Initialize(ApplicationEngine engine, Hardfork? hardfork)
internal override ContractTask InitializeAsync(ApplicationEngine engine, Hardfork? hardfork)
{
if (hardfork == ActiveIn)
{
Expand All @@ -190,7 +190,7 @@ internal override ContractTask Initialize(ApplicationEngine engine, Hardfork? ha
return ContractTask.CompletedTask;
}

internal override ContractTask OnPersist(ApplicationEngine engine)
internal override ContractTask OnPersistAsync(ApplicationEngine engine)
{
// Set next committee
if (ShouldRefreshCommittee(engine.PersistingBlock.Index, engine.ProtocolSettings.CommitteeMembersCount))
Expand All @@ -216,7 +216,7 @@ internal override ContractTask OnPersist(ApplicationEngine engine)
return ContractTask.CompletedTask;
}

internal override async ContractTask PostPersist(ApplicationEngine engine)
internal override async ContractTask PostPersistAsync(ApplicationEngine engine)
{
// Distribute GAS for committee

Expand Down
6 changes: 3 additions & 3 deletions src/Neo/SmartContract/Native/OracleContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private ContractTask Finish(ApplicationEngine engine)
if (request == null) throw new ArgumentException("Oracle request was not found");
engine.SendNotification(Hash, "OracleResponse", new VM.Types.Array(engine.ReferenceCounter) { response.Id, request.OriginalTxid.ToArray() });
StackItem userData = BinarySerializer.Deserialize(request.UserData, engine.Limits, engine.ReferenceCounter);
return engine.CallFromNativeContract(Hash, request.CallbackContract, request.CallbackMethod, request.Url, userData, (int)response.Code, response.Result);
return engine.CallFromNativeContractAsync(Hash, request.CallbackContract, request.CallbackMethod, request.Url, userData, (int)response.Code, response.Result);
}

private UInt256 GetOriginalTxid(ApplicationEngine engine)
Expand Down Expand Up @@ -134,7 +134,7 @@ private static byte[] GetUrlHash(string url)
return Crypto.Hash160(Utility.StrictUTF8.GetBytes(url));
}

internal override ContractTask Initialize(ApplicationEngine engine, Hardfork? hardfork)
internal override ContractTask InitializeAsync(ApplicationEngine engine, Hardfork? hardfork)
{
if (hardfork == ActiveIn)
{
Expand All @@ -144,7 +144,7 @@ internal override ContractTask Initialize(ApplicationEngine engine, Hardfork? ha
return ContractTask.CompletedTask;
}

internal override async ContractTask PostPersist(ApplicationEngine engine)
internal override async ContractTask PostPersistAsync(ApplicationEngine engine)
{
(UInt160 Account, BigInteger GAS)[] nodes = null;
foreach (Transaction tx in engine.PersistingBlock.Transactions)
Expand Down
2 changes: 1 addition & 1 deletion src/Neo/SmartContract/Native/PolicyContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public sealed class PolicyContract : NativeContract

internal PolicyContract() : base() { }

internal override ContractTask Initialize(ApplicationEngine engine, Hardfork? hardfork)
internal override ContractTask InitializeAsync(ApplicationEngine engine, Hardfork? hardfork)
{
if (hardfork == ActiveIn)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void TestSetup()
_snapshot = TestBlockchain.GetTestSnapshot();

ApplicationEngine engine = ApplicationEngine.Create(TriggerType.OnPersist, null, _snapshot, new Block { Header = new Header() }, settings: TestBlockchain.TheNeoSystem.Settings, gas: 0);
NativeContract.ContractManagement.OnPersist(engine);
NativeContract.ContractManagement.OnPersistAsync(engine);
}

[TestMethod]
Expand Down

0 comments on commit 429a081

Please sign in to comment.