/** * Module: NativeApi.cs * Description: Represents a collection of functions to interact with the API endpoints * Author: Moralis Web3 Technology AB, 559307-5988 - David B. Goodrich * * NOTE: THIS FILE HAS BEEN AUTOMATICALLY GENERATED. ANY CHANGES MADE TO THIS * FILE WILL BE LOST * * MIT License * * Copyright (c) 2022 Moralis Web3 Technology AB, 559307-5988 * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the 'Software'), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and / or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ using System; using System.Collections.Generic; using Newtonsoft.Json; using System.Net; using Cysharp.Threading.Tasks; using MoralisUnity.Web3Api.Client; using MoralisUnity.Web3Api.Core; using MoralisUnity.Web3Api.Core.Models; using MoralisUnity.Web3Api.Interfaces; using MoralisUnity.Web3Api.Models; namespace MoralisUnity.Web3Api.CloudApi { /// /// Represents a collection of functions to interact with the API endpoints /// public class NativeApi : INativeApi { /// /// Initializes a new instance of the class. /// /// an instance of ApiClient (optional) /// public NativeApi(ApiClient apiClient = null) { if (apiClient == null) // use the default one in Configuration this.ApiClient = Configuration.DefaultApiClient; else this.ApiClient = apiClient; } /// /// Initializes a new instance of the class. /// /// public NativeApi(String basePath) { this.ApiClient = new ApiClient(basePath); } /// /// Sets the base path of the API client. /// /// The base path /// The base path public void SetBasePath(String basePath) { this.ApiClient.BasePath = basePath; } /// /// Gets the base path of the API client. /// /// The base path /// The base path public String GetBasePath(String basePath) { return this.ApiClient.BasePath; } /// /// Gets or sets the API client. /// /// An instance of the ApiClient public ApiClient ApiClient {get; set;} /// /// Gets the contents of a block by block hash /// /// The block hash or block number /// The chain to query /// The subdomain of the moralis server to use (Only use when selecting local devchain as chain) /// Returns the contents of a block public async UniTask GetBlock (string blockNumberOrHash, ChainList chain, string subdomain=null) { // Verify the required parameter 'blockNumberOrHash' is set if (blockNumberOrHash == null) throw new ApiException(400, "Missing required parameter 'blockNumberOrHash' when calling GetBlock"); var postBody = new Dictionary(); var queryParams = new Dictionary(); var headerParams = new Dictionary(); var formParams = new Dictionary(); var fileParams = new Dictionary(); var path = "/functions/getBlock"; if (blockNumberOrHash != null) postBody.Add("block_number_or_hash", ApiClient.ParameterToString(blockNumberOrHash)); if (subdomain != null) postBody.Add("subdomain", ApiClient.ParameterToString(subdomain)); postBody.Add("chain", ApiClient.ParameterToHex((long)chain)); // Authentication setting, if any String[] authSettings = new String[] { "ApiKeyAuth" }; string bodyData = postBody.Count > 0 ? JsonConvert.SerializeObject(postBody) : null; Tuple, string> response = await ApiClient.CallApi(path, Method.POST, queryParams, bodyData, headerParams, formParams, fileParams, authSettings); if (((int)response.Item1) >= 400) throw new ApiException((int)response.Item1, "Error calling GetBlock: " + response.Item3, response.Item3); else if (((int)response.Item1) == 0) throw new ApiException((int)response.Item1, "Error calling GetBlock: " + response.Item3, response.Item3); return ((CloudFunctionResult)ApiClient.Deserialize(response.Item3, typeof(CloudFunctionResult), response.Item2)).Result; } /// /// Gets the closest block of the provided date /// /// Unix date in miliseconds or a datestring (any format that is accepted by momentjs) /// The chain to query /// web3 provider url to user when using local dev chain /// Returns the blocknumber and corresponding date and timestamp public async UniTask GetDateToBlock (string date, ChainList chain, string providerUrl=null) { // Verify the required parameter 'date' is set if (date == null) throw new ApiException(400, "Missing required parameter 'date' when calling GetDateToBlock"); var postBody = new Dictionary(); var queryParams = new Dictionary(); var headerParams = new Dictionary(); var formParams = new Dictionary(); var fileParams = new Dictionary(); var path = "/functions/getDateToBlock"; if (date != null) postBody.Add("date", ApiClient.ParameterToString(date)); if (providerUrl != null) postBody.Add("providerUrl", ApiClient.ParameterToString(providerUrl)); postBody.Add("chain", ApiClient.ParameterToHex((long)chain)); // Authentication setting, if any String[] authSettings = new String[] { "ApiKeyAuth" }; string bodyData = postBody.Count > 0 ? JsonConvert.SerializeObject(postBody) : null; Tuple, string> response = await ApiClient.CallApi(path, Method.POST, queryParams, bodyData, headerParams, formParams, fileParams, authSettings); if (((int)response.Item1) >= 400) throw new ApiException((int)response.Item1, "Error calling GetDateToBlock: " + response.Item3, response.Item3); else if (((int)response.Item1) == 0) throw new ApiException((int)response.Item1, "Error calling GetDateToBlock: " + response.Item3, response.Item3); return ((CloudFunctionResult)ApiClient.Deserialize(response.Item3, typeof(CloudFunctionResult), response.Item2)).Result; } /// /// Gets the logs from an address /// /// address /// The chain to query /// The subdomain of the moralis server to use (Only use when selecting local devchain as chain) /// The block number /// * Provide the param 'block_numer' or ('from_block' and / or 'to_block') /// * If 'block_numer' is provided in conbinaison with 'from_block' and / or 'to_block', 'block_number' will will be used /// /// The minimum block number from where to get the logs /// * Provide the param 'block_numer' or ('from_block' and / or 'to_block') /// * If 'block_numer' is provided in conbinaison with 'from_block' and / or 'to_block', 'block_number' will will be used /// /// The maximum block number from where to get the logs /// * Provide the param 'block_numer' or ('from_block' and / or 'to_block') /// * If 'block_numer' is provided in conbinaison with 'from_block' and / or 'to_block', 'block_number' will will be used /// /// The date from where to get the logs (any format that is accepted by momentjs) /// * Provide the param 'from_block' or 'from_date' /// * If 'from_date' and 'from_block' are provided, 'from_block' will be used. /// * If 'from_date' and the block params are provided, the block params will be used. Please refer to the blocks params sections (block_number,from_block and to_block) on how to use them /// /// Get the logs to this date (any format that is accepted by momentjs) /// * Provide the param 'to_block' or 'to_date' /// * If 'to_date' and 'to_block' are provided, 'to_block' will be used. /// * If 'to_date' and the block params are provided, the block params will be used. Please refer to the blocks params sections (block_number,from_block and to_block) on how to use them /// /// topic0 /// topic1 /// topic2 /// topic3 /// limit /// Returns the logs of an address public async UniTask GetLogsByAddress (string address, ChainList chain, string cursor="", string subdomain=null, string blockNumber=null, string fromBlock=null, string toBlock=null, string fromDate=null, string toDate=null, string topic0=null, string topic1=null, string topic2=null, string topic3=null, int? limit = null) { // Verify the required parameter 'address' is set if (address == null) throw new ApiException(400, "Missing required parameter 'address' when calling GetLogsByAddress"); var postBody = new Dictionary(); var queryParams = new Dictionary(); var headerParams = new Dictionary(); var formParams = new Dictionary(); var fileParams = new Dictionary(); var path = "/functions/getLogsByAddress"; if (address != null) postBody.Add("address", ApiClient.ParameterToString(address)); if (subdomain != null) postBody.Add("subdomain", ApiClient.ParameterToString(subdomain)); if (blockNumber != null) postBody.Add("block_number", ApiClient.ParameterToString(blockNumber)); if (fromBlock != null) postBody.Add("from_block", ApiClient.ParameterToString(fromBlock)); if (toBlock != null) postBody.Add("to_block", ApiClient.ParameterToString(toBlock)); if (fromDate != null) postBody.Add("from_date", ApiClient.ParameterToString(fromDate)); if (toDate != null) postBody.Add("to_date", ApiClient.ParameterToString(toDate)); if (topic0 != null) postBody.Add("topic0", ApiClient.ParameterToString(topic0)); if (topic1 != null) postBody.Add("topic1", ApiClient.ParameterToString(topic1)); if (topic2 != null) postBody.Add("topic2", ApiClient.ParameterToString(topic2)); if (topic3 != null) postBody.Add("topic3", ApiClient.ParameterToString(topic3)); if (cursor != null) postBody.Add("cursor", ApiClient.ParameterToString(cursor)); if (limit != null) postBody.Add("limit", ApiClient.ParameterToString(limit)); postBody.Add("chain", ApiClient.ParameterToHex((long)chain)); // Authentication setting, if any String[] authSettings = new String[] { "ApiKeyAuth" }; string bodyData = postBody.Count > 0 ? JsonConvert.SerializeObject(postBody) : null; Tuple, string> response = await ApiClient.CallApi(path, Method.POST, queryParams, bodyData, headerParams, formParams, fileParams, authSettings); if (((int)response.Item1) >= 400) throw new ApiException((int)response.Item1, "Error calling GetLogsByAddress: " + response.Item3, response.Item3); else if (((int)response.Item1) == 0) throw new ApiException((int)response.Item1, "Error calling GetLogsByAddress: " + response.Item3, response.Item3); return ((CloudFunctionResult)ApiClient.Deserialize(response.Item3, typeof(CloudFunctionResult), response.Item2)).Result; } /// /// Gets NFT transfers by block number or block hash /// /// The block hash or block number /// The chain to query /// cursor /// The subdomain of the moralis server to use (Only use when selecting local devchain as chain) /// limit /// Returns the contents of a block public async UniTask GetNFTTransfersByBlock (string blockNumberOrHash, ChainList chain, string cursor="", string subdomain=null, int? limit=null) { // Verify the required parameter 'blockNumberOrHash' is set if (blockNumberOrHash == null) throw new ApiException(400, "Missing required parameter 'blockNumberOrHash' when calling GetNFTTransfersByBlock"); var postBody = new Dictionary(); var queryParams = new Dictionary(); var headerParams = new Dictionary(); var formParams = new Dictionary(); var fileParams = new Dictionary(); var path = "/functions/getNFTTransfersByBlock"; if (blockNumberOrHash != null) postBody.Add("block_number_or_hash", ApiClient.ParameterToString(blockNumberOrHash)); if (subdomain != null) postBody.Add("subdomain", ApiClient.ParameterToString(subdomain)); if (cursor != null) postBody.Add("cursor", ApiClient.ParameterToString(cursor)); if (limit != null) postBody.Add("limit", ApiClient.ParameterToString(limit)); postBody.Add("chain", ApiClient.ParameterToHex((long)chain)); // Authentication setting, if any String[] authSettings = new String[] { "ApiKeyAuth" }; string bodyData = postBody.Count > 0 ? JsonConvert.SerializeObject(postBody) : null; Tuple, string> response = await ApiClient.CallApi(path, Method.POST, queryParams, bodyData, headerParams, formParams, fileParams, authSettings); if (((int)response.Item1) >= 400) throw new ApiException((int)response.Item1, "Error calling GetNFTTransfersByBlock: " + response.Item3, response.Item3); else if (((int)response.Item1) == 0) throw new ApiException((int)response.Item1, "Error calling GetNFTTransfersByBlock: " + response.Item3, response.Item3); return ((CloudFunctionResult)ApiClient.Deserialize(response.Item3, typeof(CloudFunctionResult), response.Item2)).Result; } /// /// Gets the contents of a block transaction by hash /// /// The transaction hash /// The chain to query /// The subdomain of the moralis server to use (Only use when selecting local devchain as chain) /// Returns the contents of a block transaction public async UniTask GetTransaction (string transactionHash, ChainList chain, string subdomain=null) { // Verify the required parameter 'transactionHash' is set if (transactionHash == null) throw new ApiException(400, "Missing required parameter 'transactionHash' when calling GetTransaction"); var postBody = new Dictionary(); var queryParams = new Dictionary(); var headerParams = new Dictionary(); var formParams = new Dictionary(); var fileParams = new Dictionary(); var path = "/functions/getTransaction"; if (transactionHash != null) postBody.Add("transaction_hash", ApiClient.ParameterToString(transactionHash)); if (subdomain != null) postBody.Add("subdomain", ApiClient.ParameterToString(subdomain)); postBody.Add("chain", ApiClient.ParameterToHex((long)chain)); // Authentication setting, if any String[] authSettings = new String[] { "ApiKeyAuth" }; string bodyData = postBody.Count > 0 ? JsonConvert.SerializeObject(postBody) : null; Tuple, string> response = await ApiClient.CallApi(path, Method.POST, queryParams, bodyData, headerParams, formParams, fileParams, authSettings); if (((int)response.Item1) >= 400) throw new ApiException((int)response.Item1, "Error calling GetTransaction: " + response.Item3, response.Item3); else if (((int)response.Item1) == 0) throw new ApiException((int)response.Item1, "Error calling GetTransaction: " + response.Item3, response.Item3); return ((CloudFunctionResult)ApiClient.Deserialize(response.Item3, typeof(CloudFunctionResult), response.Item2)).Result; } /// /// Gets events in descending order based on block number /// /// address /// The topic of the event /// ABI of the specific event /// The chain to query /// offset /// The subdomain of the moralis server to use (Only use when selecting local devchain as chain) /// web3 provider url to user when using local dev chain /// The minimum block number from where to get the logs /// * Provide the param 'from_block' or 'from_date' /// * If 'from_date' and 'from_block' are provided, 'from_block' will be used. /// /// The maximum block number from where to get the logs. /// * Provide the param 'to_block' or 'to_date' /// * If 'to_date' and 'to_block' are provided, 'to_block' will be used. /// /// The date from where to get the logs (any format that is accepted by momentjs) /// * Provide the param 'from_block' or 'from_date' /// * If 'from_date' and 'from_block' are provided, 'from_block' will be used. /// /// Get the logs to this date (any format that is accepted by momentjs) /// * Provide the param 'to_block' or 'to_date' /// * If 'to_date' and 'to_block' are provided, 'to_block' will be used. /// /// limit /// Returns a collection of events by topic public async UniTask> GetContractEvents (string address, string topic, object abi, ChainList chain, string cursor="", string subdomain=null, string providerUrl=null, int? fromBlock=null, int? toBlock=null, string fromDate=null, string toDate=null, int? limit=null) { // Verify the required parameter 'address' is set if (address == null) throw new ApiException(400, "Missing required parameter 'address' when calling GetContractEvents"); // Verify the required parameter 'topic' is set if (topic == null) throw new ApiException(400, "Missing required parameter 'topic' when calling GetContractEvents"); // Verify the required parameter 'abi' is set if (abi == null) throw new ApiException(400, "Missing required parameter 'abi' when calling GetContractEvents"); var postBody = new Dictionary(); var queryParams = new Dictionary(); var headerParams = new Dictionary(); var formParams = new Dictionary(); var fileParams = new Dictionary(); var path = "/functions/getContractEvents"; if (address != null) postBody.Add("address", ApiClient.ParameterToString(address)); if (topic != null) postBody.Add("topic", ApiClient.ParameterToString(topic)); if (abi != null) postBody.Add("abi", abi); if (subdomain != null) postBody.Add("subdomain", ApiClient.ParameterToString(subdomain)); if (providerUrl != null) postBody.Add("providerUrl", ApiClient.ParameterToString(providerUrl)); if (fromBlock != null) postBody.Add("from_block", ApiClient.ParameterToString(fromBlock)); if (toBlock != null) postBody.Add("to_block", ApiClient.ParameterToString(toBlock)); if (fromDate != null) postBody.Add("from_date", ApiClient.ParameterToString(fromDate)); if (toDate != null) postBody.Add("to_date", ApiClient.ParameterToString(toDate)); if (cursor != null) postBody.Add("cursor", ApiClient.ParameterToString(cursor)); if (limit != null) postBody.Add("limit", ApiClient.ParameterToString(limit)); postBody.Add("chain", ApiClient.ParameterToHex((long)chain)); // Authentication setting, if any String[] authSettings = new String[] { "ApiKeyAuth" }; string bodyData = postBody.Count > 0 ? JsonConvert.SerializeObject(postBody) : null; Tuple, string> response = await ApiClient.CallApi(path, Method.POST, queryParams, bodyData, headerParams, formParams, fileParams, authSettings); if (((int)response.Item1) >= 400) throw new ApiException((int)response.Item1, "Error calling GetContractEvents: " + response.Item3, response.Item3); else if (((int)response.Item1) == 0) throw new ApiException((int)response.Item1, "Error calling GetContractEvents: " + response.Item3, response.Item3); LogEventResponse resp = ((CloudFunctionResult)ApiClient.Deserialize(response.Item3, typeof(CloudFunctionResult), response.Item2)).Result; return resp.Events; } /// /// Runs a given function of a contract abi and returns readonly data /// /// address /// function_name /// Body /// The chain to query /// The subdomain of the moralis server to use (Only use when selecting local devchain as chain) /// web3 provider url to user when using local dev chain /// Returns response of the function executed public async UniTask RunContractFunction (string address, string functionName, RunContractDto abi, ChainList chain, string subdomain=null, string providerUrl=null) { // Verify the required parameter 'address' is set if (address == null) throw new ApiException(400, "Missing required parameter 'address' when calling RunContractFunction"); // Verify the required parameter 'functionName' is set if (functionName == null) throw new ApiException(400, "Missing required parameter 'functionName' when calling RunContractFunction"); // Verify the required parameter 'abi' is set if (abi == null) throw new ApiException(400, "Missing required parameter 'abi' when calling RunContractFunction"); var postBody = new Dictionary(); var queryParams = new Dictionary(); var headerParams = new Dictionary(); var formParams = new Dictionary(); var fileParams = new Dictionary(); var path = "/functions/runContractFunction"; if (address != null) postBody.Add("address", ApiClient.ParameterToString(address)); if (functionName != null) postBody.Add("function_name", ApiClient.ParameterToString(functionName)); if (abi != null) postBody.Add("abi", abi.Abi); if (abi != null) postBody.Add("params", abi.Params); if (subdomain != null) postBody.Add("subdomain", ApiClient.ParameterToString(subdomain)); if (providerUrl != null) postBody.Add("providerUrl", ApiClient.ParameterToString(providerUrl)); postBody.Add("chain", ApiClient.ParameterToHex((long)chain)); // Authentication setting, if any String[] authSettings = new String[] { "ApiKeyAuth" }; string bodyData = postBody.Count > 0 ? JsonConvert.SerializeObject(postBody) : null; Tuple, string> response = await ApiClient.CallApi(path, Method.POST, queryParams, bodyData, headerParams, formParams, fileParams, authSettings); if (((int)response.Item1) >= 400) throw new ApiException((int)response.Item1, "Error calling GetContractEvents: " + response.Item3, response.Item3); else if (((int)response.Item1) == 0) throw new ApiException((int)response.Item1, "Error calling GetContractEvents: " + response.Item3, response.Item3); T resp = ((CloudFunctionResult)ApiClient.Deserialize(response.Item3, typeof(CloudFunctionResult), response.Item2)).Result; return resp; } } }