cryptoapis/apis/
automatic_tokens_forwarding_api.rs

1/*
2 * CryptoAPIs
3 *
4 * Crypto APIs is a complex and innovative infrastructure layer that radically simplifies the development of any Blockchain and Crypto related applications. Organized around REST, Crypto APIs can assist both novice Bitcoin/Ethereum enthusiasts and crypto experts with the development of their blockchain applications. Crypto APIs provides unified endpoints and data, raw data, automatic tokens and coins forwardings, callback functionalities, and much more.
5 *
6 * The version of the OpenAPI document: 2021-03-20
7 * Contact: developers@cryptoapis.io
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method `add_tokens_to_existing_from_address`
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AddTokensToExistingFromAddressError {
22    Status400(crate::models::InlineResponse40099),
23    Status401(crate::models::InlineResponse40199),
24    Status402(crate::models::InlineResponse402),
25    Status403(crate::models::InlineResponse40399),
26    Status404(crate::models::InlineResponse4041),
27    Status409(crate::models::InlineResponse409),
28    Status415(crate::models::InlineResponse415),
29    Status422(crate::models::InlineResponse422),
30    Status429(crate::models::InlineResponse429),
31    Status500(crate::models::InlineResponse500),
32    UnknownValue(serde_json::Value),
33}
34
35/// struct for typed errors of method `create_automatic_tokens_forwarding`
36#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum CreateAutomaticTokensForwardingError {
39    Status400(crate::models::InlineResponse40098),
40    Status401(crate::models::InlineResponse40198),
41    Status402(crate::models::InlineResponse402),
42    Status403(crate::models::InlineResponse40398),
43    Status404(crate::models::InlineResponse4041),
44    Status409(crate::models::InlineResponse409),
45    Status415(crate::models::InlineResponse415),
46    Status422(crate::models::InlineResponse422),
47    Status429(crate::models::InlineResponse429),
48    Status500(crate::models::InlineResponse500),
49    UnknownValue(serde_json::Value),
50}
51
52/// struct for typed errors of method `delete_automatic_tokens_forwarding`
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum DeleteAutomaticTokensForwardingError {
56    Status400(crate::models::InlineResponse400101),
57    Status401(crate::models::InlineResponse401101),
58    Status402(crate::models::InlineResponse402),
59    Status403(crate::models::InlineResponse403101),
60    Status404(crate::models::InlineResponse4041),
61    Status409(crate::models::InlineResponse409),
62    Status415(crate::models::InlineResponse415),
63    Status422(crate::models::InlineResponse422),
64    Status429(crate::models::InlineResponse429),
65    Status500(crate::models::InlineResponse500),
66    UnknownValue(serde_json::Value),
67}
68
69/// struct for typed errors of method `get_fee_address_details`
70#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum GetFeeAddressDetailsError {
73    Status400(crate::models::InlineResponse400100),
74    Status401(crate::models::InlineResponse401100),
75    Status402(crate::models::InlineResponse402),
76    Status403(crate::models::InlineResponse403100),
77    Status404(crate::models::InlineResponse4041),
78    Status409(crate::models::InlineResponse409),
79    Status415(crate::models::InlineResponse415),
80    Status422(crate::models::InlineResponse422),
81    Status429(crate::models::InlineResponse429),
82    Status500(crate::models::InlineResponse500),
83    UnknownValue(serde_json::Value),
84}
85
86/// struct for typed errors of method `list_tokens_forwarding_automations`
87#[derive(Debug, Clone, Serialize, Deserialize)]
88#[serde(untagged)]
89pub enum ListTokensForwardingAutomationsError {
90    Status400(crate::models::InlineResponse40097),
91    Status401(crate::models::InlineResponse40197),
92    Status402(crate::models::InlineResponse402),
93    Status403(crate::models::InlineResponse40397),
94    Status404(crate::models::InlineResponse4041),
95    Status409(crate::models::InlineResponse409),
96    Status415(crate::models::InlineResponse415),
97    Status422(crate::models::InlineResponse422),
98    Status429(crate::models::InlineResponse429),
99    Status500(crate::models::InlineResponse500),
100    UnknownValue(serde_json::Value),
101}
102
103
104/// Through this endpoint customers can add **Automatic Tokens forwardings** to an already existing `fromAddress`. Unlike the \"Create Automatic Tokens Forwarding\" endpoint, where the `fromAddress` is generated each time, with this endpoint customers can add an automation from another token to one and the same `fromAddress`.    The `fromAddress` can be used as a deposit address. Any funds received by this address will be automatically forwarded to `toAddress` based on what the customer has set for the automation. The  `toAddress` is essentially the main address and destination for the automatic tokens forwarding.    There is also a `minimumTransferAmount` which only when reached will then trigger the forwarding. Through this the customer can save from fees.    Moreover, `feePriority` can be also set,  which defines how quickly to move the tokens once they are received. The higher priority, the larger the fee will be. It can be \"SLOW\", \"STANDARD\" or \"FAST\".    For this automatic forwarding the customer can set a callback subscription.    {warning}Currently we support fungible tokens (ERC-20) **only**, NFTs (ERC-721) are **not** supported.{/warning}    {warning}The subscription will work for all incoming transactions until it is deleted. There is no need to do that for every transaction.{/warning}
105pub async fn add_tokens_to_existing_from_address(configuration: &configuration::Configuration, blockchain: &str, network: &str, context: Option<&str>, add_tokens_to_existing_from_address_rb: Option<crate::models::AddTokensToExistingFromAddressRb>) -> Result<crate::models::AddTokensToExistingFromAddressR, Error<AddTokensToExistingFromAddressError>> {
106
107    let local_var_client = &configuration.client;
108
109    let local_var_uri_str = format!("{}/blockchain-automations/{blockchain}/{network}/tokens-forwarding/automations/add-token", configuration.base_path, blockchain=crate::apis::urlencode(blockchain), network=crate::apis::urlencode(network));
110    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
111
112    if let Some(ref local_var_str) = context {
113        local_var_req_builder = local_var_req_builder.query(&[("context", &local_var_str.to_string())]);
114    }
115    if let Some(ref local_var_user_agent) = configuration.user_agent {
116        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
117    }
118    if let Some(ref local_var_apikey) = configuration.api_key {
119        let local_var_key = local_var_apikey.key.clone();
120        let local_var_value = match local_var_apikey.prefix {
121            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
122            None => local_var_key,
123        };
124        local_var_req_builder = local_var_req_builder.header("x-api-key", local_var_value);
125    };
126    local_var_req_builder = local_var_req_builder.json(&add_tokens_to_existing_from_address_rb);
127
128    let local_var_req = local_var_req_builder.build()?;
129    let local_var_resp = local_var_client.execute(local_var_req).await?;
130
131    let local_var_status = local_var_resp.status();
132    let local_var_content = local_var_resp.text().await?;
133
134    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
135        serde_json::from_str(&local_var_content).map_err(Error::from)
136    } else {
137        let local_var_entity: Option<AddTokensToExistingFromAddressError> = serde_json::from_str(&local_var_content).ok();
138        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
139        Err(Error::ResponseError(local_var_error))
140    }
141}
142
143/// Through this endpoint customers can set up an automatic forwarding function specifically for tokens (**not** coins). They can have a `toAddress` which is essentially the main address and the destination for the automatic tokens forwarding.     There is also a `minimumTransferAmount` which only when reached will then trigger the forwarding. Through this the customer can save from fees.    Moreover, `feePriority` can be also set,  which defines how quickly to move the tokens once they are received. The higher priority, the larger the fee will be. It can be \"SLOW\", \"STANDARD\" or \"FAST\".    The response of this endpoint contains an attribute `fromAddress` which can be used as a deposit address. Any funds received by this address will be automatically forwarded to `toAddress` based on what the customer has set for the automation.    For this automatic forwarding the customer can set a callback subscription.    {warning}Currently we support fungible tokens (ERC-20) **only**, NFTs (ERC-721) are **not** supported.{/warning}    {warning}The subscription will work for all incoming transactions until it is deleted. There is no need to do that for every transaction.{/warning}    {note}This endpoint generates a new `fromAddress` each time.{/note}
144pub async fn create_automatic_tokens_forwarding(configuration: &configuration::Configuration, blockchain: &str, network: &str, context: Option<&str>, create_automatic_tokens_forwarding_rb: Option<crate::models::CreateAutomaticTokensForwardingRb>) -> Result<crate::models::CreateAutomaticTokensForwardingR, Error<CreateAutomaticTokensForwardingError>> {
145
146    let local_var_client = &configuration.client;
147
148    let local_var_uri_str = format!("{}/blockchain-automations/{blockchain}/{network}/tokens-forwarding/automations", configuration.base_path, blockchain=crate::apis::urlencode(blockchain), network=crate::apis::urlencode(network));
149    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
150
151    if let Some(ref local_var_str) = context {
152        local_var_req_builder = local_var_req_builder.query(&[("context", &local_var_str.to_string())]);
153    }
154    if let Some(ref local_var_user_agent) = configuration.user_agent {
155        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
156    }
157    if let Some(ref local_var_apikey) = configuration.api_key {
158        let local_var_key = local_var_apikey.key.clone();
159        let local_var_value = match local_var_apikey.prefix {
160            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
161            None => local_var_key,
162        };
163        local_var_req_builder = local_var_req_builder.header("x-api-key", local_var_value);
164    };
165    local_var_req_builder = local_var_req_builder.json(&create_automatic_tokens_forwarding_rb);
166
167    let local_var_req = local_var_req_builder.build()?;
168    let local_var_resp = local_var_client.execute(local_var_req).await?;
169
170    let local_var_status = local_var_resp.status();
171    let local_var_content = local_var_resp.text().await?;
172
173    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
174        serde_json::from_str(&local_var_content).map_err(Error::from)
175    } else {
176        let local_var_entity: Option<CreateAutomaticTokensForwardingError> = serde_json::from_str(&local_var_content).ok();
177        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
178        Err(Error::ResponseError(local_var_error))
179    }
180}
181
182/// Through this endpoint customers can delete a forwarding function they have set for **tokens** (**not** coins).    By setting a `fromAddress` and a `toAddress`, and specifying the amount, tokens can be transferred between addresses.     A `feePriority` will be returned which represents the fee priority of the automation whether it is \"SLOW\", \"STANDARD\" OR \"FAST\".    {warning}Currently we support fungible tokens (ERC-20) **only**, NFTs (ERC-721) are **not** supported.{/warning}    {warning}The subscription will work for all incoming transactions until it is deleted. There is no need to do that for every transaction.{/warning}
183pub async fn delete_automatic_tokens_forwarding(configuration: &configuration::Configuration, blockchain: &str, network: &str, reference_id: &str, context: Option<&str>) -> Result<crate::models::DeleteAutomaticTokensForwardingR, Error<DeleteAutomaticTokensForwardingError>> {
184
185    let local_var_client = &configuration.client;
186
187    let local_var_uri_str = format!("{}/blockchain-automations/{blockchain}/{network}/tokens-forwarding/automations/{referenceId}", configuration.base_path, blockchain=crate::apis::urlencode(blockchain), network=crate::apis::urlencode(network), referenceId=crate::apis::urlencode(reference_id));
188    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
189
190    if let Some(ref local_var_str) = context {
191        local_var_req_builder = local_var_req_builder.query(&[("context", &local_var_str.to_string())]);
192    }
193    if let Some(ref local_var_user_agent) = configuration.user_agent {
194        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
195    }
196    if let Some(ref local_var_apikey) = configuration.api_key {
197        let local_var_key = local_var_apikey.key.clone();
198        let local_var_value = match local_var_apikey.prefix {
199            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
200            None => local_var_key,
201        };
202        local_var_req_builder = local_var_req_builder.header("x-api-key", local_var_value);
203    };
204
205    let local_var_req = local_var_req_builder.build()?;
206    let local_var_resp = local_var_client.execute(local_var_req).await?;
207
208    let local_var_status = local_var_resp.status();
209    let local_var_content = local_var_resp.text().await?;
210
211    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
212        serde_json::from_str(&local_var_content).map_err(Error::from)
213    } else {
214        let local_var_entity: Option<DeleteAutomaticTokensForwardingError> = serde_json::from_str(&local_var_content).ok();
215        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
216        Err(Error::ResponseError(local_var_error))
217    }
218}
219
220/// Through this endpoint customers can obtain details about a fee address. Only one fee address per currency per network for a user's account can be set no matter how many tokens or subscriptions they have or want to automatically forward.    {warning}Currently we support fungible tokens (ERC-20) **only**, NFTs (ERC-721) are **not** supported.{/warning}
221pub async fn get_fee_address_details(configuration: &configuration::Configuration, blockchain: &str, network: &str, context: Option<&str>) -> Result<crate::models::GetFeeAddressDetailsR, Error<GetFeeAddressDetailsError>> {
222
223    let local_var_client = &configuration.client;
224
225    let local_var_uri_str = format!("{}/blockchain-automations/{blockchain}/{network}/tokens-forwarding/fee-addresses", configuration.base_path, blockchain=crate::apis::urlencode(blockchain), network=crate::apis::urlencode(network));
226    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
227
228    if let Some(ref local_var_str) = context {
229        local_var_req_builder = local_var_req_builder.query(&[("context", &local_var_str.to_string())]);
230    }
231    if let Some(ref local_var_user_agent) = configuration.user_agent {
232        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
233    }
234    if let Some(ref local_var_apikey) = configuration.api_key {
235        let local_var_key = local_var_apikey.key.clone();
236        let local_var_value = match local_var_apikey.prefix {
237            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
238            None => local_var_key,
239        };
240        local_var_req_builder = local_var_req_builder.header("x-api-key", local_var_value);
241    };
242
243    let local_var_req = local_var_req_builder.build()?;
244    let local_var_resp = local_var_client.execute(local_var_req).await?;
245
246    let local_var_status = local_var_resp.status();
247    let local_var_content = local_var_resp.text().await?;
248
249    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
250        serde_json::from_str(&local_var_content).map_err(Error::from)
251    } else {
252        let local_var_entity: Option<GetFeeAddressDetailsError> = serde_json::from_str(&local_var_content).ok();
253        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
254        Err(Error::ResponseError(local_var_error))
255    }
256}
257
258/// Through this endpoint customers can list all of their **tokens** forwarding automations (**not** coins).    Customers can set up automatic forwarding functions for tokens by setting a `fromAddress` and a `toAddress`, and specifying the amount that can be transferred between addresses.     A `feePriority` will be returned which represents the fee priority of the automation whether it is \"SLOW\", \"STANDARD\" OR \"FAST\".     {warning}Currently we support fungible tokens (ERC-20) **only**, NFTs (ERC-721) are **not** supported.{/warning}    {warning}The subscription will work for all transactions until it is deleted. There is no need to do that for every transaction.{/warning}
259pub async fn list_tokens_forwarding_automations(configuration: &configuration::Configuration, blockchain: &str, network: &str, context: Option<&str>, limit: Option<i64>, offset: Option<i64>) -> Result<crate::models::ListTokensForwardingAutomationsR, Error<ListTokensForwardingAutomationsError>> {
260
261    let local_var_client = &configuration.client;
262
263    let local_var_uri_str = format!("{}/blockchain-automations/{blockchain}/{network}/tokens-forwarding/automations", configuration.base_path, blockchain=crate::apis::urlencode(blockchain), network=crate::apis::urlencode(network));
264    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
265
266    if let Some(ref local_var_str) = context {
267        local_var_req_builder = local_var_req_builder.query(&[("context", &local_var_str.to_string())]);
268    }
269    if let Some(ref local_var_str) = limit {
270        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
271    }
272    if let Some(ref local_var_str) = offset {
273        local_var_req_builder = local_var_req_builder.query(&[("offset", &local_var_str.to_string())]);
274    }
275    if let Some(ref local_var_user_agent) = configuration.user_agent {
276        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
277    }
278    if let Some(ref local_var_apikey) = configuration.api_key {
279        let local_var_key = local_var_apikey.key.clone();
280        let local_var_value = match local_var_apikey.prefix {
281            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
282            None => local_var_key,
283        };
284        local_var_req_builder = local_var_req_builder.header("x-api-key", local_var_value);
285    };
286
287    let local_var_req = local_var_req_builder.build()?;
288    let local_var_resp = local_var_client.execute(local_var_req).await?;
289
290    let local_var_status = local_var_resp.status();
291    let local_var_content = local_var_resp.text().await?;
292
293    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
294        serde_json::from_str(&local_var_content).map_err(Error::from)
295    } else {
296        let local_var_entity: Option<ListTokensForwardingAutomationsError> = serde_json::from_str(&local_var_content).ok();
297        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
298        Err(Error::ResponseError(local_var_error))
299    }
300}
301