proto_blue_api/generated/tools/ozone/hosting/
getAccountHistory.rs1use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
7#[serde(rename_all = "camelCase")]
8pub struct AccountCreated {
9 #[serde(skip_serializing_if = "Option::is_none")]
10 pub email: Option<String>,
11 #[serde(skip_serializing_if = "Option::is_none")]
12 pub handle: Option<String>,
13}
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
16#[serde(rename_all = "camelCase")]
17pub struct EmailConfirmed {
18 pub email: String,
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
22#[serde(rename_all = "camelCase")]
23pub struct EmailUpdated {
24 pub email: String,
25}
26
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(rename_all = "camelCase")]
29pub struct Event {
30 pub created_at: String,
31 pub created_by: String,
32 pub details: serde_json::Value,
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(rename_all = "camelCase")]
37pub struct HandleUpdated {
38 pub handle: String,
39}
40
41#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(rename_all = "camelCase")]
45pub struct Params {
46 #[serde(skip_serializing_if = "Option::is_none")]
47 pub cursor: Option<String>,
48 pub did: String,
49 #[serde(skip_serializing_if = "Option::is_none")]
50 pub events: Option<Vec<String>>,
51 #[serde(skip_serializing_if = "Option::is_none")]
52 pub limit: Option<i64>,
53}
54
55#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(rename_all = "camelCase")]
57pub struct Output {
58 #[serde(skip_serializing_if = "Option::is_none")]
59 pub cursor: Option<String>,
60 pub events: Vec<Event>,
61}
62
63#[derive(Debug, thiserror::Error)]
65pub enum CallError {
66 #[error("{0}")]
67 Xrpc(proto_blue_xrpc::XrpcError),
68 #[error(transparent)]
69 Transport(#[from] proto_blue_xrpc::Error),
70 #[error(transparent)]
71 Json(#[from] serde_json::Error),
72}
73
74fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
75 CallError::Xrpc(err)
76}
77
78fn to_query_params(p: &Params) -> proto_blue_xrpc::QueryParams {
79 let mut qp = proto_blue_xrpc::QueryParams::new();
80 if let Some(v) = &p.cursor { qp.insert("cursor".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
81 { let v = &p.did; qp.insert("did".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
82 if let Some(v) = &p.events { qp.insert("events".to_string(), proto_blue_xrpc::QueryValue::Array(v.iter().map(|x| proto_blue_xrpc::QueryValue::String(x.clone())).collect())); }
83 if let Some(v) = &p.limit { qp.insert("limit".to_string(), proto_blue_xrpc::QueryValue::Integer(*v)); }
84 qp
85}
86
87pub async fn call(
89 client: &proto_blue_xrpc::XrpcClient,
90 params: Option<&Params>,
91 opts: Option<&proto_blue_xrpc::CallOptions>,
92) -> Result<Output, CallError> {
93 let qp = params.map(to_query_params);
94 let response = match client.query("tools.ozone.hosting.getAccountHistory", qp.as_ref(), opts).await {
95 Ok(r) => r,
96 Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
97 Err(e) => return Err(CallError::Transport(e)),
98 };
99 Ok(serde_json::from_value(response.data)?)
100}
101
102#[cfg(feature = "server")]
104pub fn register<F, Fut>(
105server: proto_blue_xrpc::XrpcServer,
106handler: F,
107) -> proto_blue_xrpc::XrpcServer
108where
109 F: Fn(proto_blue_xrpc::HandlerContext, Option<Params>) -> Fut + Send + Sync + 'static,
110 Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>> + Send + 'static,
111{
112 let handler = std::sync::Arc::new(handler);
113 server.query("tools.ozone.hosting.getAccountHistory", move |ctx| {
114 let handler = handler.clone();
115 async move {
116 let params = params_from_ctx(&ctx);
117 let out = handler(ctx, params).await?;
118 let value = serde_json::to_value(&out)
119 .map_err(|e| proto_blue_xrpc::XrpcServerError::new(proto_blue_xrpc::ResponseType::InternalServerError, format!("output serialize: {e}")))?;
120 Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
121 }
122 })
123}
124
125#[cfg(feature = "server")]
126fn params_from_ctx(ctx: &proto_blue_xrpc::HandlerContext) -> Option<Params> {
127 Some(Params {
131 cursor: ctx.params.get("cursor").cloned(),
132 did: (ctx.params.get("did").cloned())?,
133 events: Some(ctx.params.get("events").map(|v| v.split(',').map(String::from).collect::<Vec<_>>()).unwrap_or_default()),
134 limit: ctx.params.get("limit").and_then(|v| v.parse::<i64>().ok()),
135 })
136}
137
138#[derive(Debug, Clone, Serialize, Deserialize)]
139#[serde(rename_all = "camelCase")]
140pub struct PasswordUpdated {
141}
142