1use {
10 super::{configuration, Error},
11 crate::{
12 apis::{ContentType, ResponseContent},
13 models,
14 },
15 async_trait::async_trait,
16 reqwest,
17 serde::{de::Error as _, Deserialize, Serialize},
18 std::sync::Arc,
19};
20
21#[async_trait]
22pub trait StakingApi: Send + Sync {
23 async fn approve_terms_of_service_by_provider_id(
30 &self,
31 params: ApproveTermsOfServiceByProviderIdParams,
32 ) -> Result<(), Error<ApproveTermsOfServiceByProviderIdError>>;
33
34 async fn claim_rewards(
38 &self,
39 params: ClaimRewardsParams,
40 ) -> Result<(), Error<ClaimRewardsError>>;
41
42 async fn get_all_delegations(
48 &self,
49 params: GetAllDelegationsParams,
50 ) -> Result<Vec<models::Delegation>, Error<GetAllDelegationsError>>;
51
52 async fn get_chain_info(
58 &self,
59 params: GetChainInfoParams,
60 ) -> Result<models::ChainInfoResponse, Error<GetChainInfoError>>;
61
62 async fn get_chains(&self) -> Result<Vec<models::ChainDescriptor>, Error<GetChainsError>>;
67
68 async fn get_delegation_by_id(
74 &self,
75 params: GetDelegationByIdParams,
76 ) -> Result<models::Delegation, Error<GetDelegationByIdError>>;
77
78 async fn get_providers(&self) -> Result<Vec<models::Provider>, Error<GetProvidersError>>;
83
84 async fn get_summary(&self) -> Result<models::DelegationSummary, Error<GetSummaryError>>;
91
92 async fn get_summary_by_vault(
99 &self,
100 ) -> Result<
101 std::collections::HashMap<String, models::DelegationSummary>,
102 Error<GetSummaryByVaultError>,
103 >;
104
105 async fn split(&self, params: SplitParams) -> Result<models::SplitResponse, Error<SplitError>>;
109
110 async fn stake(&self, params: StakeParams) -> Result<models::StakeResponse, Error<StakeError>>;
114
115 async fn unstake(&self, params: UnstakeParams) -> Result<(), Error<UnstakeError>>;
119
120 async fn withdraw(&self, params: WithdrawParams) -> Result<(), Error<WithdrawError>>;
124}
125
126pub struct StakingApiClient {
127 configuration: Arc<configuration::Configuration>,
128}
129
130impl StakingApiClient {
131 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
132 Self { configuration }
133 }
134}
135
136#[derive(Clone, Debug)]
139#[cfg_attr(feature = "bon", derive(::bon::Builder))]
140pub struct ApproveTermsOfServiceByProviderIdParams {
141 pub provider_id: models::StakingProvider,
143 pub idempotency_key: Option<String>,
148}
149
150#[derive(Clone, Debug)]
152#[cfg_attr(feature = "bon", derive(::bon::Builder))]
153pub struct ClaimRewardsParams {
154 pub chain_descriptor: String,
156 pub claim_rewards_request: models::ClaimRewardsRequest,
157 pub idempotency_key: Option<String>,
162}
163
164#[derive(Clone, Debug)]
166#[cfg_attr(feature = "bon", derive(::bon::Builder))]
167pub struct GetAllDelegationsParams {
168 pub chain_descriptor: Option<models::ChainDescriptor>,
173}
174
175#[derive(Clone, Debug)]
177#[cfg_attr(feature = "bon", derive(::bon::Builder))]
178pub struct GetChainInfoParams {
179 pub chain_descriptor: models::ChainDescriptor,
182}
183
184#[derive(Clone, Debug)]
186#[cfg_attr(feature = "bon", derive(::bon::Builder))]
187pub struct GetDelegationByIdParams {
188 pub id: String,
190}
191
192#[derive(Clone, Debug)]
194#[cfg_attr(feature = "bon", derive(::bon::Builder))]
195pub struct SplitParams {
196 pub chain_descriptor: String,
198 pub split_request: models::SplitRequest,
199 pub idempotency_key: Option<String>,
204}
205
206#[derive(Clone, Debug)]
208#[cfg_attr(feature = "bon", derive(::bon::Builder))]
209pub struct StakeParams {
210 pub chain_descriptor: models::ChainDescriptor,
212 pub stake_request: models::StakeRequest,
213 pub idempotency_key: Option<String>,
218}
219
220#[derive(Clone, Debug)]
222#[cfg_attr(feature = "bon", derive(::bon::Builder))]
223pub struct UnstakeParams {
224 pub chain_descriptor: models::ChainDescriptor,
226 pub unstake_request: models::UnstakeRequest,
227 pub idempotency_key: Option<String>,
232}
233
234#[derive(Clone, Debug)]
236#[cfg_attr(feature = "bon", derive(::bon::Builder))]
237pub struct WithdrawParams {
238 pub chain_descriptor: models::ChainDescriptor,
240 pub withdraw_request: models::WithdrawRequest,
241 pub idempotency_key: Option<String>,
246}
247
248#[async_trait]
249impl StakingApi for StakingApiClient {
250 async fn approve_terms_of_service_by_provider_id(
255 &self,
256 params: ApproveTermsOfServiceByProviderIdParams,
257 ) -> Result<(), Error<ApproveTermsOfServiceByProviderIdError>> {
258 let ApproveTermsOfServiceByProviderIdParams {
259 provider_id,
260 idempotency_key,
261 } = params;
262
263 let local_var_configuration = &self.configuration;
264
265 let local_var_client = &local_var_configuration.client;
266
267 let local_var_uri_str = format!(
268 "{}/staking/providers/{providerId}/approveTermsOfService",
269 local_var_configuration.base_path,
270 providerId = provider_id.to_string()
271 );
272 let mut local_var_req_builder =
273 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
274
275 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
276 local_var_req_builder = local_var_req_builder
277 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
278 }
279 if let Some(local_var_param_value) = idempotency_key {
280 local_var_req_builder =
281 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
282 }
283
284 let local_var_req = local_var_req_builder.build()?;
285 let local_var_resp = local_var_client.execute(local_var_req).await?;
286
287 let local_var_status = local_var_resp.status();
288 let local_var_content = local_var_resp.text().await?;
289
290 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
291 Ok(())
292 } else {
293 let local_var_entity: Option<ApproveTermsOfServiceByProviderIdError> =
294 serde_json::from_str(&local_var_content).ok();
295 let local_var_error = ResponseContent {
296 status: local_var_status,
297 content: local_var_content,
298 entity: local_var_entity,
299 };
300 Err(Error::ResponseError(local_var_error))
301 }
302 }
303
304 async fn claim_rewards(
306 &self,
307 params: ClaimRewardsParams,
308 ) -> Result<(), Error<ClaimRewardsError>> {
309 let ClaimRewardsParams {
310 chain_descriptor,
311 claim_rewards_request,
312 idempotency_key,
313 } = params;
314
315 let local_var_configuration = &self.configuration;
316
317 let local_var_client = &local_var_configuration.client;
318
319 let local_var_uri_str = format!(
320 "{}/staking/chains/{chainDescriptor}/claim_rewards",
321 local_var_configuration.base_path,
322 chainDescriptor = crate::apis::urlencode(chain_descriptor)
323 );
324 let mut local_var_req_builder =
325 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
326
327 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
328 local_var_req_builder = local_var_req_builder
329 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
330 }
331 if let Some(local_var_param_value) = idempotency_key {
332 local_var_req_builder =
333 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
334 }
335 local_var_req_builder = local_var_req_builder.json(&claim_rewards_request);
336
337 let local_var_req = local_var_req_builder.build()?;
338 let local_var_resp = local_var_client.execute(local_var_req).await?;
339
340 let local_var_status = local_var_resp.status();
341 let local_var_content = local_var_resp.text().await?;
342
343 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
344 Ok(())
345 } else {
346 let local_var_entity: Option<ClaimRewardsError> =
347 serde_json::from_str(&local_var_content).ok();
348 let local_var_error = ResponseContent {
349 status: local_var_status,
350 content: local_var_content,
351 entity: local_var_entity,
352 };
353 Err(Error::ResponseError(local_var_error))
354 }
355 }
356
357 async fn get_all_delegations(
361 &self,
362 params: GetAllDelegationsParams,
363 ) -> Result<Vec<models::Delegation>, Error<GetAllDelegationsError>> {
364 let GetAllDelegationsParams { chain_descriptor } = params;
365
366 let local_var_configuration = &self.configuration;
367
368 let local_var_client = &local_var_configuration.client;
369
370 let local_var_uri_str = format!("{}/staking/positions", local_var_configuration.base_path);
371 let mut local_var_req_builder =
372 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
373
374 if let Some(ref local_var_str) = chain_descriptor {
375 local_var_req_builder =
376 local_var_req_builder.query(&[("chainDescriptor", &local_var_str.to_string())]);
377 }
378 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
379 local_var_req_builder = local_var_req_builder
380 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
381 }
382
383 let local_var_req = local_var_req_builder.build()?;
384 let local_var_resp = local_var_client.execute(local_var_req).await?;
385
386 let local_var_status = local_var_resp.status();
387 let local_var_content_type = local_var_resp
388 .headers()
389 .get("content-type")
390 .and_then(|v| v.to_str().ok())
391 .unwrap_or("application/octet-stream");
392 let local_var_content_type = super::ContentType::from(local_var_content_type);
393 let local_var_content = local_var_resp.text().await?;
394
395 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
396 match local_var_content_type {
397 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
398 ContentType::Text => {
399 return Err(Error::from(serde_json::Error::custom(
400 "Received `text/plain` content type response that cannot be converted to \
401 `Vec<models::Delegation>`",
402 )))
403 }
404 ContentType::Unsupported(local_var_unknown_type) => {
405 return Err(Error::from(serde_json::Error::custom(format!(
406 "Received `{local_var_unknown_type}` content type response that cannot be \
407 converted to `Vec<models::Delegation>`"
408 ))))
409 }
410 }
411 } else {
412 let local_var_entity: Option<GetAllDelegationsError> =
413 serde_json::from_str(&local_var_content).ok();
414 let local_var_error = ResponseContent {
415 status: local_var_status,
416 content: local_var_content,
417 entity: local_var_entity,
418 };
419 Err(Error::ResponseError(local_var_error))
420 }
421 }
422
423 async fn get_chain_info(
427 &self,
428 params: GetChainInfoParams,
429 ) -> Result<models::ChainInfoResponse, Error<GetChainInfoError>> {
430 let GetChainInfoParams { chain_descriptor } = params;
431
432 let local_var_configuration = &self.configuration;
433
434 let local_var_client = &local_var_configuration.client;
435
436 let local_var_uri_str = format!(
437 "{}/staking/chains/{chainDescriptor}/chainInfo",
438 local_var_configuration.base_path,
439 chainDescriptor = chain_descriptor.to_string()
440 );
441 let mut local_var_req_builder =
442 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
443
444 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
445 local_var_req_builder = local_var_req_builder
446 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
447 }
448
449 let local_var_req = local_var_req_builder.build()?;
450 let local_var_resp = local_var_client.execute(local_var_req).await?;
451
452 let local_var_status = local_var_resp.status();
453 let local_var_content_type = local_var_resp
454 .headers()
455 .get("content-type")
456 .and_then(|v| v.to_str().ok())
457 .unwrap_or("application/octet-stream");
458 let local_var_content_type = super::ContentType::from(local_var_content_type);
459 let local_var_content = local_var_resp.text().await?;
460
461 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
462 match local_var_content_type {
463 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
464 ContentType::Text => {
465 return Err(Error::from(serde_json::Error::custom(
466 "Received `text/plain` content type response that cannot be converted to \
467 `models::ChainInfoResponse`",
468 )))
469 }
470 ContentType::Unsupported(local_var_unknown_type) => {
471 return Err(Error::from(serde_json::Error::custom(format!(
472 "Received `{local_var_unknown_type}` content type response that cannot be \
473 converted to `models::ChainInfoResponse`"
474 ))))
475 }
476 }
477 } else {
478 let local_var_entity: Option<GetChainInfoError> =
479 serde_json::from_str(&local_var_content).ok();
480 let local_var_error = ResponseContent {
481 status: local_var_status,
482 content: local_var_content,
483 entity: local_var_entity,
484 };
485 Err(Error::ResponseError(local_var_error))
486 }
487 }
488
489 async fn get_chains(&self) -> Result<Vec<models::ChainDescriptor>, Error<GetChainsError>> {
492 let local_var_configuration = &self.configuration;
493
494 let local_var_client = &local_var_configuration.client;
495
496 let local_var_uri_str = format!("{}/staking/chains", local_var_configuration.base_path);
497 let mut local_var_req_builder =
498 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
499
500 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
501 local_var_req_builder = local_var_req_builder
502 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
503 }
504
505 let local_var_req = local_var_req_builder.build()?;
506 let local_var_resp = local_var_client.execute(local_var_req).await?;
507
508 let local_var_status = local_var_resp.status();
509 let local_var_content_type = local_var_resp
510 .headers()
511 .get("content-type")
512 .and_then(|v| v.to_str().ok())
513 .unwrap_or("application/octet-stream");
514 let local_var_content_type = super::ContentType::from(local_var_content_type);
515 let local_var_content = local_var_resp.text().await?;
516
517 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
518 match local_var_content_type {
519 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
520 ContentType::Text => {
521 return Err(Error::from(serde_json::Error::custom(
522 "Received `text/plain` content type response that cannot be converted to \
523 `Vec<models::ChainDescriptor>`",
524 )))
525 }
526 ContentType::Unsupported(local_var_unknown_type) => {
527 return Err(Error::from(serde_json::Error::custom(format!(
528 "Received `{local_var_unknown_type}` content type response that cannot be \
529 converted to `Vec<models::ChainDescriptor>`"
530 ))))
531 }
532 }
533 } else {
534 let local_var_entity: Option<GetChainsError> =
535 serde_json::from_str(&local_var_content).ok();
536 let local_var_error = ResponseContent {
537 status: local_var_status,
538 content: local_var_content,
539 entity: local_var_entity,
540 };
541 Err(Error::ResponseError(local_var_error))
542 }
543 }
544
545 async fn get_delegation_by_id(
549 &self,
550 params: GetDelegationByIdParams,
551 ) -> Result<models::Delegation, Error<GetDelegationByIdError>> {
552 let GetDelegationByIdParams { id } = params;
553
554 let local_var_configuration = &self.configuration;
555
556 let local_var_client = &local_var_configuration.client;
557
558 let local_var_uri_str = format!(
559 "{}/staking/positions/{id}",
560 local_var_configuration.base_path,
561 id = crate::apis::urlencode(id)
562 );
563 let mut local_var_req_builder =
564 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
565
566 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
567 local_var_req_builder = local_var_req_builder
568 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
569 }
570
571 let local_var_req = local_var_req_builder.build()?;
572 let local_var_resp = local_var_client.execute(local_var_req).await?;
573
574 let local_var_status = local_var_resp.status();
575 let local_var_content_type = local_var_resp
576 .headers()
577 .get("content-type")
578 .and_then(|v| v.to_str().ok())
579 .unwrap_or("application/octet-stream");
580 let local_var_content_type = super::ContentType::from(local_var_content_type);
581 let local_var_content = local_var_resp.text().await?;
582
583 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
584 match local_var_content_type {
585 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
586 ContentType::Text => {
587 return Err(Error::from(serde_json::Error::custom(
588 "Received `text/plain` content type response that cannot be converted to \
589 `models::Delegation`",
590 )))
591 }
592 ContentType::Unsupported(local_var_unknown_type) => {
593 return Err(Error::from(serde_json::Error::custom(format!(
594 "Received `{local_var_unknown_type}` content type response that cannot be \
595 converted to `models::Delegation`"
596 ))))
597 }
598 }
599 } else {
600 let local_var_entity: Option<GetDelegationByIdError> =
601 serde_json::from_str(&local_var_content).ok();
602 let local_var_error = ResponseContent {
603 status: local_var_status,
604 content: local_var_content,
605 entity: local_var_entity,
606 };
607 Err(Error::ResponseError(local_var_error))
608 }
609 }
610
611 async fn get_providers(&self) -> Result<Vec<models::Provider>, Error<GetProvidersError>> {
614 let local_var_configuration = &self.configuration;
615
616 let local_var_client = &local_var_configuration.client;
617
618 let local_var_uri_str = format!("{}/staking/providers", local_var_configuration.base_path);
619 let mut local_var_req_builder =
620 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
621
622 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
623 local_var_req_builder = local_var_req_builder
624 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
625 }
626
627 let local_var_req = local_var_req_builder.build()?;
628 let local_var_resp = local_var_client.execute(local_var_req).await?;
629
630 let local_var_status = local_var_resp.status();
631 let local_var_content_type = local_var_resp
632 .headers()
633 .get("content-type")
634 .and_then(|v| v.to_str().ok())
635 .unwrap_or("application/octet-stream");
636 let local_var_content_type = super::ContentType::from(local_var_content_type);
637 let local_var_content = local_var_resp.text().await?;
638
639 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
640 match local_var_content_type {
641 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
642 ContentType::Text => {
643 return Err(Error::from(serde_json::Error::custom(
644 "Received `text/plain` content type response that cannot be converted to \
645 `Vec<models::Provider>`",
646 )))
647 }
648 ContentType::Unsupported(local_var_unknown_type) => {
649 return Err(Error::from(serde_json::Error::custom(format!(
650 "Received `{local_var_unknown_type}` content type response that cannot be \
651 converted to `Vec<models::Provider>`"
652 ))))
653 }
654 }
655 } else {
656 let local_var_entity: Option<GetProvidersError> =
657 serde_json::from_str(&local_var_content).ok();
658 let local_var_error = ResponseContent {
659 status: local_var_status,
660 content: local_var_content,
661 entity: local_var_entity,
662 };
663 Err(Error::ResponseError(local_var_error))
664 }
665 }
666
667 async fn get_summary(&self) -> Result<models::DelegationSummary, Error<GetSummaryError>> {
672 let local_var_configuration = &self.configuration;
673
674 let local_var_client = &local_var_configuration.client;
675
676 let local_var_uri_str = format!(
677 "{}/staking/positions/summary",
678 local_var_configuration.base_path
679 );
680 let mut local_var_req_builder =
681 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
682
683 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
684 local_var_req_builder = local_var_req_builder
685 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
686 }
687
688 let local_var_req = local_var_req_builder.build()?;
689 let local_var_resp = local_var_client.execute(local_var_req).await?;
690
691 let local_var_status = local_var_resp.status();
692 let local_var_content_type = local_var_resp
693 .headers()
694 .get("content-type")
695 .and_then(|v| v.to_str().ok())
696 .unwrap_or("application/octet-stream");
697 let local_var_content_type = super::ContentType::from(local_var_content_type);
698 let local_var_content = local_var_resp.text().await?;
699
700 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
701 match local_var_content_type {
702 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
703 ContentType::Text => {
704 return Err(Error::from(serde_json::Error::custom(
705 "Received `text/plain` content type response that cannot be converted to \
706 `models::DelegationSummary`",
707 )))
708 }
709 ContentType::Unsupported(local_var_unknown_type) => {
710 return Err(Error::from(serde_json::Error::custom(format!(
711 "Received `{local_var_unknown_type}` content type response that cannot be \
712 converted to `models::DelegationSummary`"
713 ))))
714 }
715 }
716 } else {
717 let local_var_entity: Option<GetSummaryError> =
718 serde_json::from_str(&local_var_content).ok();
719 let local_var_error = ResponseContent {
720 status: local_var_status,
721 content: local_var_content,
722 entity: local_var_entity,
723 };
724 Err(Error::ResponseError(local_var_error))
725 }
726 }
727
728 async fn get_summary_by_vault(
733 &self,
734 ) -> Result<
735 std::collections::HashMap<String, models::DelegationSummary>,
736 Error<GetSummaryByVaultError>,
737 > {
738 let local_var_configuration = &self.configuration;
739
740 let local_var_client = &local_var_configuration.client;
741
742 let local_var_uri_str = format!(
743 "{}/staking/positions/summary/vaults",
744 local_var_configuration.base_path
745 );
746 let mut local_var_req_builder =
747 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
748
749 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
750 local_var_req_builder = local_var_req_builder
751 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
752 }
753
754 let local_var_req = local_var_req_builder.build()?;
755 let local_var_resp = local_var_client.execute(local_var_req).await?;
756
757 let local_var_status = local_var_resp.status();
758 let local_var_content_type = local_var_resp
759 .headers()
760 .get("content-type")
761 .and_then(|v| v.to_str().ok())
762 .unwrap_or("application/octet-stream");
763 let local_var_content_type = super::ContentType::from(local_var_content_type);
764 let local_var_content = local_var_resp.text().await?;
765
766 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
767 match local_var_content_type {
768 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
769 ContentType::Text => {
770 return Err(Error::from(serde_json::Error::custom(
771 "Received `text/plain` content type response that cannot be converted to \
772 `std::collections::HashMap<String, models::DelegationSummary>`",
773 )))
774 }
775 ContentType::Unsupported(local_var_unknown_type) => {
776 return Err(Error::from(serde_json::Error::custom(format!(
777 "Received `{local_var_unknown_type}` content type response that cannot be \
778 converted to `std::collections::HashMap<String, \
779 models::DelegationSummary>`"
780 ))))
781 }
782 }
783 } else {
784 let local_var_entity: Option<GetSummaryByVaultError> =
785 serde_json::from_str(&local_var_content).ok();
786 let local_var_error = ResponseContent {
787 status: local_var_status,
788 content: local_var_content,
789 entity: local_var_entity,
790 };
791 Err(Error::ResponseError(local_var_error))
792 }
793 }
794
795 async fn split(&self, params: SplitParams) -> Result<models::SplitResponse, Error<SplitError>> {
797 let SplitParams {
798 chain_descriptor,
799 split_request,
800 idempotency_key,
801 } = params;
802
803 let local_var_configuration = &self.configuration;
804
805 let local_var_client = &local_var_configuration.client;
806
807 let local_var_uri_str = format!(
808 "{}/staking/chains/{chainDescriptor}/split",
809 local_var_configuration.base_path,
810 chainDescriptor = crate::apis::urlencode(chain_descriptor)
811 );
812 let mut local_var_req_builder =
813 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
814
815 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
816 local_var_req_builder = local_var_req_builder
817 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
818 }
819 if let Some(local_var_param_value) = idempotency_key {
820 local_var_req_builder =
821 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
822 }
823 local_var_req_builder = local_var_req_builder.json(&split_request);
824
825 let local_var_req = local_var_req_builder.build()?;
826 let local_var_resp = local_var_client.execute(local_var_req).await?;
827
828 let local_var_status = local_var_resp.status();
829 let local_var_content_type = local_var_resp
830 .headers()
831 .get("content-type")
832 .and_then(|v| v.to_str().ok())
833 .unwrap_or("application/octet-stream");
834 let local_var_content_type = super::ContentType::from(local_var_content_type);
835 let local_var_content = local_var_resp.text().await?;
836
837 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
838 match local_var_content_type {
839 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
840 ContentType::Text => {
841 return Err(Error::from(serde_json::Error::custom(
842 "Received `text/plain` content type response that cannot be converted to \
843 `models::SplitResponse`",
844 )))
845 }
846 ContentType::Unsupported(local_var_unknown_type) => {
847 return Err(Error::from(serde_json::Error::custom(format!(
848 "Received `{local_var_unknown_type}` content type response that cannot be \
849 converted to `models::SplitResponse`"
850 ))))
851 }
852 }
853 } else {
854 let local_var_entity: Option<SplitError> =
855 serde_json::from_str(&local_var_content).ok();
856 let local_var_error = ResponseContent {
857 status: local_var_status,
858 content: local_var_content,
859 entity: local_var_entity,
860 };
861 Err(Error::ResponseError(local_var_error))
862 }
863 }
864
865 async fn stake(&self, params: StakeParams) -> Result<models::StakeResponse, Error<StakeError>> {
867 let StakeParams {
868 chain_descriptor,
869 stake_request,
870 idempotency_key,
871 } = params;
872
873 let local_var_configuration = &self.configuration;
874
875 let local_var_client = &local_var_configuration.client;
876
877 let local_var_uri_str = format!(
878 "{}/staking/chains/{chainDescriptor}/stake",
879 local_var_configuration.base_path,
880 chainDescriptor = chain_descriptor.to_string()
881 );
882 let mut local_var_req_builder =
883 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
884
885 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
886 local_var_req_builder = local_var_req_builder
887 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
888 }
889 if let Some(local_var_param_value) = idempotency_key {
890 local_var_req_builder =
891 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
892 }
893 local_var_req_builder = local_var_req_builder.json(&stake_request);
894
895 let local_var_req = local_var_req_builder.build()?;
896 let local_var_resp = local_var_client.execute(local_var_req).await?;
897
898 let local_var_status = local_var_resp.status();
899 let local_var_content_type = local_var_resp
900 .headers()
901 .get("content-type")
902 .and_then(|v| v.to_str().ok())
903 .unwrap_or("application/octet-stream");
904 let local_var_content_type = super::ContentType::from(local_var_content_type);
905 let local_var_content = local_var_resp.text().await?;
906
907 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
908 match local_var_content_type {
909 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
910 ContentType::Text => {
911 return Err(Error::from(serde_json::Error::custom(
912 "Received `text/plain` content type response that cannot be converted to \
913 `models::StakeResponse`",
914 )))
915 }
916 ContentType::Unsupported(local_var_unknown_type) => {
917 return Err(Error::from(serde_json::Error::custom(format!(
918 "Received `{local_var_unknown_type}` content type response that cannot be \
919 converted to `models::StakeResponse`"
920 ))))
921 }
922 }
923 } else {
924 let local_var_entity: Option<StakeError> =
925 serde_json::from_str(&local_var_content).ok();
926 let local_var_error = ResponseContent {
927 status: local_var_status,
928 content: local_var_content,
929 entity: local_var_entity,
930 };
931 Err(Error::ResponseError(local_var_error))
932 }
933 }
934
935 async fn unstake(&self, params: UnstakeParams) -> Result<(), Error<UnstakeError>> {
937 let UnstakeParams {
938 chain_descriptor,
939 unstake_request,
940 idempotency_key,
941 } = params;
942
943 let local_var_configuration = &self.configuration;
944
945 let local_var_client = &local_var_configuration.client;
946
947 let local_var_uri_str = format!(
948 "{}/staking/chains/{chainDescriptor}/unstake",
949 local_var_configuration.base_path,
950 chainDescriptor = chain_descriptor.to_string()
951 );
952 let mut local_var_req_builder =
953 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
954
955 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
956 local_var_req_builder = local_var_req_builder
957 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
958 }
959 if let Some(local_var_param_value) = idempotency_key {
960 local_var_req_builder =
961 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
962 }
963 local_var_req_builder = local_var_req_builder.json(&unstake_request);
964
965 let local_var_req = local_var_req_builder.build()?;
966 let local_var_resp = local_var_client.execute(local_var_req).await?;
967
968 let local_var_status = local_var_resp.status();
969 let local_var_content = local_var_resp.text().await?;
970
971 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
972 Ok(())
973 } else {
974 let local_var_entity: Option<UnstakeError> =
975 serde_json::from_str(&local_var_content).ok();
976 let local_var_error = ResponseContent {
977 status: local_var_status,
978 content: local_var_content,
979 entity: local_var_entity,
980 };
981 Err(Error::ResponseError(local_var_error))
982 }
983 }
984
985 async fn withdraw(&self, params: WithdrawParams) -> Result<(), Error<WithdrawError>> {
987 let WithdrawParams {
988 chain_descriptor,
989 withdraw_request,
990 idempotency_key,
991 } = params;
992
993 let local_var_configuration = &self.configuration;
994
995 let local_var_client = &local_var_configuration.client;
996
997 let local_var_uri_str = format!(
998 "{}/staking/chains/{chainDescriptor}/withdraw",
999 local_var_configuration.base_path,
1000 chainDescriptor = chain_descriptor.to_string()
1001 );
1002 let mut local_var_req_builder =
1003 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
1004
1005 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
1006 local_var_req_builder = local_var_req_builder
1007 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
1008 }
1009 if let Some(local_var_param_value) = idempotency_key {
1010 local_var_req_builder =
1011 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
1012 }
1013 local_var_req_builder = local_var_req_builder.json(&withdraw_request);
1014
1015 let local_var_req = local_var_req_builder.build()?;
1016 let local_var_resp = local_var_client.execute(local_var_req).await?;
1017
1018 let local_var_status = local_var_resp.status();
1019 let local_var_content = local_var_resp.text().await?;
1020
1021 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1022 Ok(())
1023 } else {
1024 let local_var_entity: Option<WithdrawError> =
1025 serde_json::from_str(&local_var_content).ok();
1026 let local_var_error = ResponseContent {
1027 status: local_var_status,
1028 content: local_var_content,
1029 entity: local_var_entity,
1030 };
1031 Err(Error::ResponseError(local_var_error))
1032 }
1033 }
1034}
1035
1036#[derive(Debug, Clone, Serialize, Deserialize)]
1039#[serde(untagged)]
1040pub enum ApproveTermsOfServiceByProviderIdError {
1041 DefaultResponse(models::ErrorSchema),
1042 UnknownValue(serde_json::Value),
1043}
1044
1045#[derive(Debug, Clone, Serialize, Deserialize)]
1047#[serde(untagged)]
1048pub enum ClaimRewardsError {
1049 DefaultResponse(models::ErrorSchema),
1050 UnknownValue(serde_json::Value),
1051}
1052
1053#[derive(Debug, Clone, Serialize, Deserialize)]
1055#[serde(untagged)]
1056pub enum GetAllDelegationsError {
1057 DefaultResponse(models::ErrorSchema),
1058 UnknownValue(serde_json::Value),
1059}
1060
1061#[derive(Debug, Clone, Serialize, Deserialize)]
1063#[serde(untagged)]
1064pub enum GetChainInfoError {
1065 DefaultResponse(models::ErrorSchema),
1066 UnknownValue(serde_json::Value),
1067}
1068
1069#[derive(Debug, Clone, Serialize, Deserialize)]
1071#[serde(untagged)]
1072pub enum GetChainsError {
1073 DefaultResponse(models::ErrorSchema),
1074 UnknownValue(serde_json::Value),
1075}
1076
1077#[derive(Debug, Clone, Serialize, Deserialize)]
1079#[serde(untagged)]
1080pub enum GetDelegationByIdError {
1081 DefaultResponse(models::ErrorSchema),
1082 UnknownValue(serde_json::Value),
1083}
1084
1085#[derive(Debug, Clone, Serialize, Deserialize)]
1087#[serde(untagged)]
1088pub enum GetProvidersError {
1089 DefaultResponse(models::ErrorSchema),
1090 UnknownValue(serde_json::Value),
1091}
1092
1093#[derive(Debug, Clone, Serialize, Deserialize)]
1095#[serde(untagged)]
1096pub enum GetSummaryError {
1097 DefaultResponse(models::ErrorSchema),
1098 UnknownValue(serde_json::Value),
1099}
1100
1101#[derive(Debug, Clone, Serialize, Deserialize)]
1103#[serde(untagged)]
1104pub enum GetSummaryByVaultError {
1105 DefaultResponse(models::ErrorSchema),
1106 UnknownValue(serde_json::Value),
1107}
1108
1109#[derive(Debug, Clone, Serialize, Deserialize)]
1111#[serde(untagged)]
1112pub enum SplitError {
1113 DefaultResponse(models::ErrorSchema),
1114 UnknownValue(serde_json::Value),
1115}
1116
1117#[derive(Debug, Clone, Serialize, Deserialize)]
1119#[serde(untagged)]
1120pub enum StakeError {
1121 DefaultResponse(models::ErrorSchema),
1122 UnknownValue(serde_json::Value),
1123}
1124
1125#[derive(Debug, Clone, Serialize, Deserialize)]
1127#[serde(untagged)]
1128pub enum UnstakeError {
1129 DefaultResponse(models::ErrorSchema),
1130 UnknownValue(serde_json::Value),
1131}
1132
1133#[derive(Debug, Clone, Serialize, Deserialize)]
1135#[serde(untagged)]
1136pub enum WithdrawError {
1137 DefaultResponse(models::ErrorSchema),
1138 UnknownValue(serde_json::Value),
1139}