coinbase_mesh/apis/
account_api.rs

1/*
2 * Rosetta
3 *
4 * Build Once. Integrate Your Blockchain Everywhere. 
5 *
6 * The version of the OpenAPI document: 1.4.13
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`account_balance`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AccountBalanceError {
22    Status500(models::Error),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`account_coins`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum AccountCoinsError {
30    Status500(models::Error),
31    UnknownValue(serde_json::Value),
32}
33
34
35/// Get an array of all AccountBalances for an AccountIdentifier and the BlockIdentifier at which the balance lookup was performed. The BlockIdentifier must always be returned because some consumers of account balance data need to know specifically at which block the balance was calculated to compare balances they compute from operations with the balance returned by the node.  It is important to note that making a balance request for an account without populating the SubAccountIdentifier should not result in the balance of all possible SubAccountIdentifiers being returned. Rather, it should result in the balance pertaining to no SubAccountIdentifiers being returned (sometimes called the liquid balance). To get all balances associated with an account, it may be necessary to perform multiple balance requests with unique AccountIdentifiers.  It is also possible to perform a historical balance lookup (if the server supports it) by passing in an optional BlockIdentifier. 
36pub async fn account_balance(configuration: &configuration::Configuration, account_balance_request: models::AccountBalanceRequest) -> Result<models::AccountBalanceResponse, Error<AccountBalanceError>> {
37    let local_var_configuration = configuration;
38
39    let local_var_client = &local_var_configuration.client;
40
41    let local_var_uri_str = format!("{}/account/balance", local_var_configuration.base_path);
42    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
43
44    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
45        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
46    }
47    local_var_req_builder = local_var_req_builder.json(&account_balance_request);
48
49    let local_var_req = local_var_req_builder.build()?;
50    let local_var_resp = local_var_client.execute(local_var_req).await?;
51
52    let local_var_status = local_var_resp.status();
53    let local_var_content = local_var_resp.text().await?;
54
55    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
56        serde_json::from_str(&local_var_content).map_err(Error::from)
57    } else {
58        let local_var_entity: Option<AccountBalanceError> = serde_json::from_str(&local_var_content).ok();
59        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
60        Err(Error::ResponseError(local_var_error))
61    }
62}
63
64/// Get an array of all unspent coins for an AccountIdentifier and the BlockIdentifier at which the lookup was performed. If your implementation does not support coins (i.e. it is for an account-based blockchain), you do not need to implement this endpoint. If you implementation does support coins (i.e. it is fro a UTXO-based blockchain), you MUST also complete the `/account/balance` endpoint.  It is important to note that making a coins request for an account without populating the SubAccountIdentifier should not result in the coins of all possible SubAccountIdentifiers being returned. Rather, it should result in the coins pertaining to no SubAccountIdentifiers being returned. To get all coins associated with an account, it may be necessary to perform multiple coin requests with unique AccountIdentifiers.  Optionally, an implementation may choose to support updating an AccountIdentifier's unspent coins based on the contents of the mempool. Note, using this functionality breaks any guarantee of idempotency. 
65pub async fn account_coins(configuration: &configuration::Configuration, account_coins_request: models::AccountCoinsRequest) -> Result<models::AccountCoinsResponse, Error<AccountCoinsError>> {
66    let local_var_configuration = configuration;
67
68    let local_var_client = &local_var_configuration.client;
69
70    let local_var_uri_str = format!("{}/account/coins", local_var_configuration.base_path);
71    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
72
73    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
74        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
75    }
76    local_var_req_builder = local_var_req_builder.json(&account_coins_request);
77
78    let local_var_req = local_var_req_builder.build()?;
79    let local_var_resp = local_var_client.execute(local_var_req).await?;
80
81    let local_var_status = local_var_resp.status();
82    let local_var_content = local_var_resp.text().await?;
83
84    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
85        serde_json::from_str(&local_var_content).map_err(Error::from)
86    } else {
87        let local_var_entity: Option<AccountCoinsError> = serde_json::from_str(&local_var_content).ok();
88        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
89        Err(Error::ResponseError(local_var_error))
90    }
91}
92