/// <summary> /// Create an unsigned Transaction object with given parameters. /// </summary> /// <param name="script">Transaction Script</param> /// <param name="attributes">Transaction Attributes</param> /// <returns></returns> public TransactionManager MakeTransaction(byte[] script, TransactionAttribute[] attributes = null) { var random = new Random(); uint height = rpcClient.GetBlockCount() - 1; Tx = new Transaction { Version = 0, Nonce = (uint)random.Next(), Script = script, Sender = sender, ValidUntilBlock = height + Transaction.MaxValidUntilBlockIncrement, Attributes = attributes ?? Array.Empty <TransactionAttribute>(), Witnesses = Array.Empty <Witness>() }; // Add witness hashes parameter to pass CheckWitness UInt160[] hashes = Tx.GetScriptHashesForVerifying(null); RpcInvokeResult result = rpcClient.InvokeScript(script, hashes); Tx.SystemFee = long.Parse(result.GasConsumed); context = new ContractParametersContext(Tx); signStore = new List <SignItem>(); return(this); }
/// <summary> /// Create an unsigned Transaction object with given parameters. /// </summary> /// <param name="script">Transaction Script</param> /// <param name="attributes">Transaction Attributes</param> /// <param name="cosigners">Transaction Cosigners</param> /// <param name="networkFee">Transaction NetworkFee, will set to estimate value(with only basic signatures) when networkFee is 0</param> /// <returns></returns> public TransactionManager MakeTransaction(byte[] script, TransactionAttribute[] attributes = null, Cosigner[] cosigners = null, long networkFee = 0) { var random = new Random(); uint height = rpcClient.GetBlockCount() - 1; Tx = new Transaction { Version = 0, Nonce = (uint)random.Next(), Script = script, Sender = sender, ValidUntilBlock = height + Transaction.MaxValidUntilBlockIncrement, Attributes = attributes ?? new TransactionAttribute[0], Cosigners = cosigners ?? new Cosigner[0], Witnesses = new Witness[0] }; // Add witness hashes parameter to pass CheckWitness UInt160[] hashes = Tx.GetScriptHashesForVerifying(null); RpcInvokeResult result = rpcClient.InvokeScript(script, hashes); Tx.SystemFee = Math.Max(long.Parse(result.GasConsumed) - ApplicationEngine.GasFree, 0); if (Tx.SystemFee > 0) { long d = (long)NativeContract.GAS.Factor; long remainder = Tx.SystemFee % d; if (remainder > 0) { Tx.SystemFee += d - remainder; } else if (remainder < 0) { Tx.SystemFee -= remainder; } } context = new ContractParametersContext(Tx); // set networkfee to estimate value when networkFee is 0 Tx.NetworkFee = networkFee == 0 ? EstimateNetworkFee() : networkFee; var gasBalance = nep5API.BalanceOf(NativeContract.GAS.Hash, sender); if (gasBalance >= Tx.SystemFee + Tx.NetworkFee) { return(this); } throw new InvalidOperationException($"Insufficient GAS in address: {sender.ToAddress()}"); }
/// <summary> /// Create an unsigned Transaction object with given parameters. /// </summary> /// <param name="script">Transaction Script</param> /// <param name="attributes">Transaction Attributes</param> /// <param name="cosigners">Transaction Cosigners</param> /// <returns></returns> public TransactionManager MakeTransaction(byte[] script, TransactionAttribute[] attributes = null, Cosigner[] cosigners = null) { var random = new Random(); uint height = rpcClient.GetBlockCount() - 1; Tx = new Transaction { Version = 0, Nonce = (uint)random.Next(), Script = script, Sender = sender, ValidUntilBlock = height + Transaction.MaxValidUntilBlockIncrement, Attributes = attributes ?? Array.Empty <TransactionAttribute>(), Cosigners = cosigners ?? Array.Empty <Cosigner>(), Witnesses = Array.Empty <Witness>() }; // Add witness hashes parameter to pass CheckWitness UInt160[] hashes = Tx.GetScriptHashesForVerifying(null); RpcInvokeResult result = rpcClient.InvokeScript(script, hashes); Tx.SystemFee = Math.Max(long.Parse(result.GasConsumed) - ApplicationEngine.GasFree, 0); if (Tx.SystemFee > 0) { long d = (long)NativeContract.GAS.Factor; long remainder = Tx.SystemFee % d; if (remainder > 0) { Tx.SystemFee += d - remainder; } else if (remainder < 0) { Tx.SystemFee -= remainder; } } context = new ContractParametersContext(Tx); signStore = new List <SignItem>(); return(this); }
/// <summary> /// Create an unsigned Transaction object with given parameters. /// </summary> /// <param name="script">Transaction Script</param> /// <param name="attributes">Transaction Attributes</param> /// <returns></returns> public TransactionManager MakeTransaction(byte[] script, Signer[] signers = null, TransactionAttribute[] attributes = null) { var random = new Random(); uint height = rpcClient.GetBlockCount() - 1; Tx = new Transaction { Version = 0, Nonce = (uint)random.Next(), Script = script, Signers = signers, ValidUntilBlock = height + Transaction.MaxValidUntilBlockIncrement, Attributes = attributes ?? Array.Empty <TransactionAttribute>(), }; RpcInvokeResult result = rpcClient.InvokeScript(script, signers); Tx.SystemFee = long.Parse(result.GasConsumed); context = new ContractParametersContext(Tx); signStore = new List <SignItem>(); return(this); }
/// <summary> /// Use RPC method to test invoke operation. /// </summary> /// <param name="scriptHash">contract script hash</param> /// <param name="operation">contract operation</param> /// <param name="args">operation arguments</param> /// <returns></returns> public RpcInvokeResult TestInvoke(UInt160 scriptHash, string operation, params object[] args) { byte[] script = scriptHash.MakeScript(operation, args); return(rpcClient.InvokeScript(script)); }