/// <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); }
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> 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); }
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); }
/// <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); }
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> /// 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 <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 <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); }
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); }
/// <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 <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); }
public override EthCallPromise <int?> QueryDecimals() { EthCallPromise <int?> promise = new EthCallPromise <int?>(); promise.Build(() => 0); 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> /// 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> /// 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> /// 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); }