coinbase_mesh/apis/
construction_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 [`construction_combine`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ConstructionCombineError {
22    Status500(models::Error),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`construction_derive`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum ConstructionDeriveError {
30    Status500(models::Error),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`construction_hash`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum ConstructionHashError {
38    Status500(models::Error),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`construction_metadata`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum ConstructionMetadataError {
46    Status500(models::Error),
47    UnknownValue(serde_json::Value),
48}
49
50/// struct for typed errors of method [`construction_parse`]
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum ConstructionParseError {
54    Status500(models::Error),
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method [`construction_payloads`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum ConstructionPayloadsError {
62    Status500(models::Error),
63    UnknownValue(serde_json::Value),
64}
65
66/// struct for typed errors of method [`construction_preprocess`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum ConstructionPreprocessError {
70    Status500(models::Error),
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method [`construction_submit`]
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum ConstructionSubmitError {
78    Status500(models::Error),
79    UnknownValue(serde_json::Value),
80}
81
82
83/// Combine creates a network-specific transaction from an unsigned transaction and an array of provided signatures.  The signed transaction returned from this method will be sent to the `/construction/submit` endpoint by the caller. 
84pub async fn construction_combine(configuration: &configuration::Configuration, construction_combine_request: models::ConstructionCombineRequest) -> Result<models::ConstructionCombineResponse, Error<ConstructionCombineError>> {
85    let local_var_configuration = configuration;
86
87    let local_var_client = &local_var_configuration.client;
88
89    let local_var_uri_str = format!("{}/construction/combine", local_var_configuration.base_path);
90    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
91
92    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
93        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
94    }
95    local_var_req_builder = local_var_req_builder.json(&construction_combine_request);
96
97    let local_var_req = local_var_req_builder.build()?;
98    let local_var_resp = local_var_client.execute(local_var_req).await?;
99
100    let local_var_status = local_var_resp.status();
101    let local_var_content = local_var_resp.text().await?;
102
103    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
104        serde_json::from_str(&local_var_content).map_err(Error::from)
105    } else {
106        let local_var_entity: Option<ConstructionCombineError> = serde_json::from_str(&local_var_content).ok();
107        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
108        Err(Error::ResponseError(local_var_error))
109    }
110}
111
112/// Derive returns the AccountIdentifier associated with a public key.  Blockchains that require an on-chain action to create an account should not implement this method. 
113pub async fn construction_derive(configuration: &configuration::Configuration, construction_derive_request: models::ConstructionDeriveRequest) -> Result<models::ConstructionDeriveResponse, Error<ConstructionDeriveError>> {
114    let local_var_configuration = configuration;
115
116    let local_var_client = &local_var_configuration.client;
117
118    let local_var_uri_str = format!("{}/construction/derive", local_var_configuration.base_path);
119    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
120
121    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
122        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
123    }
124    local_var_req_builder = local_var_req_builder.json(&construction_derive_request);
125
126    let local_var_req = local_var_req_builder.build()?;
127    let local_var_resp = local_var_client.execute(local_var_req).await?;
128
129    let local_var_status = local_var_resp.status();
130    let local_var_content = local_var_resp.text().await?;
131
132    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
133        serde_json::from_str(&local_var_content).map_err(Error::from)
134    } else {
135        let local_var_entity: Option<ConstructionDeriveError> = serde_json::from_str(&local_var_content).ok();
136        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
137        Err(Error::ResponseError(local_var_error))
138    }
139}
140
141/// TransactionHash returns the network-specific transaction hash for a signed transaction. 
142pub async fn construction_hash(configuration: &configuration::Configuration, construction_hash_request: models::ConstructionHashRequest) -> Result<models::TransactionIdentifierResponse, Error<ConstructionHashError>> {
143    let local_var_configuration = configuration;
144
145    let local_var_client = &local_var_configuration.client;
146
147    let local_var_uri_str = format!("{}/construction/hash", local_var_configuration.base_path);
148    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
149
150    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
151        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
152    }
153    local_var_req_builder = local_var_req_builder.json(&construction_hash_request);
154
155    let local_var_req = local_var_req_builder.build()?;
156    let local_var_resp = local_var_client.execute(local_var_req).await?;
157
158    let local_var_status = local_var_resp.status();
159    let local_var_content = local_var_resp.text().await?;
160
161    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
162        serde_json::from_str(&local_var_content).map_err(Error::from)
163    } else {
164        let local_var_entity: Option<ConstructionHashError> = serde_json::from_str(&local_var_content).ok();
165        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
166        Err(Error::ResponseError(local_var_error))
167    }
168}
169
170/// Get any information required to construct a transaction for a specific network. Metadata returned here could be a recent hash to use, an account sequence number, or even arbitrary chain state. The request used when calling this endpoint is created by calling `/construction/preprocess` in an offline environment.  You should NEVER assume that the request sent to this endpoint will be created by the caller or populated with any custom parameters. This must occur in `/construction/preprocess`.  It is important to clarify that this endpoint should not pre-construct any transactions for the client (this should happen in `/construction/payloads`). This endpoint is left purposely unstructured because of the wide scope of metadata that could be required. 
171pub async fn construction_metadata(configuration: &configuration::Configuration, construction_metadata_request: models::ConstructionMetadataRequest) -> Result<models::ConstructionMetadataResponse, Error<ConstructionMetadataError>> {
172    let local_var_configuration = configuration;
173
174    let local_var_client = &local_var_configuration.client;
175
176    let local_var_uri_str = format!("{}/construction/metadata", local_var_configuration.base_path);
177    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
178
179    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
180        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
181    }
182    local_var_req_builder = local_var_req_builder.json(&construction_metadata_request);
183
184    let local_var_req = local_var_req_builder.build()?;
185    let local_var_resp = local_var_client.execute(local_var_req).await?;
186
187    let local_var_status = local_var_resp.status();
188    let local_var_content = local_var_resp.text().await?;
189
190    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
191        serde_json::from_str(&local_var_content).map_err(Error::from)
192    } else {
193        let local_var_entity: Option<ConstructionMetadataError> = serde_json::from_str(&local_var_content).ok();
194        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
195        Err(Error::ResponseError(local_var_error))
196    }
197}
198
199/// Parse is called on both unsigned and signed transactions to understand the intent of the formulated transaction.  This is run as a sanity check before signing (after `/construction/payloads`) and before broadcast (after `/construction/combine`).  
200pub async fn construction_parse(configuration: &configuration::Configuration, construction_parse_request: models::ConstructionParseRequest) -> Result<models::ConstructionParseResponse, Error<ConstructionParseError>> {
201    let local_var_configuration = configuration;
202
203    let local_var_client = &local_var_configuration.client;
204
205    let local_var_uri_str = format!("{}/construction/parse", local_var_configuration.base_path);
206    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
207
208    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
209        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
210    }
211    local_var_req_builder = local_var_req_builder.json(&construction_parse_request);
212
213    let local_var_req = local_var_req_builder.build()?;
214    let local_var_resp = local_var_client.execute(local_var_req).await?;
215
216    let local_var_status = local_var_resp.status();
217    let local_var_content = local_var_resp.text().await?;
218
219    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
220        serde_json::from_str(&local_var_content).map_err(Error::from)
221    } else {
222        let local_var_entity: Option<ConstructionParseError> = serde_json::from_str(&local_var_content).ok();
223        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
224        Err(Error::ResponseError(local_var_error))
225    }
226}
227
228/// Payloads is called with an array of operations and the response from `/construction/metadata`. It returns an unsigned transaction blob and a collection of payloads that must be signed by particular AccountIdentifiers using a certain SignatureType.  The array of operations provided in transaction construction often times can not specify all \"effects\" of a transaction (consider invoked transactions in Ethereum). However, they can deterministically specify the \"intent\" of the transaction, which is sufficient for construction. For this reason, parsing the corresponding transaction in the Data API (when it lands on chain) will contain a superset of whatever operations were provided during construction. 
229pub async fn construction_payloads(configuration: &configuration::Configuration, construction_payloads_request: models::ConstructionPayloadsRequest) -> Result<models::ConstructionPayloadsResponse, Error<ConstructionPayloadsError>> {
230    let local_var_configuration = configuration;
231
232    let local_var_client = &local_var_configuration.client;
233
234    let local_var_uri_str = format!("{}/construction/payloads", local_var_configuration.base_path);
235    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
236
237    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
238        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
239    }
240    local_var_req_builder = local_var_req_builder.json(&construction_payloads_request);
241
242    let local_var_req = local_var_req_builder.build()?;
243    let local_var_resp = local_var_client.execute(local_var_req).await?;
244
245    let local_var_status = local_var_resp.status();
246    let local_var_content = local_var_resp.text().await?;
247
248    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
249        serde_json::from_str(&local_var_content).map_err(Error::from)
250    } else {
251        let local_var_entity: Option<ConstructionPayloadsError> = serde_json::from_str(&local_var_content).ok();
252        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
253        Err(Error::ResponseError(local_var_error))
254    }
255}
256
257/// Preprocess is called prior to `/construction/payloads` to construct a request for any metadata that is needed for transaction construction given (i.e. account nonce).  The `options` object returned from this endpoint will be sent to the `/construction/metadata` endpoint UNMODIFIED by the caller (in an offline execution environment). If your Construction API implementation has configuration options, they MUST be specified in the `/construction/preprocess` request (in the `metadata` field). 
258pub async fn construction_preprocess(configuration: &configuration::Configuration, construction_preprocess_request: models::ConstructionPreprocessRequest) -> Result<models::ConstructionPreprocessResponse, Error<ConstructionPreprocessError>> {
259    let local_var_configuration = configuration;
260
261    let local_var_client = &local_var_configuration.client;
262
263    let local_var_uri_str = format!("{}/construction/preprocess", local_var_configuration.base_path);
264    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
265
266    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
267        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
268    }
269    local_var_req_builder = local_var_req_builder.json(&construction_preprocess_request);
270
271    let local_var_req = local_var_req_builder.build()?;
272    let local_var_resp = local_var_client.execute(local_var_req).await?;
273
274    let local_var_status = local_var_resp.status();
275    let local_var_content = local_var_resp.text().await?;
276
277    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
278        serde_json::from_str(&local_var_content).map_err(Error::from)
279    } else {
280        let local_var_entity: Option<ConstructionPreprocessError> = serde_json::from_str(&local_var_content).ok();
281        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
282        Err(Error::ResponseError(local_var_error))
283    }
284}
285
286/// Submit a pre-signed transaction to the node. This call should not block on the transaction being included in a block. Rather, it should return immediately with an indication of whether or not the transaction was included in the mempool.  The transaction submission response should only return a 200 status if the submitted transaction could be included in the mempool. Otherwise, it should return an error. 
287pub async fn construction_submit(configuration: &configuration::Configuration, construction_submit_request: models::ConstructionSubmitRequest) -> Result<models::TransactionIdentifierResponse, Error<ConstructionSubmitError>> {
288    let local_var_configuration = configuration;
289
290    let local_var_client = &local_var_configuration.client;
291
292    let local_var_uri_str = format!("{}/construction/submit", local_var_configuration.base_path);
293    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
294
295    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
296        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
297    }
298    local_var_req_builder = local_var_req_builder.json(&construction_submit_request);
299
300    let local_var_req = local_var_req_builder.build()?;
301    let local_var_resp = local_var_client.execute(local_var_req).await?;
302
303    let local_var_status = local_var_resp.status();
304    let local_var_content = local_var_resp.text().await?;
305
306    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
307        serde_json::from_str(&local_var_content).map_err(Error::from)
308    } else {
309        let local_var_entity: Option<ConstructionSubmitError> = serde_json::from_str(&local_var_content).ok();
310        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
311        Err(Error::ResponseError(local_var_error))
312    }
313}
314