1use {
10 super::{Error, configuration},
11 crate::{
12 apis::{ContentType, ResponseContent},
13 models,
14 },
15 async_trait::async_trait,
16 reqwest,
17 serde::{Deserialize, Serialize, de::Error as _},
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 merge_stake_accounts(
110 &self,
111 params: MergeStakeAccountsParams,
112 ) -> Result<models::MergeStakeAccountsResponse, Error<MergeStakeAccountsError>>;
113
114 async fn split(&self, params: SplitParams) -> Result<models::SplitResponse, Error<SplitError>>;
118
119 async fn stake(&self, params: StakeParams) -> Result<models::StakeResponse, Error<StakeError>>;
123
124 async fn unstake(&self, params: UnstakeParams) -> Result<(), Error<UnstakeError>>;
128
129 async fn withdraw(&self, params: WithdrawParams) -> Result<(), Error<WithdrawError>>;
133}
134
135pub struct StakingApiClient {
136 configuration: Arc<configuration::Configuration>,
137}
138
139impl StakingApiClient {
140 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
141 Self { configuration }
142 }
143}
144
145#[derive(Clone, Debug)]
148#[cfg_attr(feature = "bon", derive(::bon::Builder))]
149pub struct ApproveTermsOfServiceByProviderIdParams {
150 pub provider_id: models::StakingProvider,
152 pub idempotency_key: Option<String>,
157}
158
159#[derive(Clone, Debug)]
161#[cfg_attr(feature = "bon", derive(::bon::Builder))]
162pub struct ClaimRewardsParams {
163 pub chain_descriptor: String,
165 pub claim_rewards_request: models::ClaimRewardsRequest,
166 pub idempotency_key: Option<String>,
171}
172
173#[derive(Clone, Debug)]
176#[cfg_attr(feature = "bon", derive(::bon::Builder))]
177pub struct GetAllDelegationsParams {
178 pub chain_descriptor: Option<models::ChainDescriptor>,
183}
184
185#[derive(Clone, Debug)]
187#[cfg_attr(feature = "bon", derive(::bon::Builder))]
188pub struct GetChainInfoParams {
189 pub chain_descriptor: models::ChainDescriptor,
192}
193
194#[derive(Clone, Debug)]
197#[cfg_attr(feature = "bon", derive(::bon::Builder))]
198pub struct GetDelegationByIdParams {
199 pub id: String,
201}
202
203#[derive(Clone, Debug)]
206#[cfg_attr(feature = "bon", derive(::bon::Builder))]
207pub struct MergeStakeAccountsParams {
208 pub chain_descriptor: String,
210 pub merge_stake_accounts_request: models::MergeStakeAccountsRequest,
211 pub idempotency_key: Option<String>,
216}
217
218#[derive(Clone, Debug)]
220#[cfg_attr(feature = "bon", derive(::bon::Builder))]
221pub struct SplitParams {
222 pub chain_descriptor: String,
224 pub split_request: models::SplitRequest,
225 pub idempotency_key: Option<String>,
230}
231
232#[derive(Clone, Debug)]
234#[cfg_attr(feature = "bon", derive(::bon::Builder))]
235pub struct StakeParams {
236 pub chain_descriptor: models::ChainDescriptor,
238 pub stake_request: models::StakeRequest,
239 pub idempotency_key: Option<String>,
244}
245
246#[derive(Clone, Debug)]
248#[cfg_attr(feature = "bon", derive(::bon::Builder))]
249pub struct UnstakeParams {
250 pub chain_descriptor: models::ChainDescriptor,
252 pub unstake_request: models::UnstakeRequest,
253 pub idempotency_key: Option<String>,
258}
259
260#[derive(Clone, Debug)]
262#[cfg_attr(feature = "bon", derive(::bon::Builder))]
263pub struct WithdrawParams {
264 pub chain_descriptor: models::ChainDescriptor,
266 pub withdraw_request: models::WithdrawRequest,
267 pub idempotency_key: Option<String>,
272}
273
274#[async_trait]
275impl StakingApi for StakingApiClient {
276 async fn approve_terms_of_service_by_provider_id(
281 &self,
282 params: ApproveTermsOfServiceByProviderIdParams,
283 ) -> Result<(), Error<ApproveTermsOfServiceByProviderIdError>> {
284 let ApproveTermsOfServiceByProviderIdParams {
285 provider_id,
286 idempotency_key,
287 } = params;
288
289 let local_var_configuration = &self.configuration;
290
291 let local_var_client = &local_var_configuration.client;
292
293 let local_var_uri_str = format!(
294 "{}/staking/providers/{providerId}/approveTermsOfService",
295 local_var_configuration.base_path,
296 providerId = provider_id.to_string()
297 );
298 let mut local_var_req_builder =
299 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
300
301 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
302 local_var_req_builder = local_var_req_builder
303 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
304 }
305 if let Some(local_var_param_value) = idempotency_key {
306 local_var_req_builder =
307 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
308 }
309
310 let local_var_req = local_var_req_builder.build()?;
311 let local_var_resp = local_var_client.execute(local_var_req).await?;
312
313 let local_var_status = local_var_resp.status();
314 let local_var_content = local_var_resp.text().await?;
315
316 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
317 Ok(())
318 } else {
319 let local_var_entity: Option<ApproveTermsOfServiceByProviderIdError> =
320 serde_json::from_str(&local_var_content).ok();
321 let local_var_error = ResponseContent {
322 status: local_var_status,
323 content: local_var_content,
324 entity: local_var_entity,
325 };
326 Err(Error::ResponseError(local_var_error))
327 }
328 }
329
330 async fn claim_rewards(
332 &self,
333 params: ClaimRewardsParams,
334 ) -> Result<(), Error<ClaimRewardsError>> {
335 let ClaimRewardsParams {
336 chain_descriptor,
337 claim_rewards_request,
338 idempotency_key,
339 } = params;
340
341 let local_var_configuration = &self.configuration;
342
343 let local_var_client = &local_var_configuration.client;
344
345 let local_var_uri_str = format!(
346 "{}/staking/chains/{chainDescriptor}/claim_rewards",
347 local_var_configuration.base_path,
348 chainDescriptor = crate::apis::urlencode(chain_descriptor)
349 );
350 let mut local_var_req_builder =
351 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
352
353 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
354 local_var_req_builder = local_var_req_builder
355 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
356 }
357 if let Some(local_var_param_value) = idempotency_key {
358 local_var_req_builder =
359 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
360 }
361 local_var_req_builder = local_var_req_builder.json(&claim_rewards_request);
362
363 let local_var_req = local_var_req_builder.build()?;
364 let local_var_resp = local_var_client.execute(local_var_req).await?;
365
366 let local_var_status = local_var_resp.status();
367 let local_var_content = local_var_resp.text().await?;
368
369 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
370 Ok(())
371 } else {
372 let local_var_entity: Option<ClaimRewardsError> =
373 serde_json::from_str(&local_var_content).ok();
374 let local_var_error = ResponseContent {
375 status: local_var_status,
376 content: local_var_content,
377 entity: local_var_entity,
378 };
379 Err(Error::ResponseError(local_var_error))
380 }
381 }
382
383 async fn get_all_delegations(
387 &self,
388 params: GetAllDelegationsParams,
389 ) -> Result<Vec<models::Delegation>, Error<GetAllDelegationsError>> {
390 let GetAllDelegationsParams { chain_descriptor } = params;
391
392 let local_var_configuration = &self.configuration;
393
394 let local_var_client = &local_var_configuration.client;
395
396 let local_var_uri_str = format!("{}/staking/positions", local_var_configuration.base_path);
397 let mut local_var_req_builder =
398 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
399
400 if let Some(ref param_value) = chain_descriptor {
401 local_var_req_builder =
402 local_var_req_builder.query(&[("chainDescriptor", ¶m_value.to_string())]);
403 }
404 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
405 local_var_req_builder = local_var_req_builder
406 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
407 }
408
409 let local_var_req = local_var_req_builder.build()?;
410 let local_var_resp = local_var_client.execute(local_var_req).await?;
411
412 let local_var_status = local_var_resp.status();
413 let local_var_content_type = local_var_resp
414 .headers()
415 .get("content-type")
416 .and_then(|v| v.to_str().ok())
417 .unwrap_or("application/octet-stream");
418 let local_var_content_type = super::ContentType::from(local_var_content_type);
419 let local_var_content = local_var_resp.text().await?;
420
421 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
422 match local_var_content_type {
423 ContentType::Json => {
424 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
425 }
426 ContentType::Text => {
427 return Err(Error::from(serde_json::Error::custom(
428 "Received `text/plain` content type response that cannot be converted to \
429 `Vec<models::Delegation>`",
430 )));
431 }
432 ContentType::Unsupported(local_var_unknown_type) => {
433 return Err(Error::from(serde_json::Error::custom(format!(
434 "Received `{local_var_unknown_type}` content type response that cannot be \
435 converted to `Vec<models::Delegation>`"
436 ))));
437 }
438 }
439 } else {
440 let local_var_entity: Option<GetAllDelegationsError> =
441 serde_json::from_str(&local_var_content).ok();
442 let local_var_error = ResponseContent {
443 status: local_var_status,
444 content: local_var_content,
445 entity: local_var_entity,
446 };
447 Err(Error::ResponseError(local_var_error))
448 }
449 }
450
451 async fn get_chain_info(
455 &self,
456 params: GetChainInfoParams,
457 ) -> Result<models::ChainInfoResponse, Error<GetChainInfoError>> {
458 let GetChainInfoParams { chain_descriptor } = params;
459
460 let local_var_configuration = &self.configuration;
461
462 let local_var_client = &local_var_configuration.client;
463
464 let local_var_uri_str = format!(
465 "{}/staking/chains/{chainDescriptor}/chainInfo",
466 local_var_configuration.base_path,
467 chainDescriptor = chain_descriptor.to_string()
468 );
469 let mut local_var_req_builder =
470 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
471
472 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
473 local_var_req_builder = local_var_req_builder
474 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
475 }
476
477 let local_var_req = local_var_req_builder.build()?;
478 let local_var_resp = local_var_client.execute(local_var_req).await?;
479
480 let local_var_status = local_var_resp.status();
481 let local_var_content_type = local_var_resp
482 .headers()
483 .get("content-type")
484 .and_then(|v| v.to_str().ok())
485 .unwrap_or("application/octet-stream");
486 let local_var_content_type = super::ContentType::from(local_var_content_type);
487 let local_var_content = local_var_resp.text().await?;
488
489 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
490 match local_var_content_type {
491 ContentType::Json => {
492 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
493 }
494 ContentType::Text => {
495 return Err(Error::from(serde_json::Error::custom(
496 "Received `text/plain` content type response that cannot be converted to \
497 `models::ChainInfoResponse`",
498 )));
499 }
500 ContentType::Unsupported(local_var_unknown_type) => {
501 return Err(Error::from(serde_json::Error::custom(format!(
502 "Received `{local_var_unknown_type}` content type response that cannot be \
503 converted to `models::ChainInfoResponse`"
504 ))));
505 }
506 }
507 } else {
508 let local_var_entity: Option<GetChainInfoError> =
509 serde_json::from_str(&local_var_content).ok();
510 let local_var_error = ResponseContent {
511 status: local_var_status,
512 content: local_var_content,
513 entity: local_var_entity,
514 };
515 Err(Error::ResponseError(local_var_error))
516 }
517 }
518
519 async fn get_chains(&self) -> Result<Vec<models::ChainDescriptor>, Error<GetChainsError>> {
522 let local_var_configuration = &self.configuration;
523
524 let local_var_client = &local_var_configuration.client;
525
526 let local_var_uri_str = format!("{}/staking/chains", local_var_configuration.base_path);
527 let mut local_var_req_builder =
528 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
529
530 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
531 local_var_req_builder = local_var_req_builder
532 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
533 }
534
535 let local_var_req = local_var_req_builder.build()?;
536 let local_var_resp = local_var_client.execute(local_var_req).await?;
537
538 let local_var_status = local_var_resp.status();
539 let local_var_content_type = local_var_resp
540 .headers()
541 .get("content-type")
542 .and_then(|v| v.to_str().ok())
543 .unwrap_or("application/octet-stream");
544 let local_var_content_type = super::ContentType::from(local_var_content_type);
545 let local_var_content = local_var_resp.text().await?;
546
547 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
548 match local_var_content_type {
549 ContentType::Json => {
550 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
551 }
552 ContentType::Text => {
553 return Err(Error::from(serde_json::Error::custom(
554 "Received `text/plain` content type response that cannot be converted to \
555 `Vec<models::ChainDescriptor>`",
556 )));
557 }
558 ContentType::Unsupported(local_var_unknown_type) => {
559 return Err(Error::from(serde_json::Error::custom(format!(
560 "Received `{local_var_unknown_type}` content type response that cannot be \
561 converted to `Vec<models::ChainDescriptor>`"
562 ))));
563 }
564 }
565 } else {
566 let local_var_entity: Option<GetChainsError> =
567 serde_json::from_str(&local_var_content).ok();
568 let local_var_error = ResponseContent {
569 status: local_var_status,
570 content: local_var_content,
571 entity: local_var_entity,
572 };
573 Err(Error::ResponseError(local_var_error))
574 }
575 }
576
577 async fn get_delegation_by_id(
581 &self,
582 params: GetDelegationByIdParams,
583 ) -> Result<models::Delegation, Error<GetDelegationByIdError>> {
584 let GetDelegationByIdParams { id } = params;
585
586 let local_var_configuration = &self.configuration;
587
588 let local_var_client = &local_var_configuration.client;
589
590 let local_var_uri_str = format!(
591 "{}/staking/positions/{id}",
592 local_var_configuration.base_path,
593 id = crate::apis::urlencode(id)
594 );
595 let mut local_var_req_builder =
596 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
597
598 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
599 local_var_req_builder = local_var_req_builder
600 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
601 }
602
603 let local_var_req = local_var_req_builder.build()?;
604 let local_var_resp = local_var_client.execute(local_var_req).await?;
605
606 let local_var_status = local_var_resp.status();
607 let local_var_content_type = local_var_resp
608 .headers()
609 .get("content-type")
610 .and_then(|v| v.to_str().ok())
611 .unwrap_or("application/octet-stream");
612 let local_var_content_type = super::ContentType::from(local_var_content_type);
613 let local_var_content = local_var_resp.text().await?;
614
615 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
616 match local_var_content_type {
617 ContentType::Json => {
618 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
619 }
620 ContentType::Text => {
621 return Err(Error::from(serde_json::Error::custom(
622 "Received `text/plain` content type response that cannot be converted to \
623 `models::Delegation`",
624 )));
625 }
626 ContentType::Unsupported(local_var_unknown_type) => {
627 return Err(Error::from(serde_json::Error::custom(format!(
628 "Received `{local_var_unknown_type}` content type response that cannot be \
629 converted to `models::Delegation`"
630 ))));
631 }
632 }
633 } else {
634 let local_var_entity: Option<GetDelegationByIdError> =
635 serde_json::from_str(&local_var_content).ok();
636 let local_var_error = ResponseContent {
637 status: local_var_status,
638 content: local_var_content,
639 entity: local_var_entity,
640 };
641 Err(Error::ResponseError(local_var_error))
642 }
643 }
644
645 async fn get_providers(&self) -> Result<Vec<models::Provider>, Error<GetProvidersError>> {
648 let local_var_configuration = &self.configuration;
649
650 let local_var_client = &local_var_configuration.client;
651
652 let local_var_uri_str = format!("{}/staking/providers", local_var_configuration.base_path);
653 let mut local_var_req_builder =
654 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
655
656 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
657 local_var_req_builder = local_var_req_builder
658 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
659 }
660
661 let local_var_req = local_var_req_builder.build()?;
662 let local_var_resp = local_var_client.execute(local_var_req).await?;
663
664 let local_var_status = local_var_resp.status();
665 let local_var_content_type = local_var_resp
666 .headers()
667 .get("content-type")
668 .and_then(|v| v.to_str().ok())
669 .unwrap_or("application/octet-stream");
670 let local_var_content_type = super::ContentType::from(local_var_content_type);
671 let local_var_content = local_var_resp.text().await?;
672
673 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
674 match local_var_content_type {
675 ContentType::Json => {
676 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
677 }
678 ContentType::Text => {
679 return Err(Error::from(serde_json::Error::custom(
680 "Received `text/plain` content type response that cannot be converted to \
681 `Vec<models::Provider>`",
682 )));
683 }
684 ContentType::Unsupported(local_var_unknown_type) => {
685 return Err(Error::from(serde_json::Error::custom(format!(
686 "Received `{local_var_unknown_type}` content type response that cannot be \
687 converted to `Vec<models::Provider>`"
688 ))));
689 }
690 }
691 } else {
692 let local_var_entity: Option<GetProvidersError> =
693 serde_json::from_str(&local_var_content).ok();
694 let local_var_error = ResponseContent {
695 status: local_var_status,
696 content: local_var_content,
697 entity: local_var_entity,
698 };
699 Err(Error::ResponseError(local_var_error))
700 }
701 }
702
703 async fn get_summary(&self) -> Result<models::DelegationSummary, Error<GetSummaryError>> {
708 let local_var_configuration = &self.configuration;
709
710 let local_var_client = &local_var_configuration.client;
711
712 let local_var_uri_str = format!(
713 "{}/staking/positions/summary",
714 local_var_configuration.base_path
715 );
716 let mut local_var_req_builder =
717 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
718
719 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
720 local_var_req_builder = local_var_req_builder
721 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
722 }
723
724 let local_var_req = local_var_req_builder.build()?;
725 let local_var_resp = local_var_client.execute(local_var_req).await?;
726
727 let local_var_status = local_var_resp.status();
728 let local_var_content_type = local_var_resp
729 .headers()
730 .get("content-type")
731 .and_then(|v| v.to_str().ok())
732 .unwrap_or("application/octet-stream");
733 let local_var_content_type = super::ContentType::from(local_var_content_type);
734 let local_var_content = local_var_resp.text().await?;
735
736 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
737 match local_var_content_type {
738 ContentType::Json => {
739 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
740 }
741 ContentType::Text => {
742 return Err(Error::from(serde_json::Error::custom(
743 "Received `text/plain` content type response that cannot be converted to \
744 `models::DelegationSummary`",
745 )));
746 }
747 ContentType::Unsupported(local_var_unknown_type) => {
748 return Err(Error::from(serde_json::Error::custom(format!(
749 "Received `{local_var_unknown_type}` content type response that cannot be \
750 converted to `models::DelegationSummary`"
751 ))));
752 }
753 }
754 } else {
755 let local_var_entity: Option<GetSummaryError> =
756 serde_json::from_str(&local_var_content).ok();
757 let local_var_error = ResponseContent {
758 status: local_var_status,
759 content: local_var_content,
760 entity: local_var_entity,
761 };
762 Err(Error::ResponseError(local_var_error))
763 }
764 }
765
766 async fn get_summary_by_vault(
771 &self,
772 ) -> Result<
773 std::collections::HashMap<String, models::DelegationSummary>,
774 Error<GetSummaryByVaultError>,
775 > {
776 let local_var_configuration = &self.configuration;
777
778 let local_var_client = &local_var_configuration.client;
779
780 let local_var_uri_str = format!(
781 "{}/staking/positions/summary/vaults",
782 local_var_configuration.base_path
783 );
784 let mut local_var_req_builder =
785 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
786
787 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
788 local_var_req_builder = local_var_req_builder
789 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
790 }
791
792 let local_var_req = local_var_req_builder.build()?;
793 let local_var_resp = local_var_client.execute(local_var_req).await?;
794
795 let local_var_status = local_var_resp.status();
796 let local_var_content_type = local_var_resp
797 .headers()
798 .get("content-type")
799 .and_then(|v| v.to_str().ok())
800 .unwrap_or("application/octet-stream");
801 let local_var_content_type = super::ContentType::from(local_var_content_type);
802 let local_var_content = local_var_resp.text().await?;
803
804 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
805 match local_var_content_type {
806 ContentType::Json => {
807 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
808 }
809 ContentType::Text => {
810 return Err(Error::from(serde_json::Error::custom(
811 "Received `text/plain` content type response that cannot be converted to \
812 `std::collections::HashMap<String, models::DelegationSummary>`",
813 )));
814 }
815 ContentType::Unsupported(local_var_unknown_type) => {
816 return Err(Error::from(serde_json::Error::custom(format!(
817 "Received `{local_var_unknown_type}` content type response that cannot be \
818 converted to `std::collections::HashMap<String, \
819 models::DelegationSummary>`"
820 ))));
821 }
822 }
823 } else {
824 let local_var_entity: Option<GetSummaryByVaultError> =
825 serde_json::from_str(&local_var_content).ok();
826 let local_var_error = ResponseContent {
827 status: local_var_status,
828 content: local_var_content,
829 entity: local_var_entity,
830 };
831 Err(Error::ResponseError(local_var_error))
832 }
833 }
834
835 async fn merge_stake_accounts(
838 &self,
839 params: MergeStakeAccountsParams,
840 ) -> Result<models::MergeStakeAccountsResponse, Error<MergeStakeAccountsError>> {
841 let MergeStakeAccountsParams {
842 chain_descriptor,
843 merge_stake_accounts_request,
844 idempotency_key,
845 } = params;
846
847 let local_var_configuration = &self.configuration;
848
849 let local_var_client = &local_var_configuration.client;
850
851 let local_var_uri_str = format!(
852 "{}/staking/chains/{chainDescriptor}/merge",
853 local_var_configuration.base_path,
854 chainDescriptor = crate::apis::urlencode(chain_descriptor)
855 );
856 let mut local_var_req_builder =
857 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
858
859 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
860 local_var_req_builder = local_var_req_builder
861 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
862 }
863 if let Some(local_var_param_value) = idempotency_key {
864 local_var_req_builder =
865 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
866 }
867 local_var_req_builder = local_var_req_builder.json(&merge_stake_accounts_request);
868
869 let local_var_req = local_var_req_builder.build()?;
870 let local_var_resp = local_var_client.execute(local_var_req).await?;
871
872 let local_var_status = local_var_resp.status();
873 let local_var_content_type = local_var_resp
874 .headers()
875 .get("content-type")
876 .and_then(|v| v.to_str().ok())
877 .unwrap_or("application/octet-stream");
878 let local_var_content_type = super::ContentType::from(local_var_content_type);
879 let local_var_content = local_var_resp.text().await?;
880
881 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
882 match local_var_content_type {
883 ContentType::Json => {
884 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
885 }
886 ContentType::Text => {
887 return Err(Error::from(serde_json::Error::custom(
888 "Received `text/plain` content type response that cannot be converted to \
889 `models::MergeStakeAccountsResponse`",
890 )));
891 }
892 ContentType::Unsupported(local_var_unknown_type) => {
893 return Err(Error::from(serde_json::Error::custom(format!(
894 "Received `{local_var_unknown_type}` content type response that cannot be \
895 converted to `models::MergeStakeAccountsResponse`"
896 ))));
897 }
898 }
899 } else {
900 let local_var_entity: Option<MergeStakeAccountsError> =
901 serde_json::from_str(&local_var_content).ok();
902 let local_var_error = ResponseContent {
903 status: local_var_status,
904 content: local_var_content,
905 entity: local_var_entity,
906 };
907 Err(Error::ResponseError(local_var_error))
908 }
909 }
910
911 async fn split(&self, params: SplitParams) -> Result<models::SplitResponse, Error<SplitError>> {
913 let SplitParams {
914 chain_descriptor,
915 split_request,
916 idempotency_key,
917 } = params;
918
919 let local_var_configuration = &self.configuration;
920
921 let local_var_client = &local_var_configuration.client;
922
923 let local_var_uri_str = format!(
924 "{}/staking/chains/{chainDescriptor}/split",
925 local_var_configuration.base_path,
926 chainDescriptor = crate::apis::urlencode(chain_descriptor)
927 );
928 let mut local_var_req_builder =
929 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
930
931 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
932 local_var_req_builder = local_var_req_builder
933 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
934 }
935 if let Some(local_var_param_value) = idempotency_key {
936 local_var_req_builder =
937 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
938 }
939 local_var_req_builder = local_var_req_builder.json(&split_request);
940
941 let local_var_req = local_var_req_builder.build()?;
942 let local_var_resp = local_var_client.execute(local_var_req).await?;
943
944 let local_var_status = local_var_resp.status();
945 let local_var_content_type = local_var_resp
946 .headers()
947 .get("content-type")
948 .and_then(|v| v.to_str().ok())
949 .unwrap_or("application/octet-stream");
950 let local_var_content_type = super::ContentType::from(local_var_content_type);
951 let local_var_content = local_var_resp.text().await?;
952
953 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
954 match local_var_content_type {
955 ContentType::Json => {
956 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
957 }
958 ContentType::Text => {
959 return Err(Error::from(serde_json::Error::custom(
960 "Received `text/plain` content type response that cannot be converted to \
961 `models::SplitResponse`",
962 )));
963 }
964 ContentType::Unsupported(local_var_unknown_type) => {
965 return Err(Error::from(serde_json::Error::custom(format!(
966 "Received `{local_var_unknown_type}` content type response that cannot be \
967 converted to `models::SplitResponse`"
968 ))));
969 }
970 }
971 } else {
972 let local_var_entity: Option<SplitError> =
973 serde_json::from_str(&local_var_content).ok();
974 let local_var_error = ResponseContent {
975 status: local_var_status,
976 content: local_var_content,
977 entity: local_var_entity,
978 };
979 Err(Error::ResponseError(local_var_error))
980 }
981 }
982
983 async fn stake(&self, params: StakeParams) -> Result<models::StakeResponse, Error<StakeError>> {
985 let StakeParams {
986 chain_descriptor,
987 stake_request,
988 idempotency_key,
989 } = params;
990
991 let local_var_configuration = &self.configuration;
992
993 let local_var_client = &local_var_configuration.client;
994
995 let local_var_uri_str = format!(
996 "{}/staking/chains/{chainDescriptor}/stake",
997 local_var_configuration.base_path,
998 chainDescriptor = chain_descriptor.to_string()
999 );
1000 let mut local_var_req_builder =
1001 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
1002
1003 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
1004 local_var_req_builder = local_var_req_builder
1005 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
1006 }
1007 if let Some(local_var_param_value) = idempotency_key {
1008 local_var_req_builder =
1009 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
1010 }
1011 local_var_req_builder = local_var_req_builder.json(&stake_request);
1012
1013 let local_var_req = local_var_req_builder.build()?;
1014 let local_var_resp = local_var_client.execute(local_var_req).await?;
1015
1016 let local_var_status = local_var_resp.status();
1017 let local_var_content_type = local_var_resp
1018 .headers()
1019 .get("content-type")
1020 .and_then(|v| v.to_str().ok())
1021 .unwrap_or("application/octet-stream");
1022 let local_var_content_type = super::ContentType::from(local_var_content_type);
1023 let local_var_content = local_var_resp.text().await?;
1024
1025 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1026 match local_var_content_type {
1027 ContentType::Json => {
1028 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
1029 }
1030 ContentType::Text => {
1031 return Err(Error::from(serde_json::Error::custom(
1032 "Received `text/plain` content type response that cannot be converted to \
1033 `models::StakeResponse`",
1034 )));
1035 }
1036 ContentType::Unsupported(local_var_unknown_type) => {
1037 return Err(Error::from(serde_json::Error::custom(format!(
1038 "Received `{local_var_unknown_type}` content type response that cannot be \
1039 converted to `models::StakeResponse`"
1040 ))));
1041 }
1042 }
1043 } else {
1044 let local_var_entity: Option<StakeError> =
1045 serde_json::from_str(&local_var_content).ok();
1046 let local_var_error = ResponseContent {
1047 status: local_var_status,
1048 content: local_var_content,
1049 entity: local_var_entity,
1050 };
1051 Err(Error::ResponseError(local_var_error))
1052 }
1053 }
1054
1055 async fn unstake(&self, params: UnstakeParams) -> Result<(), Error<UnstakeError>> {
1057 let UnstakeParams {
1058 chain_descriptor,
1059 unstake_request,
1060 idempotency_key,
1061 } = params;
1062
1063 let local_var_configuration = &self.configuration;
1064
1065 let local_var_client = &local_var_configuration.client;
1066
1067 let local_var_uri_str = format!(
1068 "{}/staking/chains/{chainDescriptor}/unstake",
1069 local_var_configuration.base_path,
1070 chainDescriptor = chain_descriptor.to_string()
1071 );
1072 let mut local_var_req_builder =
1073 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
1074
1075 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
1076 local_var_req_builder = local_var_req_builder
1077 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
1078 }
1079 if let Some(local_var_param_value) = idempotency_key {
1080 local_var_req_builder =
1081 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
1082 }
1083 local_var_req_builder = local_var_req_builder.json(&unstake_request);
1084
1085 let local_var_req = local_var_req_builder.build()?;
1086 let local_var_resp = local_var_client.execute(local_var_req).await?;
1087
1088 let local_var_status = local_var_resp.status();
1089 let local_var_content = local_var_resp.text().await?;
1090
1091 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1092 Ok(())
1093 } else {
1094 let local_var_entity: Option<UnstakeError> =
1095 serde_json::from_str(&local_var_content).ok();
1096 let local_var_error = ResponseContent {
1097 status: local_var_status,
1098 content: local_var_content,
1099 entity: local_var_entity,
1100 };
1101 Err(Error::ResponseError(local_var_error))
1102 }
1103 }
1104
1105 async fn withdraw(&self, params: WithdrawParams) -> Result<(), Error<WithdrawError>> {
1107 let WithdrawParams {
1108 chain_descriptor,
1109 withdraw_request,
1110 idempotency_key,
1111 } = params;
1112
1113 let local_var_configuration = &self.configuration;
1114
1115 let local_var_client = &local_var_configuration.client;
1116
1117 let local_var_uri_str = format!(
1118 "{}/staking/chains/{chainDescriptor}/withdraw",
1119 local_var_configuration.base_path,
1120 chainDescriptor = chain_descriptor.to_string()
1121 );
1122 let mut local_var_req_builder =
1123 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
1124
1125 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
1126 local_var_req_builder = local_var_req_builder
1127 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
1128 }
1129 if let Some(local_var_param_value) = idempotency_key {
1130 local_var_req_builder =
1131 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
1132 }
1133 local_var_req_builder = local_var_req_builder.json(&withdraw_request);
1134
1135 let local_var_req = local_var_req_builder.build()?;
1136 let local_var_resp = local_var_client.execute(local_var_req).await?;
1137
1138 let local_var_status = local_var_resp.status();
1139 let local_var_content = local_var_resp.text().await?;
1140
1141 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1142 Ok(())
1143 } else {
1144 let local_var_entity: Option<WithdrawError> =
1145 serde_json::from_str(&local_var_content).ok();
1146 let local_var_error = ResponseContent {
1147 status: local_var_status,
1148 content: local_var_content,
1149 entity: local_var_entity,
1150 };
1151 Err(Error::ResponseError(local_var_error))
1152 }
1153 }
1154}
1155
1156#[derive(Debug, Clone, Serialize, Deserialize)]
1159#[serde(untagged)]
1160pub enum ApproveTermsOfServiceByProviderIdError {
1161 DefaultResponse(models::ErrorSchema),
1162 UnknownValue(serde_json::Value),
1163}
1164
1165#[derive(Debug, Clone, Serialize, Deserialize)]
1167#[serde(untagged)]
1168pub enum ClaimRewardsError {
1169 DefaultResponse(models::ErrorSchema),
1170 UnknownValue(serde_json::Value),
1171}
1172
1173#[derive(Debug, Clone, Serialize, Deserialize)]
1175#[serde(untagged)]
1176pub enum GetAllDelegationsError {
1177 DefaultResponse(models::ErrorSchema),
1178 UnknownValue(serde_json::Value),
1179}
1180
1181#[derive(Debug, Clone, Serialize, Deserialize)]
1183#[serde(untagged)]
1184pub enum GetChainInfoError {
1185 DefaultResponse(models::ErrorSchema),
1186 UnknownValue(serde_json::Value),
1187}
1188
1189#[derive(Debug, Clone, Serialize, Deserialize)]
1191#[serde(untagged)]
1192pub enum GetChainsError {
1193 DefaultResponse(models::ErrorSchema),
1194 UnknownValue(serde_json::Value),
1195}
1196
1197#[derive(Debug, Clone, Serialize, Deserialize)]
1199#[serde(untagged)]
1200pub enum GetDelegationByIdError {
1201 DefaultResponse(models::ErrorSchema),
1202 UnknownValue(serde_json::Value),
1203}
1204
1205#[derive(Debug, Clone, Serialize, Deserialize)]
1207#[serde(untagged)]
1208pub enum GetProvidersError {
1209 DefaultResponse(models::ErrorSchema),
1210 UnknownValue(serde_json::Value),
1211}
1212
1213#[derive(Debug, Clone, Serialize, Deserialize)]
1215#[serde(untagged)]
1216pub enum GetSummaryError {
1217 DefaultResponse(models::ErrorSchema),
1218 UnknownValue(serde_json::Value),
1219}
1220
1221#[derive(Debug, Clone, Serialize, Deserialize)]
1223#[serde(untagged)]
1224pub enum GetSummaryByVaultError {
1225 DefaultResponse(models::ErrorSchema),
1226 UnknownValue(serde_json::Value),
1227}
1228
1229#[derive(Debug, Clone, Serialize, Deserialize)]
1231#[serde(untagged)]
1232pub enum MergeStakeAccountsError {
1233 DefaultResponse(models::ErrorSchema),
1234 UnknownValue(serde_json::Value),
1235}
1236
1237#[derive(Debug, Clone, Serialize, Deserialize)]
1239#[serde(untagged)]
1240pub enum SplitError {
1241 DefaultResponse(models::ErrorSchema),
1242 UnknownValue(serde_json::Value),
1243}
1244
1245#[derive(Debug, Clone, Serialize, Deserialize)]
1247#[serde(untagged)]
1248pub enum StakeError {
1249 DefaultResponse(models::ErrorSchema),
1250 UnknownValue(serde_json::Value),
1251}
1252
1253#[derive(Debug, Clone, Serialize, Deserialize)]
1255#[serde(untagged)]
1256pub enum UnstakeError {
1257 DefaultResponse(models::ErrorSchema),
1258 UnknownValue(serde_json::Value),
1259}
1260
1261#[derive(Debug, Clone, Serialize, Deserialize)]
1263#[serde(untagged)]
1264pub enum WithdrawError {
1265 DefaultResponse(models::ErrorSchema),
1266 UnknownValue(serde_json::Value),
1267}