public override EthCallPromise <int?> QueryDecimals() { EthCallPromise <int?> promise = new EthCallPromise <int?>(); promise.Build(() => 0); return(promise); }
/// <summary> /// Gets the details of a transaction hash. /// </summary> /// <param name="txHash"> The transaction hash. </param> /// <param name="onTxReceived"> Action to call once the transaction is received. </param> /// <returns> The promise returning the transaction details. </returns> public static EthCallPromise <Transaction> GetTransactionDetails(string txHash) { EthCallPromise <Transaction> promise = new EthCallPromise <Transaction>(); _GetTransactionDetailsCoroutine(txHash, promise).StartCoroutine(); return(promise); }
/// <summary> /// Gets the transaction count of an Ethereum address. /// </summary> /// <param name="address"> The Ethereum address to get the transaction count for. </param> /// <returns> The promise returning the transaction count. </returns> public static EthCallPromise <BigInteger> GetAddressTransactionCount(string address) { EthCallPromise <BigInteger> promise = new EthCallPromise <BigInteger>(); _GetAddressTransactionCount(address, promise).StartCoroutine(); return(promise); }
/// <summary> /// Gets the amount of ether in a user's wallet. /// </summary> /// <param name="address"> The address to check for the ether balance. </param> /// <param name="onBalanceReceived"> Called when the eth balance has been received. </param> /// <returns> The promise which will return the eth balance. </returns> public static EthCallPromise <dynamic> GetEtherBalance(string address) { var promise = new EthCallPromise <dynamic>(); _AddressEthBalanceCoroutine(promise, address).StartCoroutine(); return(promise); }
/// <summary> /// Gets the ether balance of a certain wallet. /// </summary> /// <param name="promise"> Promise of an eventual eth balance returned. </param> /// <param name="address"> The address to check the ether balance for. </param> /// <returns> The time waited for the request to complete. </returns> private static IEnumerator _AddressEthBalanceCoroutine(EthCallPromise <dynamic> promise, string address) { var request = new EthGetBalanceUnityRequest(EthereumNetworkManager.CurrentNetwork.NetworkUrl); yield return(request.SendRequest(address, BlockParameter.CreateLatest())); promise.Build(request, () => SolidityUtils.ConvertFromUInt(request.Result.Value, 18)); }
/// <summary> /// Estimates the gas price based on current network congestion. /// </summary> /// <param name="promise"> Promise of the eventual gas price estimate. </param> /// <param name="gasPriceTarget"> The GasPriceTarget to aim for. </param> /// <returns> The time taken to retrieve the estimated gas limit. </returns> private static IEnumerator _EstimateGasPriceCoroutine(EthCallPromise <BigInteger> promise, GasPriceTarget gasPriceTarget) { var request = new EthGasPriceUnityRequest(NetworkProvider.GetNetworkChainUrl()); yield return(request.SendRequest()); promise.Build(request, () => ModifyGasPrice(gasPriceTarget, request.Result.Value)); }
/// <summary> /// Estimates the gas limit of a certain function of a contract. /// </summary> /// <param name="promise"> Promise of the estimated gas limit of a transaction. </param> /// <param name="callInput"> The transaction input to estimate the gas limit for. </param> /// <param name="overEstimate"> Whether the gas limit should be slightly overestimated. </param> /// <returns> The time taken to retrieve the estimated gas limit. </returns> private static IEnumerator _EstimateGasLimitCoroutine(EthCallPromise <BigInteger> promise, CallInput callInput, bool overEstimate) { var request = new EthEstimateGasUnityRequest(EthereumNetworkManager.CurrentNetwork.NetworkUrl); yield return(request.SendRequest(callInput)); promise.Build(request, () => overEstimate ? (request.Result.Value * 100 / 90) : request.Result.Value); }
/// <summary> /// Estimates the gas price based on current network congestion. /// </summary> /// <param name="promise"> Promise of the eventual gas price estimate. </param> /// <param name="gasPriceTarget"> The GasPriceTarget to aim for. </param> /// <returns> The time taken to retrieve the estimated gas limit. </returns> private static IEnumerator _EstimateGasPriceCoroutine(EthCallPromise <BigInteger> promise, GasPriceTarget gasPriceTarget) { var request = new EthGasPriceUnityRequest(EthereumNetworkManager.CurrentNetwork.NetworkUrl); yield return(request.SendRequest()); promise.Build(request, () => ModifyGasPrice(gasPriceTarget, request.Result.Value)); }
/// <summary> /// Estimates the gas limit for a basic ether transaction. /// </summary> /// <param name="addressTo"> The address the ether is being sent to. </param> /// <param name="value"> The amount of ether in wei that will be sent. </param> /// <returns> Promise of the gas limit estimate of an eth transaction. </returns> public static EthCallPromise <BigInteger> EstimateEthGasLimit(string addressTo, BigInteger value) { var promise = new EthCallPromise <BigInteger>(); _EstimateGasLimitCoroutine(promise, new CallInput("", addressTo, new HexBigInteger(value)), false).StartCoroutine(); return(promise); }
/// <summary> /// Estimates the gas price given the GasPriceTarget. /// </summary> /// <param name="gasPriceTarget"> The target gas price to aim for. </param> /// <returns> Promise of the eventual estimated gas price. </returns> public static EthCallPromise <BigInteger> EstimateGasPrice(GasPriceTarget gasPriceTarget = GasPriceTarget.Standard) { var promise = new EthCallPromise <BigInteger>(); _EstimateGasPriceCoroutine(promise, gasPriceTarget).StartCoroutine(); return(promise); }
public override EthCallPromise <int?> QueryDecimals() { EthCallPromise <int?> promise = new EthCallPromise <int?>(); SimpleContractQueries.QueryUInt256Output(new Queries.Decimals(), ContractAddress, null) .OnSuccess(decimals => promise.Build(() => (int?)decimals?.Value)) .OnError(error => promise.Build(() => "error", () => error)); return(promise); }
public override EthCallPromise <string> QuerySymbol() { EthCallPromise <string> promise = new EthCallPromise <string>(); SimpleContractQueries.QueryStringOutput(new Queries.Symbol(), ContractAddress, null) .OnSuccess(symbol => promise.Build(() => symbol?.Value)) .OnError(error => promise.Build(() => "error", () => error)); return(promise); }
public override EthCallPromise <string> QueryName() { EthCallPromise <string> promise = new EthCallPromise <string>(); SimpleContractQueries.QueryStringOutput <Queries.Name>(ContractAddress, null) .OnSuccess(name => promise.Build(() => name?.Value)) .OnError(error => promise.Build(() => "error", () => error)); return(promise); }
/// <summary> /// Gets the total supply of this ERC721 token contract. /// </summary> public EthCallPromise <BigInteger> QueryTotalSupply() { EthCallPromise <BigInteger> promise = new EthCallPromise <BigInteger>(); SimpleContractQueries.QueryUInt256Output(new Queries.TotalSupply(), ContractAddress, null) .OnSuccess(supply => promise.Build(() => supply.Value)) .OnError(error => promise.Build(() => "error", () => error)); return(promise); }
/// <summary> /// Gets the total supply of this ERC20 token contract. /// </summary> public EthCallPromise <decimal> QueryTotalSupply() { EthCallPromise <decimal> promise = new EthCallPromise <decimal>(); SimpleContractQueries.QueryUInt256Output(new Queries.TotalSupply(), ContractAddress, null) .OnSuccess(supply => promise.Build(() => SolidityUtils.ConvertFromUInt(supply.Value, Decimals.Value))) .OnError(error => promise.Build(() => "error", () => error)); return(promise); }
/// <summary> /// Queries some data from an ethereum smart contract which is active on the blockchain. /// </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="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> /// <returns> The promise which will return the call result. </returns> public static EthCallPromise <TOut> QueryContract <TFunc, TOut>( string contractAddress, string senderAddress, params object[] functionInput) where TFunc : ContractFunction where TOut : IFunctionOutputDTO, new() { var promise = new EthCallPromise <TOut>(); _QueryContractCoroutine <TFunc, TOut>(promise, contractAddress, senderAddress, functionInput).StartCoroutine(); return(promise); }
/// <summary> /// Queries some data from an ethereum smart contract which is active on the blockchain. /// </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="contractAddress"> The contract address to execute the <see cref="FunctionMessage"/> on. </param> /// <param name="senderAddress"> The address of the sender requesting this data. </param> /// <returns> The promise which will return the call result. </returns> public static EthCallPromise <TOut> QueryContract <TFunc, TOut>( TFunc function, string contractAddress, string senderAddress) where TFunc : FunctionMessage, new() where TOut : IFunctionOutputDTO, new() { var promise = new EthCallPromise <TOut>(); _QueryContractCoroutine(function, promise, contractAddress, senderAddress).StartCoroutine(); return(promise); }
/// <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); }
public EthCallPromise <BigInteger> QueryTokenByIndex(BigInteger index) { EthCallPromise <BigInteger> promise = new EthCallPromise <BigInteger>(); SimpleContractQueries.QueryUInt256Output(new Queries.TokenByIndex { Index = index }, ContractAddress, null) .OnSuccess(id => promise.Build(() => id.Value)) .OnError(error => promise.Build(() => "error", () => error)); return(promise); }
public EthCallPromise <bool> QueryIsApprovedForAll(string ownerAddress, string operatorAddress) { EthCallPromise <bool> promise = new EthCallPromise <bool>(); SimpleContractQueries.QueryBoolOutput(new Queries.IsApprovedForAll { Owner = ownerAddress, Operator = operatorAddress }, ContractAddress, null) .OnSuccess(approved => promise.Build(() => approved.Value)) .OnError(error => promise.Build(() => "error", () => error)); return(promise); }
/// <summary> /// Gets the token balance of an address. /// </summary> /// <param name="address"> The address to check the balance of. </param> public EthCallPromise <BigInteger> QueryBalanceOf(string address) { EthCallPromise <BigInteger> promise = new EthCallPromise <BigInteger>(); SimpleContractQueries.QueryUInt256Output(new Queries.BalanceOf { Owner = address }, ContractAddress, address) .OnSuccess(balance => promise.Build(() => balance.Value)) .OnError(error => promise.Build(() => "error", () => error)); return(promise); }
public EthCallPromise <string> QueryOwnerOf(BigInteger tokenId) { EthCallPromise <string> promise = new EthCallPromise <string>(); SimpleContractQueries.QueryAddressOutput(new Queries.OwnerOf { TokenId = tokenId }, ContractAddress, null) .OnSuccess(owner => promise.Build(() => owner.Value)) .OnError(error => promise.Build(() => "error", () => error)); return(promise); }
public EthCallPromise <string> QueryTokenURI(BigInteger tokenId) { EthCallPromise <string> promise = new EthCallPromise <string>(); SimpleContractQueries.QueryStringOutput(new Queries.TokenURI { TokenId = tokenId }, ContractAddress, null) .OnSuccess(uri => promise.Build(() => uri.Value)) .OnError(error => promise.Build(() => "error", () => error)); 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> /// Gets the token balance of an address. /// </summary> /// <param name="address"> The address to check the balance of. </param> public EthCallPromise <decimal> QueryBalanceOf(string address) { EthCallPromise <decimal> promise = new EthCallPromise <decimal>(); SimpleContractQueries.QueryUInt256Output(new Queries.BalanceOf { Owner = address }, ContractAddress, address) .OnSuccess(balance => promise.Build(() => SolidityUtils.ConvertFromUInt(balance.Value, Decimals.Value))) .OnError(error => promise.Build(() => "error", () => error)); return(promise); }
public EthCallPromise <decimal> QueryAllowance(string owner, string spender) { EthCallPromise <decimal> promise = new EthCallPromise <decimal>(); SimpleContractQueries.QueryUInt256Output(new Queries.Allowance { Owner = owner, Spender = spender }, ContractAddress, null) .OnSuccess(allowance => promise.Build(() => SolidityUtils.ConvertFromUInt(allowance.Value, Decimals.Value))) .OnError(error => promise.Build(() => "error", () => error)); return(promise); }
/// <summary> /// Estimates the gas limit of a contract function. /// </summary> /// <typeparam name="TFunc"> The function type to estimate the gas limit for. </typeparam> /// <param name="function"> The function to estimate the the gas limit for. </param> /// <param name="contractAddress"> The address of the contract function to estimate. </param> /// <param name="callerAddress"> The address of the sender. </param> public static EthCallPromise <BigInteger> EstimateContractGasLimit <TFunc>( TFunc function, string contractAddress, string callerAddress) where TFunc : FunctionMessage { function.SetDefaultFromAddressIfNotSet(callerAddress); var promise = new EthCallPromise <BigInteger>(); _EstimateGasLimitCoroutine(promise, function.CreateCallInput(contractAddress), true).StartCoroutine(); return(promise); }
/// <summary> /// The coroutine for getting the details of a transaction. /// </summary> /// <param name="txHash"> The transaction hash. </param> /// <param name="promise"> Promise returning the transaction. </param> /// <returns> The transaction request to await. </returns> private static IEnumerator _GetTransactionDetailsCoroutine(string txHash, EthCallPromise <Transaction> promise) { if (!AddressUtils.IsValidTransactionHash(txHash)) { throw new ArgumentException("Expected valid Ethereum transaction hash."); } var request = new EthGetTransactionByHashUnityRequest(EthereumNetworkManager.CurrentNetwork.NetworkUrl); yield return(request.SendRequest(txHash)); promise.Build(request, () => request.Result); }
/// <summary> /// The coroutine for getting the transaction count of an ethereum address. /// </summary> /// <param name="address"> The address to get the transaction count for. </param> /// <param name="promise"> Promise returning the transaction count. </param> /// <returns> The transaction count request to await. </returns> private static IEnumerator _GetAddressTransactionCount(string address, EthCallPromise <BigInteger> promise) { if (!AddressUtils.IsValidEthereumAddress(address)) { throw new ArgumentException("Expected valid Ethereum address."); } var request = new EthGetTransactionCountUnityRequest(EthereumNetworkManager.CurrentNetwork.NetworkUrl); yield return(request.SendRequest(address, BlockParameter.CreateLatest())); promise.Build(request, () => request.Result.Value); }
/// <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); }