public Task <UInt256> ExecuteAsync(ExpressWalletAccount account, Neo.VM.Script script, decimal additionalGas = 0) { if (disposedValue) { throw new ObjectDisposedException(nameof(OfflineNode)); } var devAccount = DevWalletAccount.FromExpressWalletAccount(account); var devWallet = new DevWallet(string.Empty, devAccount); var signer = new Signer() { Account = devAccount.ScriptHash, Scopes = WitnessScope.CalledByEntry }; var tx = devWallet.MakeTransaction(script, devAccount.ScriptHash, new[] { signer }); if (additionalGas > 0.0m) { tx.SystemFee += (long)additionalGas.ToBigInteger(NativeContract.GAS.Decimals); } var context = new ContractParametersContext(tx); if (devAccount.IsMultiSigContract()) { var wallets = chain.GetMultiSigWallets(account); foreach (var wallet in wallets) { if (context.Completed) { break; } wallet.Sign(context); } } else { devWallet.Sign(context); } if (!context.Completed) { throw new Exception(); } tx.Witnesses = context.GetWitnesses(); return(SubmitTransactionAsync(tx)); }
RpcInvokeResult Invoke(Neo.VM.Script script, Signer?signer = null) { var tx = TestApplicationEngine.CreateTestTransaction(signer); using var engine = script.Invoke(neoSystem.Settings, neoSystem.StoreView, tx); return(new RpcInvokeResult() { State = engine.State, Exception = engine.FaultException?.GetBaseException().Message ?? string.Empty, GasConsumed = engine.GasConsumed, Stack = engine.ResultStack.ToArray(), Script = string.Empty, Tx = string.Empty }); }
public Task <RpcInvokeResult> InvokeAsync(Neo.VM.Script script) { if (disposedValue) { throw new ObjectDisposedException(nameof(OfflineNode)); } using ApplicationEngine engine = ApplicationEngine.Run(script, container: null, gas: 20000000L); var result = new RpcInvokeResult() { State = engine.State, Exception = engine.FaultException?.GetBaseException().Message ?? string.Empty, GasConsumed = engine.GasConsumed, Stack = engine.ResultStack.ToArray(), Script = string.Empty, Tx = string.Empty }; return(Task.FromResult(result)); }
public async Task <UInt256> ExecuteAsync(Wallet wallet, UInt160 accountHash, WitnessScope witnessScope, Neo.VM.Script script, decimal additionalGas = 0) { if (disposedValue) { throw new ObjectDisposedException(nameof(OfflineNode)); } var signer = new Signer() { Account = accountHash, Scopes = witnessScope }; var(balance, _) = await this.GetBalanceAsync(accountHash, "GAS"); var tx = wallet.MakeTransaction(neoSystem.StoreView, script, accountHash, new[] { signer }, maxGas: (long)balance.Amount); if (additionalGas > 0.0m) { tx.SystemFee += (long)additionalGas.ToBigInteger(NativeContract.GAS.Decimals); } var context = new ContractParametersContext(neoSystem.StoreView, tx, ProtocolSettings.Network); var account = wallet.GetAccount(accountHash) ?? throw new Exception(); if (account.IsMultiSigContract()) { var multiSigWallets = chain.GetMultiSigWallets(neoSystem.Settings, accountHash); for (int i = 0; i < multiSigWallets.Count; i++) { multiSigWallets[i].Sign(context); if (context.Completed) { break; } } } else { wallet.Sign(context); } if (!context.Completed) { throw new Exception(); } tx.Witnesses = context.GetWitnesses(); var blockHash = await SubmitTransactionAsync(tx).ConfigureAwait(false); return(tx.Hash); }
public Task <RpcInvokeResult> InvokeAsync(Neo.VM.Script script, Signer?signer = null) => MakeAsync(() => Invoke(script, signer));