Skip to content

Commit 46b083f

Browse files
feat(cat-gateway): Update RBAC endpoint to include information about stake addresses (#3374)
* Extend chain info with stake addresses * Stake address info * wip * Remove unused implementation, add TODO notes, bump api version * Try add property * Fix openapi lints --------- Co-authored-by: Mr-Leshiy <[email protected]>
1 parent 66721b7 commit 46b083f

File tree

6 files changed

+77
-3
lines changed

6 files changed

+77
-3
lines changed

catalyst-gateway/bin/src/rbac/get_chain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub async fn apply_regs(
131131
for reg in regs {
132132
if !reg.removed_stake_addresses.is_empty() {
133133
// TODO: This should be handled as a part of the
134-
// https://github.com/input-output-hk/catalyst-voices/issues/2599 task.
134+
// https://github.com/input-output-hk/catalyst-voices/issues/3464 task.
135135
continue;
136136
}
137137
let reg = cip509(network, reg.slot_no.into(), reg.txn_index.into()).await?;

catalyst-gateway/bin/src/service/api/cardano/rbac/registrations_get/v2/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@ mod registration_chain;
1515
mod response;
1616
mod role_data;
1717
mod role_list;
18+
mod stake_address_info;
19+
mod stake_address_info_list;
1820

1921
pub use self::{endpoint::endpoint_v2, response::AllResponsesV2};

catalyst-gateway/bin/src/service/api/cardano/rbac/registrations_get/v2/registration_chain.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ use crate::{
88
api::cardano::rbac::registrations_get::{
99
invalid_registration_list::InvalidRegistrationList,
1010
purpose_list::PurposeList,
11-
v2::{role_data::RbacRoleData, role_list::RbacRoleList},
11+
v2::{
12+
role_data::RbacRoleData, role_list::RbacRoleList,
13+
stake_address_info_list::StakeAddressInfoList,
14+
},
1215
},
1316
common::types::{
1417
cardano::{catalyst_id::CatalystId, transaction_id::TxnId},
@@ -40,6 +43,9 @@ pub struct RbacRegistrationChainV2 {
4043
/// A list of invalid registrations.
4144
#[oai(skip_serializing_if_is_empty)]
4245
invalid: InvalidRegistrationList,
46+
/// A list of stake addresses of the chain.
47+
#[oai(skip_serializing_if_is_empty)]
48+
stake_addresses: StakeAddressInfoList,
4349
}
4450

4551
impl Example for RbacRegistrationChainV2 {
@@ -51,6 +57,7 @@ impl Example for RbacRegistrationChainV2 {
5157
last_volatile_txn: Some(TxnId::example()),
5258
roles: RbacRoleList::example(),
5359
invalid: InvalidRegistrationList::example(),
60+
stake_addresses: StakeAddressInfoList::example(),
5461
}
5562
}
5663
}
@@ -70,6 +77,9 @@ impl RbacRegistrationChainV2 {
7077
let mut last_volatile_txn = None;
7178
let mut purpose = Vec::new().into();
7279
let mut roles = Vec::new().into();
80+
// TODO: This list needs to be updated as a part of the
81+
// https://github.com/input-output-hk/catalyst-voices/issues/3464 task.
82+
let stake_addresses = Vec::new().into();
7383
if let Some(info) = info {
7484
last_persistent_txn = info.last_persistent_txn.map(Into::into);
7585
last_volatile_txn = info.last_volatile_txn.map(Into::into);
@@ -91,6 +101,7 @@ impl RbacRegistrationChainV2 {
91101
purpose,
92102
roles,
93103
invalid,
104+
stake_addresses,
94105
}))
95106
}
96107
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//! An information about stake address used in a RBAC registration chain.
2+
3+
use poem_openapi::types::Example;
4+
use poem_openapi_derive::Object;
5+
6+
use crate::service::common::types::cardano::{
7+
cip19_stake_address::Cip19StakeAddress, slot_no::SlotNo,
8+
};
9+
10+
/// An information about stake address used in a RBAC registration chain.
11+
#[derive(Object, Debug, Clone)]
12+
#[oai(example)]
13+
pub struct RbacStakeAddressInfo {
14+
/// A stake address.
15+
stake: Cip19StakeAddress,
16+
/// A slot number when the registration chain started to use the stake address.
17+
active_from: SlotNo,
18+
/// A slot number when the registration chain stopped to use the stake address.
19+
#[oai(skip_serializing_if_is_empty)]
20+
inactive_from: Option<SlotNo>,
21+
}
22+
23+
impl Example for RbacStakeAddressInfo {
24+
fn example() -> Self {
25+
Self {
26+
stake: Cip19StakeAddress::example(),
27+
active_from: SlotNo::example(),
28+
inactive_from: Some(SlotNo::example()),
29+
}
30+
}
31+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//! A list of `StakeAddressInfo`.
2+
3+
use poem_openapi::{
4+
registry::MetaSchema,
5+
types::{Example, ToJSON},
6+
};
7+
8+
use crate::service::{
9+
api::cardano::rbac::registrations_get::v2::stake_address_info::RbacStakeAddressInfo,
10+
common::types::array_types::impl_array_types,
11+
};
12+
13+
impl_array_types!(
14+
/// A list of `StakeAddressInfo`.
15+
StakeAddressInfoList,
16+
RbacStakeAddressInfo,
17+
Some(MetaSchema {
18+
example: Self::example().to_json(),
19+
min_items: Some(1),
20+
max_items: Some(10000),
21+
items: Some(Box::new(RbacStakeAddressInfo::schema_ref())),
22+
..MetaSchema::ANY
23+
})
24+
);
25+
26+
impl Example for StakeAddressInfoList {
27+
fn example() -> Self {
28+
Self(vec![RbacStakeAddressInfo::example()])
29+
}
30+
}

catalyst-gateway/bin/src/service/api/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub(crate) mod health;
2323
const API_TITLE: &str = "Catalyst Gateway";
2424

2525
/// The version of the API
26-
const API_VERSION: &str = "0.4.0";
26+
const API_VERSION: &str = "0.5.0";
2727

2828
/// Get the contact details for inquiring about the API
2929
fn get_api_contact() -> ContactObject {

0 commit comments

Comments
 (0)