Skip to content

Commit cc7edbe

Browse files
feat(rust/rbac-registration): Use HashSet instead of Vec to return a list of role 0 stake addresses (#304)
* Use HashSet instead of Vec to return a list of role 0 stake addresses * Update after merge
1 parent c980a45 commit cc7edbe

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
//! Doc Reference: <https://github.com/input-output-hk/catalyst-CIPs/tree/x509-envelope-metadata/CIP-XXXX>
33
//! CDDL Reference: <https://github.com/input-output-hk/catalyst-CIPs/blob/x509-envelope-metadata/CIP-XXXX/x509-envelope.cddl>
44
5-
use std::{borrow::Cow, collections::HashMap};
5+
use std::{
6+
borrow::Cow,
7+
collections::{HashMap, HashSet},
8+
};
69

710
use anyhow::{anyhow, Context};
811
use cardano_blockchain_types::{
@@ -261,7 +264,7 @@ impl Cip509 {
261264

262265
/// Returns a list of role 0 stake addresses.
263266
#[must_use]
264-
pub fn role_0_stake_addresses(&self) -> Vec<StakeAddress> {
267+
pub fn role_0_stake_addresses(&self) -> HashSet<StakeAddress> {
265268
self.metadata
266269
.as_ref()
267270
.map(|m| m.certificate_uris.stake_addresses(0))

rust/rbac-registration/src/cardano/cip509/utils/cip134_uri_set.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
//! A set of [`Cip0134Uri`].
22
3-
use std::{collections::HashMap, sync::Arc};
3+
use std::{
4+
collections::{HashMap, HashSet},
5+
sync::Arc,
6+
};
47

58
use c509_certificate::{
69
extensions::{alt_name::GeneralNamesOrText, extension::ExtensionValue},
@@ -70,8 +73,8 @@ impl Cip0134UriSet {
7073

7174
/// Returns a list of stake addresses by the given index.
7275
#[must_use]
73-
pub fn stake_addresses(&self, index: usize) -> Vec<StakeAddress> {
74-
let mut result = Vec::new();
76+
pub fn stake_addresses(&self, index: usize) -> HashSet<StakeAddress> {
77+
let mut result = HashSet::new();
7578

7679
if let Some(uris) = self.x_uris().get(&index) {
7780
result.extend(convert_stake_addresses(uris));

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
33
mod update_rbac;
44

5-
use std::{collections::HashMap, sync::Arc};
5+
use std::{
6+
collections::{HashMap, HashSet},
7+
sync::Arc,
8+
};
69

710
use anyhow::bail;
811
use c509_certificate::c509::C509;
@@ -208,9 +211,9 @@ impl RegistrationChain {
208211
.and_then(|rdr| rdr.encryption_key_from_rotation(rotation))
209212
}
210213

211-
/// Returns a list of role 0 stake addresses.
214+
/// Returns a set of role 0 stake addresses.
212215
#[must_use]
213-
pub fn role_0_stake_addresses(&self) -> Vec<StakeAddress> {
216+
pub fn role_0_stake_addresses(&self) -> HashSet<StakeAddress> {
214217
self.inner.certificate_uris.stake_addresses(0)
215218
}
216219
}

0 commit comments

Comments
 (0)