aptos_client_icp/apis/
events_api.rs1use super::{configuration, Error};
12use crate::{apis::ResponseContent, models};
13use serde::{Deserialize, Serialize};
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
17#[serde(untagged)]
18pub enum GetEventsByCreationNumberError {
19 Status400(models::AptosError),
20 Status403(models::AptosError),
21 Status404(models::AptosError),
22 Status410(models::AptosError),
23 Status500(models::AptosError),
24 Status503(models::AptosError),
25 UnknownValue(serde_json::Value),
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum GetEventsByEventHandleError {
32 Status400(models::AptosError),
33 Status403(models::AptosError),
34 Status404(models::AptosError),
35 Status410(models::AptosError),
36 Status500(models::AptosError),
37 Status503(models::AptosError),
38 UnknownValue(serde_json::Value),
39}
40
41pub async fn get_events_by_creation_number(
43 configuration: &configuration::Configuration,
44 address: &str,
45 creation_number: &str,
46 start: Option<&str>,
47 limit: Option<i32>,
48) -> Result<Vec<models::VersionedEvent>, Error<GetEventsByCreationNumberError>> {
49 let local_var_configuration = configuration;
50
51 let local_var_client = &local_var_configuration.client;
52
53 let local_var_uri_str = format!(
54 "{}/accounts/{address}/events/{creation_number}",
55 local_var_configuration.base_path,
56 address = crate::apis::urlencode(address),
57 creation_number = crate::apis::urlencode(creation_number)
58 );
59 let mut local_var_req_builder =
60 local_var_client.request(crate::http::HttpMethod::GET, local_var_uri_str.as_str());
61
62 if let Some(ref local_var_str) = start {
63 local_var_req_builder =
64 local_var_req_builder.query(&[("start", &local_var_str.to_string())]);
65 }
66 if let Some(ref local_var_str) = limit {
67 local_var_req_builder =
68 local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
69 }
70 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
71 local_var_req_builder =
72 local_var_req_builder.header("User-Agent".to_string(), local_var_user_agent.clone());
73 }
74
75 let local_var_req = local_var_req_builder.build()?;
76 let local_var_resp = local_var_client.execute(local_var_req).await?;
77
78 let local_var_status = local_var_resp.status();
79 let local_var_content = local_var_resp.text().await?;
80
81 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
82 serde_json::from_str(&local_var_content).map_err(Error::from)
83 } else {
84 let local_var_entity: Option<GetEventsByCreationNumberError> =
85 serde_json::from_str(&local_var_content).ok();
86 let local_var_error = ResponseContent {
87 status: local_var_status,
88 content: local_var_content,
89 entity: local_var_entity,
90 };
91 Err(Error::ResponseError(local_var_error))
92 }
93}
94
95pub async fn get_events_by_event_handle(
97 configuration: &configuration::Configuration,
98 address: &str,
99 event_handle: &str,
100 field_name: &str,
101 start: Option<&str>,
102 limit: Option<i32>,
103) -> Result<Vec<models::VersionedEvent>, Error<GetEventsByEventHandleError>> {
104 let local_var_configuration = configuration;
105
106 let local_var_client = &local_var_configuration.client;
107
108 let local_var_uri_str = format!(
109 "{}/accounts/{address}/events/{event_handle}/{field_name}",
110 local_var_configuration.base_path,
111 address = crate::apis::urlencode(address),
112 event_handle = crate::apis::urlencode(event_handle),
113 field_name = crate::apis::urlencode(field_name)
114 );
115 let mut local_var_req_builder =
116 local_var_client.request(crate::http::HttpMethod::GET, local_var_uri_str.as_str());
117
118 if let Some(ref local_var_str) = start {
119 local_var_req_builder =
120 local_var_req_builder.query(&[("start", &local_var_str.to_string())]);
121 }
122 if let Some(ref local_var_str) = limit {
123 local_var_req_builder =
124 local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
125 }
126 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
127 local_var_req_builder =
128 local_var_req_builder.header("User-Agent".to_string(), local_var_user_agent.clone());
129 }
130
131 let local_var_req = local_var_req_builder.build()?;
132 let local_var_resp = local_var_client.execute(local_var_req).await?;
133
134 let local_var_status = local_var_resp.status();
135 let local_var_content = local_var_resp.text().await?;
136
137 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
138 serde_json::from_str(&local_var_content).map_err(Error::from)
139 } else {
140 let local_var_entity: Option<GetEventsByEventHandleError> =
141 serde_json::from_str(&local_var_content).ok();
142 let local_var_error = ResponseContent {
143 status: local_var_status,
144 content: local_var_content,
145 entity: local_var_entity,
146 };
147 Err(Error::ResponseError(local_var_error))
148 }
149}