/// <summary> /// Estimates the gas limit of a <see cref="ContractFunction"/>. /// </summary> /// <typeparam name="TFunc"> The <see cref="ContractFunction"/> to estimate the gas limit for. </typeparam> /// <param name="contractAddress"> The address of the contract function to estimate. </param> /// <param name="callerAddress"> The address of the sender. </param> /// <param name="input"> The input parameters of the function. </param> public static EthCallPromise <BigInteger> EstimateContractGasLimit <TFunc>( string contractAddress, string callerAddress, params object[] input) where TFunc : ContractFunction { var promise = new EthCallPromise <BigInteger>(); _EstimateGasLimitCoroutine(promise, ContractFunction.CreateFunction <TFunc>(callerAddress, input).CreateTransactionInput(contractAddress), true).StartCoroutine(); return(promise); }
/// <summary> /// Coroutine which queries some data from an ethereum smart contract. /// </summary> /// <typeparam name="TFunc"> The <see cref="ContractFunction"/> 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="promise"> Promise of eventually returning the data from the contract query. </param> /// <param name="contractAddress"> The contract address to execute the <see cref="ContractFunction"/> on. </param> /// <param name="senderAddress"> The address of the sender requesting this data. </param> /// <param name="functionInput"> The input parameters of the <see cref="ContractFunction"/>. </param> private static IEnumerator _QueryContractCoroutine <TFunc, TOut>( EthCallPromise <TOut> promise, string contractAddress, string senderAddress, params object[] functionInput) where TFunc : ContractFunction where TOut : IFunctionOutputDTO, new() { var queryRequest = new QueryUnityRequest <TFunc, TOut>(EthereumNetworkManager.CurrentNetwork.NetworkUrl, senderAddress); yield return(queryRequest.Query(ContractFunction.CreateFunction <TFunc>(functionInput), contractAddress)); promise.Build(queryRequest, () => queryRequest.Result); }
/// <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="ContractFunction"/> to execute on the blockchain given the contract address. </typeparam> /// <param name="contractAddress"> The contract address to execute the <see cref="ContractFunction"/> on. </param> /// <param name="message"> The message representing the transaction. </param> /// <param name="signedUnityRequest"> The <see cref="TransactionSignedUnityRequest"/> to use to send the message. </param> /// <param name="gasPrice"> The <see cref="HexBigInteger"/> gas price to use with the transaction. </param> /// <param name="gasLimit"> The <see cref="HexBigInteger"/> gas limit to use with the transaction. </param> /// <param name="functionInput"> The input parameters of the <see cref="ContractFunction"/>. </param> /// <returns> Promise of the transaction result of sending the contract message. </returns> public static void SendContractMessage <TFunc>( string contractAddress, string message, TransactionSignedUnityRequest signedUnityRequest, HexBigInteger gasPrice, HexBigInteger gasLimit, params object[] functionInput) where TFunc : ContractFunction { _SendContractMessageCoroutine( message, ContractFunction.CreateFunction <TFunc>(gasPrice, gasLimit, functionInput).CreateTransactionInput(contractAddress), signedUnityRequest).StartCoroutine(); }
/// <summary> /// Releases some purpose from the Hodler smart contract. /// </summary> /// <param name="userWalletManager"> The class managing the wallet. </param> /// <param name="gasLimit"> The gas limit to send with the transaction. </param> /// <param name="gasPrice"> The gas price to send with the transaction. </param> /// <param name="id"> The id of the locked purpose item. </param> /// <param name="amountToRelease"> The amount of purpose that will be released. </param> public void Release(UserWalletManager userWalletManager, HexBigInteger gasLimit, HexBigInteger gasPrice, BigInteger id, decimal amountToRelease) { var transactionInput = ContractFunction.CreateFunction <Messages.Release>( userWalletManager, gasPrice, gasLimit, id).CreateTransactionInput(ContractAddress); userWalletManager.SignTransaction <ConfirmReleasePopup>( request => ContractUtils.SendContractMessage("Releasing PRPS", transactionInput, request), gasLimit, gasPrice, 0, ContractAddress, transactionInput.Data, amountToRelease); }
/// <summary> /// Locks a certain amount of purpose into the Hodler smart contract. /// </summary> /// <param name="userWalletManager"> The class managing the wallet. </param> /// <param name="gasLimit"> The gas limit to send with the transaction. </param> /// <param name="gasPrice"> The gas price to send with the transaction. </param> /// <param name="id"> The id of the lock function call. </param> /// <param name="value"> The amount of purpose to lock. </param> /// <param name="monthsToLock"> How many months the purpose should be locked for. </param> public void Hodl(UserWalletManager userWalletManager, HexBigInteger gasLimit, HexBigInteger gasPrice, BigInteger id, decimal value, int monthsToLock) { var transactionInput = ContractFunction.CreateFunction <Messages.Hodl>( userWalletManager, gasPrice, gasLimit, id, SolidityUtils.ConvertToUInt(value, 18), new BigInteger(monthsToLock)).CreateTransactionInput(ContractAddress); userWalletManager.SignTransaction <ConfirmLockPopup>( request => ContractUtils.SendContractMessage("Locking PRPS", transactionInput, request), gasLimit, gasPrice, 0, ContractAddress, transactionInput.Data, monthsToLock, value); }
/// <summary> /// Transfers a certain number of tokens of this contract from a wallet to another address. /// </summary> /// <param name="userWalletManager"> The wallet to transfer the tokens from. </param> /// <param name="gasLimit"> The gas limit to use when sending the tokens. </param> /// <param name="gasPrice"> The gas price to use when sending the tokens. </param> /// <param name="address"> The address to transfer the tokens to. </param> /// <param name="amount"> The amount of tokens to transfer. </param> public void Transfer(UserWalletManager userWalletManager, HexBigInteger gasLimit, HexBigInteger gasPrice, string address, decimal amount) { var transactionInput = ContractFunction.CreateFunction <Messages.Transfer>( userWalletManager, gasPrice, gasLimit, address, SolidityUtils.ConvertToUInt(amount, Decimals.Value)).CreateTransactionInput(ContractAddress); userWalletManager.SignTransaction <ConfirmTransactionPopup>( request => ContractUtils.SendContractMessage($"Sending {Symbol}", transactionInput, request), gasLimit, gasPrice, 0, ContractAddress, transactionInput.Data, address, ContractAddress, amount, Symbol); }