/// <summary> /// Coroutine which sends a message to an ethereum smart contract. /// </summary> /// <param name="message"> The message representing the transaction. </param> /// <param name="transactionInput"> The <see cref="TransactionInput"/> of the message to send. </param> /// <param name="signedUnityRequest"> The <see cref="TransactionSignedUnityRequest"/> to use to send the message. </param> private static IEnumerator _SendContractMessageCoroutine( string message, TransactionInput transactionInput, TransactionSignedUnityRequest signedUnityRequest) { var promise = new EthTransactionPromise(EthereumPendingTransactionManager, transactionInput.From, message); yield return(signedUnityRequest.SignAndSendTransaction(transactionInput)); promise.Build(signedUnityRequest, () => signedUnityRequest.Result, () => EthereumNetworkManager.CurrentNetwork.NetworkUrl); }
/// <summary> /// Sends ether from one address to another. /// </summary> /// <param name="signedUnityRequest"> The signed request to send the ether with. </param> /// <param name="walletAddress"> The address of the wallet sending the ether. </param> /// <param name="gasLimit"> The gas limit of the ether send transaction. </param> /// <param name="gasPrice"> The gas price of the ether send transaction. </param> /// <param name="addressTo"> The address to send the ether to. </param> /// <param name="amount"> The amount to send in ether. </param> /// <returns> The time waited for the request to be broadcast to the network. </returns> private static IEnumerator _SendEtherCoroutine( TransactionSignedUnityRequest signedUnityRequest, HexBigInteger gasLimit, HexBigInteger gasPrice, string walletAddress, string addressTo, dynamic amount) { var promise = new EthTransactionPromise(EthereumPendingTransactionManager, walletAddress, "Sending ETH"); var transactionInput = new TransactionInput("", addressTo, walletAddress, gasLimit, gasPrice, new HexBigInteger(SolidityUtils.ConvertToUInt(amount, 18))); yield return(signedUnityRequest.SignAndSendTransaction(transactionInput)); promise.Build(signedUnityRequest, () => signedUnityRequest.Result, () => EthereumNetworkManager.CurrentNetwork.NetworkUrl); }
/// <summary> /// Sends ether from one address to another. /// </summary> /// <param name="promise"> Promise of the transaction result of sending ether. </param> /// <param name="walletAddress"> The address of the wallet sending the ether. </param> /// <param name="gasLimit"> The gas limit of the ether send transaction. </param> /// <param name="gasPrice"> The gas price of the ether send transaction. </param> /// <param name="privateKey"> The private key of the address sending the transaction. </param> /// <param name="addressTo"> The address the ether is being sent to. </param> /// <param name="amount"> The amount to send in ether. </param> /// <returns> The time waited for the request to be broadcast to the network. </returns> private static IEnumerator _SendEtherCoroutine( EthTransactionPromise promise, BigInteger gasLimit, BigInteger gasPrice, string privateKey, string addressTo, dynamic amount) { EthECKey ethKey = new EthECKey(privateKey); TransactionSignedUnityRequest unityRequest = new TransactionSignedUnityRequest(NetworkProvider.GetNetworkChainUrl(), privateKey, ethKey.GetPublicAddress()); TransactionInput transactionInput = new TransactionInput("", addressTo, ethKey.GetPublicAddress(), new HexBigInteger(gasLimit), new HexBigInteger(gasPrice), new HexBigInteger(SolidityUtils.ConvertToUInt(amount, 18))); yield return(unityRequest.SignAndSendTransaction(transactionInput)); promise.Build(unityRequest, () => unityRequest.Result, () => NetworkProvider.GetNetworkChainUrl()); }
/// <summary> /// Coroutine which sends a message to an ethereum smart contract. /// </summary> /// <typeparam name="TFunc"> The <see cref="FunctionMessage"/> to execute on the blockchain given the contract address. </typeparam> /// <param name="function"> The function to execute. </param> /// <param name="promise"> Promise of the transaction result of sending the contract message. </param> /// <param name="contractAddress"> The contract address to execute the <see cref="FunctionMessage"/> on. </param> /// <param name="privateKey"> The private key of the address sending the transaction. </param> /// <param name="gasPrice"> The <see cref="BigInteger"/> gas price to use with the transaction. </param> /// <param name="gasLimit"> The <see cref="BigInteger"/> gas limit to use with the transaction. </param> private static IEnumerator _SendContractMessageCoroutine <TFunc>( TFunc function, EthTransactionPromise promise, string contractAddress, string privateKey, BigInteger gasPrice, BigInteger gasLimit) where TFunc : FunctionMessage { EthECKey ethKey = new EthECKey(privateKey); function.SetDefaultFromAddressIfNotSet(ethKey.GetPublicAddress()); function.Gas = gasLimit; function.GasPrice = gasPrice; TransactionSignedUnityRequest unityRequest = new TransactionSignedUnityRequest(NetworkProvider.GetNetworkChainUrl(), privateKey, ethKey.GetPublicAddress()); yield return(unityRequest.SignAndSendTransaction(function.CreateTransactionInput(contractAddress))); promise.Build(unityRequest, () => unityRequest.Result, NetworkProvider.GetNetworkChainUrl); }