Skip to content

Commit 1ae00a2

Browse files
feat(rust/rbac-registration): Add the RegistrationChain::stake_addresses helper (#276)
* Add the RegistrationChain::stake_addresses helper * Rename method
1 parent ecda498 commit 1ae00a2

File tree

1 file changed

+29
-1
lines changed
  • rust/rbac-registration/src/registration/cardano

1 file changed

+29
-1
lines changed

rust/rbac-registration/src/registration/cardano/mod.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ use std::{collections::HashMap, sync::Arc};
66

77
use anyhow::bail;
88
use c509_certificate::c509::C509;
9-
use cardano_blockchain_types::TransactionId;
9+
use cardano_blockchain_types::{Cip0134Uri, StakeAddress, TransactionId};
1010
use catalyst_types::{id_uri::IdUri, uuid::UuidV4};
1111
use ed25519_dalek::VerifyingKey;
12+
use pallas::ledger::addresses::Address;
1213
use tracing::error;
1314
use update_rbac::{
1415
revocations_list, update_c509_certs, update_public_keys, update_role_data, update_x509_certs,
@@ -204,6 +205,21 @@ impl RegistrationChain {
204205
.get(role)
205206
.and_then(|rdr| rdr.encryption_key_from_rotation(rotation))
206207
}
208+
209+
/// Returns a list of role 0 stake addresses.
210+
#[must_use]
211+
pub fn role_0_stake_addresses(&self) -> Vec<StakeAddress> {
212+
let mut result = Vec::new();
213+
214+
if let Some(uris) = self.inner.certificate_uris.x_uris().get(&0) {
215+
result.extend(convert_stake_addresses(uris));
216+
}
217+
if let Some(uris) = self.inner.certificate_uris.c_uris().get(&0) {
218+
result.extend(convert_stake_addresses(uris));
219+
}
220+
221+
result
222+
}
207223
}
208224

209225
/// Inner structure of registration chain.
@@ -391,6 +407,18 @@ impl RegistrationChainInner {
391407
}
392408
}
393409

410+
/// Converts a list of `Cip0134Uri` to a list of stake addresses.
411+
fn convert_stake_addresses(uris: &[Cip0134Uri]) -> Vec<StakeAddress> {
412+
uris.iter()
413+
.filter_map(|uri| {
414+
match uri.address() {
415+
Address::Stake(a) => Some(a.clone().into()),
416+
_ => None,
417+
}
418+
})
419+
.collect()
420+
}
421+
394422
#[cfg(test)]
395423
mod test {
396424
use super::*;

0 commit comments

Comments
 (0)