From 429a081753e46d995829c5182a3f73bc55a63741 Mon Sep 17 00:00:00 2001 From: Shargon Date: Thu, 2 May 2024 00:19:58 -0700 Subject: [PATCH] Add `Async` to async method's name (#3206) * Add Async * Add more --- .../SmartContract/ApplicationEngine.Contract.cs | 16 ++++++++-------- src/Neo/SmartContract/ApplicationEngine.cs | 4 ++-- .../SmartContract/Native/ContractManagement.cs | 14 +++++++------- src/Neo/SmartContract/Native/FungibleToken.cs | 10 +++++----- src/Neo/SmartContract/Native/GasToken.cs | 4 ++-- src/Neo/SmartContract/Native/LedgerContract.cs | 4 ++-- src/Neo/SmartContract/Native/NativeContract.cs | 6 +++--- src/Neo/SmartContract/Native/NeoToken.cs | 10 +++++----- src/Neo/SmartContract/Native/OracleContract.cs | 6 +++--- src/Neo/SmartContract/Native/PolicyContract.cs | 2 +- .../SmartContract/Native/UT_PolicyContract.cs | 2 +- 11 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/Neo/SmartContract/ApplicationEngine.Contract.cs b/src/Neo/SmartContract/ApplicationEngine.Contract.cs index 1677396f1c..6f4b257016 100644 --- a/src/Neo/SmartContract/ApplicationEngine.Contract.cs +++ b/src/Neo/SmartContract/ApplicationEngine.Contract.cs @@ -54,13 +54,13 @@ partial class ApplicationEngine /// The of System.Contract.NativeOnPersist. /// /// Note: It is for internal use only. Do not use it directly in smart contracts. - 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); /// /// The of System.Contract.NativePostPersist. /// /// Note: It is for internal use only. Do not use it directly in smart contracts. - 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); /// /// The implementation of System.Contract.Call. @@ -145,9 +145,9 @@ internal protected UInt160 CreateMultisigAccount(int m, ECPoint[] pubKeys) /// /// The implementation of System.Contract.NativeOnPersist. - /// Calls to the of all native contracts. + /// Calls to the of all native contracts. /// - protected internal async void NativeOnPersist() + protected internal async void NativeOnPersistAsync() { try { @@ -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) @@ -167,9 +167,9 @@ protected internal async void NativeOnPersist() /// /// The implementation of System.Contract.NativePostPersist. - /// Calls to the of all native contracts. + /// Calls to the of all native contracts. /// - protected internal async void NativePostPersist() + protected internal async void NativePostPersistAsync() { try { @@ -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) diff --git a/src/Neo/SmartContract/ApplicationEngine.cs b/src/Neo/SmartContract/ApplicationEngine.cs index 2b78f62fe4..f2c63fe3b3 100644 --- a/src/Neo/SmartContract/ApplicationEngine.cs +++ b/src/Neo/SmartContract/ApplicationEngine.cs @@ -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(); @@ -317,7 +317,7 @@ internal ContractTask CallFromNativeContract(UInt160 callingScriptHash, UInt160 return task; } - 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, true, args); ExecutionContextState state = context_new.GetState(); diff --git a/src/Neo/SmartContract/Native/ContractManagement.cs b/src/Neo/SmartContract/Native/ContractManagement.cs index 28642a2db1..e326421f91 100644 --- a/src/Neo/SmartContract/Native/ContractManagement.cs +++ b/src/Neo/SmartContract/Native/ContractManagement.cs @@ -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) { @@ -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) { @@ -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() }); } @@ -232,7 +232,7 @@ private async ContractTask 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; } @@ -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)] diff --git a/src/Neo/SmartContract/Native/FungibleToken.cs b/src/Neo/SmartContract/Native/FungibleToken.cs index 6499c60c19..10e406dd07 100644 --- a/src/Neo/SmartContract/Native/FungibleToken.cs +++ b/src/Neo/SmartContract/Native/FungibleToken.cs @@ -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) @@ -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); } /// @@ -169,7 +169,7 @@ private protected async ContractTask 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; } @@ -177,7 +177,7 @@ internal virtual void OnBalanceChanging(ApplicationEngine engine, UInt160 accoun { } - 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 @@ -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); } } } diff --git a/src/Neo/SmartContract/Native/GasToken.cs b/src/Neo/SmartContract/Native/GasToken.cs index ce2f77ad2c..b8a185b6f1 100644 --- a/src/Neo/SmartContract/Native/GasToken.cs +++ b/src/Neo/SmartContract/Native/GasToken.cs @@ -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) { @@ -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) diff --git a/src/Neo/SmartContract/Native/LedgerContract.cs b/src/Neo/SmartContract/Native/LedgerContract.cs index d72f07c022..ea757ba348 100644 --- a/src/Neo/SmartContract/Native/LedgerContract.cs +++ b/src/Neo/SmartContract/Native/LedgerContract.cs @@ -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 { @@ -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(); state.Hash = engine.PersistingBlock.Hash; diff --git a/src/Neo/SmartContract/Native/NativeContract.cs b/src/Neo/SmartContract/Native/NativeContract.cs index 2003962b87..2b00fddfe2 100644 --- a/src/Neo/SmartContract/Native/NativeContract.cs +++ b/src/Neo/SmartContract/Native/NativeContract.cs @@ -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; } diff --git a/src/Neo/SmartContract/Native/NeoToken.cs b/src/Neo/SmartContract/Native/NeoToken.cs index c28a548d0e..82ee1b9fcb 100644 --- a/src/Neo/SmartContract/Native/NeoToken.cs +++ b/src/Neo/SmartContract/Native/NeoToken.cs @@ -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>(); foreach (var distribution in list) await GAS.Mint(engine, distribution.Account, distribution.Amount, callOnPayment); @@ -176,7 +176,7 @@ private void CheckCandidate(DataCache snapshot, ECPoint pubkey, CandidateState c /// if the votes should be recounted; otherwise, . 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) { @@ -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)) @@ -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 diff --git a/src/Neo/SmartContract/Native/OracleContract.cs b/src/Neo/SmartContract/Native/OracleContract.cs index d8415fca21..b391518733 100644 --- a/src/Neo/SmartContract/Native/OracleContract.cs +++ b/src/Neo/SmartContract/Native/OracleContract.cs @@ -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) @@ -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) { @@ -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) diff --git a/src/Neo/SmartContract/Native/PolicyContract.cs b/src/Neo/SmartContract/Native/PolicyContract.cs index 5b00af92ad..7b921d191f 100644 --- a/src/Neo/SmartContract/Native/PolicyContract.cs +++ b/src/Neo/SmartContract/Native/PolicyContract.cs @@ -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) { diff --git a/tests/Neo.UnitTests/SmartContract/Native/UT_PolicyContract.cs b/tests/Neo.UnitTests/SmartContract/Native/UT_PolicyContract.cs index 32da3b1602..703253364c 100644 --- a/tests/Neo.UnitTests/SmartContract/Native/UT_PolicyContract.cs +++ b/tests/Neo.UnitTests/SmartContract/Native/UT_PolicyContract.cs @@ -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]