Esempio n. 1
0
        public async Task <double> EstimateGasContractCall(byte[] scriptHash, string operation,
                                                           object[] args, string attachSymbol = null, IEnumerable <TransactionOutput> attachTargets = null)
        {
            var bytes = Utils.GenerateScript(scriptHash, operation, args);

            if (string.IsNullOrEmpty(attachSymbol))
            {
                attachSymbol = "GAS";
            }

            if (attachTargets == null)
            {
                attachTargets = new List <TransactionOutput>();
            }

            var(inputs, outputs) = await GenerateInputsOutputs(_accountKey, attachSymbol, attachTargets);

            if (inputs.Count == 0)
            {
                throw new WalletException($"Not enough inputs for transaction");
            }

            var tx = new SignedTransaction
            {
                Type    = TransactionType.InvocationTransaction,
                Version = 0,
                Script  = bytes,
                Gas     = 0,
                Inputs  = inputs.ToArray(),
                Outputs = outputs.ToArray()
            };

            var serializedScriptHash = SignTransaction(_accountKey, tx);

            return(await EstimateGasAsync(serializedScriptHash.ToHexString()));
        }