cat_gateway/service/api/cardano/staking/mod.rs
1//! Cardano Staking API Endpoints.
2
3use poem_openapi::{
4 param::{Path, Query},
5 OpenApi,
6};
7
8use crate::service::{
9 common::{
10 auth::none_or_rbac::NoneOrRBAC,
11 objects::cardano::network::Network,
12 tags::ApiTags,
13 types::cardano::{self, cip19_stake_address::Cip19StakeAddress, slot_no::SlotNo},
14 },
15 utilities::middleware::schema_validation::schema_version_validation,
16};
17
18mod assets_get;
19
20/// Cardano Staking API Endpoints
21pub(crate) struct Api;
22
23#[OpenApi(tag = "ApiTags::Cardano")]
24impl Api {
25 /// Get staked assets.
26 ///
27 /// This endpoint returns the total Cardano's staked assets to the corresponded
28 /// user's stake address.
29 #[oai(
30 path = "/v1/cardano/assets/:stake_address",
31 method = "get",
32 operation_id = "stakedAssetsGet",
33 transform = "schema_version_validation"
34 )]
35 async fn staked_ada_get(
36 &self,
37 /// The stake address of the user.
38 /// Should be a valid Bech32 encoded address followed by the https://cips.cardano.org/cip/CIP-19/#stake-addresses.
39 stake_address: Path<Cip19StakeAddress>,
40 /// Cardano network type.
41 /// If omitted network type is identified from the stake address.
42 /// If specified it must be correspondent to the network type encoded in the stake
43 /// address.
44 /// As `preprod` and `preview` network types in the stake address encoded as a
45 /// `testnet`, to specify `preprod` or `preview` network type use this
46 /// query parameter.
47 network: Query<Option<Network>>,
48 /// A time point at which the assets should be calculated.
49 /// If omitted latest slot number is used.
50 asat: Query<Option<cardano::query::AsAt>>,
51 /// No Authorization required, but Token permitted.
52 _auth: NoneOrRBAC,
53 ) -> assets_get::AllResponses {
54 Box::pin(assets_get::endpoint(
55 stake_address.0,
56 network.0,
57 SlotNo::into_option(asat.0),
58 ))
59 .await
60 }
61}