Exemplo n.º 1
0
        /// <summary>
        /// Utility to call functions on blockchain signing it by given account
        /// </summary>
        /// <returns>Receipt of called transaction</returns>
        public static async Task <TransactionReceipt> EvaluateOnBC(Web3 web, Profile profile, Function function, params object[] functionInput)
        {
            Debug.Assert(profile != null);

            var gasPrice = await web.Eth.GasPrice.SendRequestAsync();

            HexBigInteger gas = await function.EstimateGasAsync(profile.ID, gasPrice, new HexBigInteger(0), functionInput);

            var        nonceService = new InMemoryNonceService(profile.ID, web.Client);
            BigInteger nonce        = await nonceService.GetNextNonceAsync();

            string data         = function.GetData(functionInput);
            var    transaction  = new Nethereum.Signer.Transaction(function.ContractAddress, BigInteger.Zero, nonce, gasPrice, gas.Value, data);
            var    rlpEncodedTx = transaction.GetRLPEncodedRaw();

            string signature = await profile.SignTransaction(rlpEncodedTx);

            transaction.SetSignature(Nethereum.Signer.EthECDSASignatureFactory.ExtractECDSASignature(signature));

            var    signedTransaction = transaction.GetRLPEncoded().ToHex(true);
            string txId = await web.Eth.Transactions.SendRawTransaction.SendRequestAsync(signedTransaction).ConfigureAwait(false);

            TransactionReceipt receipt = await web.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(txId);

            while (receipt == null)
            {
                Thread.Sleep(1000);
                receipt = await web.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(txId);
            }
            return(receipt);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Utility to send ETH on blockchain signing it by given account
        /// </summary>
        /// <returns>Receipt of called transaction</returns>
        public static async Task <TransactionReceipt> EvaluateOnBC(Web3 web, Profile profile, string to, HexBigInteger amount)
        {
            Debug.Assert(profile != null);

            var        nonceService = new InMemoryNonceService(profile.ID, web.Client);
            BigInteger nonce        = await nonceService.GetNextNonceAsync();

            var    transaction  = new Nethereum.Signer.Transaction(to, amount, nonce);
            var    rlpEncodedTx = transaction.GetRLPEncodedRaw();
            string signature    = await profile.SignTransaction(rlpEncodedTx);

            transaction.SetSignature(Nethereum.Signer.EthECDSASignatureFactory.ExtractECDSASignature(signature));

            var    signedTransaction = transaction.GetRLPEncoded().ToHex(true);
            string txId = await web.Eth.Transactions.SendRawTransaction.SendRequestAsync(signedTransaction);

            TransactionReceipt receipt = await web.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(txId);

            while (receipt == null)
            {
                Thread.Sleep(1000);
                receipt = await web.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(txId);
            }
            return(receipt);
        }
Exemplo n.º 3
0
        private async Task <string> SignTransaction(Profile profile, Nethereum.Signer.Transaction transaction)
        {
            string signature = await profile.SignTransaction(transaction.GetRLPEncodedRaw());

            transaction.SetSignature(Nethereum.Signer.EthECDSASignatureFactory.ExtractECDSASignature(signature));
            return(transaction.GetRLPEncoded().ToHex(true));
        }