Ejemplo n.º 1
0
        /// <summary>
        /// Coroutine which queries some data from an ethereum smart contract.
        /// </summary>
        /// <typeparam name="TFunc"> The <see cref="FunctionMessage"/> of the smart contract to execute which will return us some data. </typeparam>
        /// <typeparam name="TOut"> The <see cref="IFunctionOutputDTO"/> which represents the data which was returned from the <see cref="ContractFunction"/>. </typeparam>
        /// <param name="function"> The contract function to query data from. </param>
        /// <param name="promise"> Promise of eventually returning the data from the contract query. </param>
        /// <param name="contractAddress"> The contract address to execute the <see cref="FunctionMessage"/> on. </param>
        /// <param name="senderAddress"> The address of the sender requesting this data. </param>
        private static IEnumerator _QueryContractCoroutine <TFunc, TOut>(
            TFunc function,
            EthCallPromise <TOut> promise,
            string contractAddress,
            string senderAddress) where TFunc : FunctionMessage, new() where TOut : IFunctionOutputDTO, new()
        {
            function.SetDefaultFromAddressIfNotSet(senderAddress);

            var queryRequest = new QueryUnityRequest <TFunc, TOut>(NetworkProvider.GetNetworkChainUrl(), senderAddress);

            yield return(queryRequest.Query(function, contractAddress));

            promise.Build(queryRequest, () => queryRequest.Result);
        }
Ejemplo n.º 2
0
        /// <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());
        }
Ejemplo n.º 3
0
        /// <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);
        }