Skip to main content

hanzo_client/apis/
validator_api.rs

1/*
2 * Hanzo Cloud API
3 *
4 * The Hanzo Cloud API as a customer calls it: every operation under /v1/ except the operator's admin product, relay routes, legacy spellings and capabilities still reached by flag. Tagged by product: the first path segment after /v1/.
5 *
6 * The version of the OpenAPI document: v1
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`get_validator`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetValidatorError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`get_validator_by_tokenid`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetValidatorByTokenidError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_validator_challenge`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetValidatorChallengeError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`post_validator`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum PostValidatorError {
43    UnknownValue(serde_json::Value),
44}
45
46
47/// Returns the validator slots the caller's org has claimed.  One entry per claimed slot with its node identity, its live-ish node status and the owner-gated registration queued for it, if any. Slots are org-scoped by the validated identity, so a caller can only ever see their own — a slot claimed by another org is not merely hidden from this list, it is unreachable through the whole surface.
48pub async fn get_validator(configuration: &configuration::Configuration, limit: Option<&str>) -> Result<models::ValidatorList, Error<GetValidatorError>> {
49    // add a prefix to parameters to efficiently prevent name collisions
50    let p_limit = limit;
51
52    let uri_str = format!("{}/v1/validator", configuration.base_path);
53    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
54
55    if let Some(ref param_value) = p_limit {
56        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
57    }
58    if let Some(ref user_agent) = configuration.user_agent {
59        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
60    }
61    if let Some(ref token) = configuration.bearer_access_token {
62        req_builder = req_builder.bearer_auth(token.to_owned());
63    };
64
65    let req = req_builder.build()?;
66    let resp = configuration.client.execute(req).await?;
67
68    let status = resp.status();
69    let content_type = resp
70        .headers()
71        .get("content-type")
72        .and_then(|v| v.to_str().ok())
73        .unwrap_or("application/octet-stream");
74    let content_type = super::ContentType::from(content_type);
75
76    if !status.is_client_error() && !status.is_server_error() {
77        let content = resp.text().await?;
78        match content_type {
79            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
80            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ValidatorList`"))),
81            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ValidatorList`")))),
82        }
83    } else {
84        let content = resp.text().await?;
85        let entity: Option<GetValidatorError> = serde_json::from_str(&content).ok();
86        Err(Error::ResponseError(ResponseContent { status, content, entity }))
87    }
88}
89
90/// Returns one claimed validator slot, scoped to the caller's org.  A slot another org holds, and a slot nobody holds, are both 404 — never a different status, so this route cannot be used to probe which slots are taken.
91pub async fn get_validator_by_tokenid(configuration: &configuration::Configuration, token_id: &str) -> Result<models::SlotView, Error<GetValidatorByTokenidError>> {
92    // add a prefix to parameters to efficiently prevent name collisions
93    let p_token_id = token_id;
94
95    let uri_str = format!("{}/v1/validator/{tokenId}", configuration.base_path, tokenId=crate::apis::urlencode(p_token_id));
96    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
97
98    if let Some(ref user_agent) = configuration.user_agent {
99        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
100    }
101    if let Some(ref token) = configuration.bearer_access_token {
102        req_builder = req_builder.bearer_auth(token.to_owned());
103    };
104
105    let req = req_builder.build()?;
106    let resp = configuration.client.execute(req).await?;
107
108    let status = resp.status();
109    let content_type = resp
110        .headers()
111        .get("content-type")
112        .and_then(|v| v.to_str().ok())
113        .unwrap_or("application/octet-stream");
114    let content_type = super::ContentType::from(content_type);
115
116    if !status.is_client_error() && !status.is_server_error() {
117        let content = resp.text().await?;
118        match content_type {
119            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
120            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SlotView`"))),
121            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SlotView`")))),
122        }
123    } else {
124        let content = resp.text().await?;
125        let entity: Option<GetValidatorByTokenidError> = serde_json::from_str(&content).ok();
126        Err(Error::ResponseError(ResponseContent { status, content, entity }))
127    }
128}
129
130/// Issues the single-use nonce and the exact message a wallet must sign to claim a validator slot.  The nonce is bound to (validated org, slot) and stored server-side, so a signature obtained for one org or one slot can never be replayed for another, and the message POST /v1/validator verifies is rebuilt from those same server facts rather than trusted from the caller. Redeem it with POST /v1/validator before it expires; it can be redeemed once.  A tokenId outside the Validator tier is refused here rather than after signing.
131pub async fn get_validator_challenge(configuration: &configuration::Configuration, token_id: Option<&str>) -> Result<models::ChallengeView, Error<GetValidatorChallengeError>> {
132    // add a prefix to parameters to efficiently prevent name collisions
133    let p_token_id = token_id;
134
135    let uri_str = format!("{}/v1/validator/challenge", configuration.base_path);
136    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
137
138    if let Some(ref param_value) = p_token_id {
139        req_builder = req_builder.query(&[("tokenId", &param_value.to_string())]);
140    }
141    if let Some(ref user_agent) = configuration.user_agent {
142        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
143    }
144    if let Some(ref token) = configuration.bearer_access_token {
145        req_builder = req_builder.bearer_auth(token.to_owned());
146    };
147
148    let req = req_builder.build()?;
149    let resp = configuration.client.execute(req).await?;
150
151    let status = resp.status();
152    let content_type = resp
153        .headers()
154        .get("content-type")
155        .and_then(|v| v.to_str().ok())
156        .unwrap_or("application/octet-stream");
157    let content_type = super::ContentType::from(content_type);
158
159    if !status.is_client_error() && !status.is_server_error() {
160        let content = resp.text().await?;
161        match content_type {
162            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
163            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ChallengeView`"))),
164            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ChallengeView`")))),
165        }
166    } else {
167        let content = resp.text().await?;
168        let entity: Option<GetValidatorChallengeError> = serde_json::from_str(&content).ok();
169        Err(Error::ResponseError(ResponseContent { status, content, entity }))
170    }
171}
172
173/// Claims a validator slot and provisions its node, after proving the caller's wallet owns the slot's NFT.  The pipeline, all server-enforced: burn the single-use challenge (so a replayed or forged nonce dies before any chain read), recover the signer from the message this server rebuilds, require that wallet to hold Validator-tier GenesisNFT #tokenId on Ethereum mainnet, generate a fresh luxd staking identity and seal it into KMS, write a LuxNetwork CR for a NEW node, and ENQUEUE an owner-gated registration. The registration is never auto-submitted to any P-Chain — the owner co-signs it out of band — and the stake weight is set at co-sign time, never derived from the NFT.  It fails CLOSED at every gate: a bad signature, a non-owner, a non-tier slot or an unavailable KMS all leave no claim persisted and no key material exposed. Re-claiming a slot this org already holds re-applies the node CR and returns 200 with the existing identity (keys and NodeID are stable); a slot held by another org is 409. A cluster-less deployment still claims the slot, seals the keys and queues the registration, reporting the node as \"node_pending\".
174pub async fn post_validator(configuration: &configuration::Configuration, validator_claim: models::ValidatorClaim) -> Result<models::SlotView, Error<PostValidatorError>> {
175    // add a prefix to parameters to efficiently prevent name collisions
176    let p_validator_claim = validator_claim;
177
178    let uri_str = format!("{}/v1/validator", configuration.base_path);
179    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
180
181    if let Some(ref user_agent) = configuration.user_agent {
182        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
183    }
184    if let Some(ref token) = configuration.bearer_access_token {
185        req_builder = req_builder.bearer_auth(token.to_owned());
186    };
187    req_builder = req_builder.json(&p_validator_claim);
188
189    let req = req_builder.build()?;
190    let resp = configuration.client.execute(req).await?;
191
192    let status = resp.status();
193    let content_type = resp
194        .headers()
195        .get("content-type")
196        .and_then(|v| v.to_str().ok())
197        .unwrap_or("application/octet-stream");
198    let content_type = super::ContentType::from(content_type);
199
200    if !status.is_client_error() && !status.is_server_error() {
201        let content = resp.text().await?;
202        match content_type {
203            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
204            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SlotView`"))),
205            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SlotView`")))),
206        }
207    } else {
208        let content = resp.text().await?;
209        let entity: Option<PostValidatorError> = serde_json::from_str(&content).ok();
210        Err(Error::ResponseError(ResponseContent { status, content, entity }))
211    }
212}
213