/// <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 a message to an ethereum smart contract with the intent to change a part of the contract on the blockchain. /// </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="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> /// <returns> Promise of the transaction result of sending the contract message. </returns> public static EthTransactionPromise SendContractMessage <TFunc>( TFunc function, string contractAddress, string privateKey, BigInteger gasPrice, BigInteger gasLimit) where TFunc : FunctionMessage { var promise = new EthTransactionPromise(); _SendContractMessageCoroutine(function, promise, contractAddress, privateKey, gasPrice, gasLimit).StartCoroutine(); return(promise); }
/// <summary> /// Sends ether from this wallet to a given address. /// </summary> /// <param name="privateKey"> The private key of the address sending the transaction. </param> /// <param name="addressTo"> The address to send the ether to. </param> /// <param name="amount"> The amount of ether to send. </param> /// <param name="gasPrice"> The gas price of the ether send transaction. </param> /// <param name="gasLimit"> The gas limit of the ether send transaction. </param> /// <returns> The promise which will contain the result of a successful/unsuccessful transaction. </returns> public static EthTransactionPromise SendEther( string privateKey, string addressTo, decimal amount, BigInteger gasPrice, BigInteger gasLimit) { var promise = new EthTransactionPromise(); _SendEtherCoroutine(promise, gasLimit, gasPrice, privateKey, addressTo, amount).StartCoroutine(); return(promise); }
/// <summary> /// Sends ether from this wallet to a given address. /// </summary> /// <param name="privateKey"> The private key of the address sending the transaction. </param> /// <param name="addressTo"> The address to send the ether to. </param> /// <param name="amount"> The amount of ether to send. </param> /// <param name="gasPrice"> The gas price of the ether send transaction. </param> /// <returns> The promise which will contain the result of a successful/unsuccessful transaction. </returns> public static EthTransactionPromise SendEther( string privateKey, string addressTo, decimal amount, BigInteger gasPrice) { var promise = new EthTransactionPromise(); GasUtils.EstimateEthGasLimit(addressTo, SolidityUtils.ConvertToUInt(amount, 18)) .OnSuccess(gasLimit => _SendEtherCoroutine(promise, gasLimit, gasPrice, privateKey, addressTo, amount).StartCoroutine()); return(promise); }
/// <summary> /// Starts a new pending transaction. /// </summary> /// <param name="ethTransactionPromise"> The transaction promise returning the result of the transaction. </param> /// <param name="txHash"> The transaction hash of the transaction. </param> /// <param name="addressFrom"> The address the transaction was sent from. </param> /// <param name="message"> The message representing the transaction. </param> public void StartNewPendingTransaction(EthTransactionPromise ethTransactionPromise, string txHash, string addressFrom, string message) { addressFrom = addressFrom.ToLower(); txHash = txHash.ToLower(); var pendingTransaction = new PendingTransaction(addressFrom, txHash, message); transactionsByAddress.AddOrReplace(addressFrom, pendingTransaction); transactionsByHash.AddOrReplace(txHash, pendingTransaction); OnNewTransactionPending?.Invoke(txHash, message); ethTransactionPromise.OnSuccess(_ => PendingTransactionSuccessful(txHash)).OnError(_ => PendingTransactionUnsuccessful(txHash)); }
/// <summary> /// Sends a message to an ethereum smart contract with the intent to change a part of the contract on the blockchain. /// </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="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> /// <returns> Promise of the transaction result of sending the contract message. </returns> public static EthTransactionPromise SendContractMessage <TFunc>( TFunc function, string contractAddress, string privateKey, BigInteger gasPrice) where TFunc : FunctionMessage { EthECKey ethKey = new EthECKey(privateKey); var promise = new EthTransactionPromise(); GasUtils.EstimateContractGasLimit(function, contractAddress, ethKey.GetPublicAddress()) .OnSuccess(gasLimit => _SendContractMessageCoroutine(function, promise, contractAddress, privateKey, gasPrice, gasLimit).StartCoroutine()); return(promise); }
/// <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); }