Skip to content

Commit c091803

Browse files
committed
wip
1 parent e76385b commit c091803

File tree

4 files changed

+40
-63
lines changed

4 files changed

+40
-63
lines changed

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,14 +337,6 @@ impl Cip509 {
337337
self.metadata.as_ref()
338338
}
339339

340-
/// Returns a set of addresses.
341-
#[must_use]
342-
pub fn addresses(&self) -> HashSet<Address> {
343-
self.certificate_uris()
344-
.map(Cip0134UriSet::addresses)
345-
.unwrap_or_default()
346-
}
347-
348340
/// Returns a set of stake addresses.
349341
#[must_use]
350342
pub fn stake_addresses(&self) -> HashSet<StakeAddress> {

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

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ struct Cip0134UriSetInner {
3939
x_uris: UrisMap,
4040
/// URIs from c509 certificates.
4141
c_uris: UrisMap,
42-
/// URIs which are taken by another chains.
43-
taken: HashSet<Cip0134Uri>,
42+
/// `StakeAddress` which are taken by another chains.
43+
taken_stake_addresses: HashSet<StakeAddress>,
4444
}
4545

4646
impl Cip0134UriSet {
@@ -53,11 +53,11 @@ impl Cip0134UriSet {
5353
) -> Self {
5454
let x_uris = extract_x509_uris(x509_certs, report);
5555
let c_uris = extract_c509_uris(c509_certs, report);
56-
let taken_uris = HashSet::new();
56+
let taken_stake_addresses = HashSet::new();
5757
Self(Arc::new(Cip0134UriSetInner {
5858
x_uris,
5959
c_uris,
60-
taken: taken_uris,
60+
taken_stake_addresses,
6161
}))
6262
}
6363

@@ -73,13 +73,12 @@ impl Cip0134UriSet {
7373
&self.0.c_uris
7474
}
7575

76-
/// Returns an iterator over of active (without taken) `Cip0134Uri`.
76+
/// Returns an iterator over of `Cip0134Uri`.
7777
pub(crate) fn values(&self) -> impl Iterator<Item = &Cip0134Uri> {
7878
self.x_uris()
7979
.values()
8080
.chain(self.c_uris().values())
8181
.flat_map(|uris| uris.iter())
82-
.filter(|v| !self.0.taken.contains(v))
8382
}
8483

8584
/// Returns `true` if both x509 and c509 certificate maps are empty.
@@ -88,7 +87,7 @@ impl Cip0134UriSet {
8887
self.x_uris().is_empty() && self.c_uris().is_empty()
8988
}
9089

91-
/// Returns a list of active (without taken) URIs by the given role.
90+
/// Returns a list of URIs by the given role.
9291
#[must_use]
9392
pub(crate) fn role_uris(
9493
&self,
@@ -97,16 +96,16 @@ impl Cip0134UriSet {
9796
let mut result = HashSet::new();
9897

9998
if let Some(uris) = self.x_uris().get(&role) {
100-
result.extend(uris.iter().filter(|v| !self.0.taken.contains(v)).cloned());
99+
result.extend(uris.iter().cloned());
101100
}
102101
if let Some(uris) = self.c_uris().get(&role) {
103-
result.extend(uris.iter().filter(|v| !self.0.taken.contains(v)).cloned());
102+
result.extend(uris.iter().cloned());
104103
}
105104

106105
result
107106
}
108107

109-
/// Returns a set of active (without taken) stake addresses by the given role.
108+
/// Returns a set of stake addresses by the given role.
110109
#[must_use]
111110
pub(crate) fn role_stake_addresses(
112111
&self,
@@ -123,12 +122,6 @@ impl Cip0134UriSet {
123122
.collect()
124123
}
125124

126-
/// Returns a set of all active (without taken) addresses.
127-
#[must_use]
128-
pub fn addresses(&self) -> HashSet<Address> {
129-
self.values().map(Cip0134Uri::address).cloned().collect()
130-
}
131-
132125
/// Returns a set of all active (without taken) stake addresses.
133126
#[must_use]
134127
pub fn stake_addresses(&self) -> HashSet<StakeAddress> {
@@ -173,7 +166,7 @@ impl Cip0134UriSet {
173166
let Cip0134UriSetInner {
174167
mut x_uris,
175168
mut c_uris,
176-
taken: mut taken_uris,
169+
mut taken_stake_addresses,
177170
} = Arc::unwrap_or_clone(self.0);
178171

179172
for (index, cert) in metadata.x509_certs.iter().enumerate() {
@@ -186,9 +179,6 @@ impl Cip0134UriSet {
186179
},
187180
X509DerCert::X509Cert(_) => {
188181
if let Some(uris) = metadata.certificate_uris.x_uris().get(&index) {
189-
uris.iter().for_each(|v| {
190-
taken_uris.remove(v);
191-
});
192182
x_uris.insert(index, uris.clone());
193183
}
194184
},
@@ -208,19 +198,24 @@ impl Cip0134UriSet {
208198
},
209199
C509Cert::C509Certificate(_) => {
210200
if let Some(uris) = metadata.certificate_uris.c_uris().get(&index) {
211-
uris.iter().for_each(|v| {
212-
taken_uris.remove(v);
213-
});
214201
c_uris.insert(index, uris.clone());
215202
}
216203
},
217204
}
218205
}
219206

207+
metadata
208+
.certificate_uris
209+
.stake_addresses()
210+
.iter()
211+
.for_each(|v| {
212+
taken_stake_addresses.remove(v);
213+
});
214+
220215
Self(Arc::new(Cip0134UriSetInner {
221216
x_uris,
222217
c_uris,
223-
taken: taken_uris,
218+
taken_stake_addresses,
224219
}))
225220
}
226221

@@ -233,27 +228,25 @@ impl Cip0134UriSet {
233228
self,
234229
reg: &Cip509RbacMetadata,
235230
) -> Self {
236-
let current_uris_set = self.values().collect::<HashSet<_>>();
237-
238-
let latest_taken_uris = reg
231+
let current_stake_addresses = self.stake_addresses();
232+
let latest_taken_stake_addresses = reg
239233
.certificate_uris
240-
.values()
241-
.filter(|v| current_uris_set.contains(v))
242-
.cloned()
243-
.collect::<Vec<_>>();
234+
.stake_addresses()
235+
.into_iter()
236+
.filter(|v| current_stake_addresses.contains(&v));
244237

245238
let Cip0134UriSetInner {
246239
x_uris,
247240
c_uris,
248-
taken: mut taken_uris,
241+
mut taken_stake_addresses,
249242
} = Arc::unwrap_or_clone(self.0);
250243

251-
taken_uris.extend(latest_taken_uris);
244+
taken_stake_addresses.extend(latest_taken_stake_addresses);
252245

253246
Self(Arc::new(Cip0134UriSetInner {
254247
x_uris,
255248
c_uris,
256-
taken: taken_uris,
249+
taken_stake_addresses,
257250
}))
258251
}
259252
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
use std::future::Future;
55

6-
use cardano_blockchain_types::pallas_addresses::Address;
6+
use cardano_blockchain_types::StakeAddress;
77
use catalyst_types::catalyst_id::CatalystId;
88
use ed25519_dalek::VerifyingKey;
99

@@ -24,9 +24,9 @@ pub trait RbacChainsState {
2424
) -> impl Future<Output = anyhow::Result<bool>> + Send;
2525

2626
/// Returns `true` if a provided address already used by any RBAC chain.
27-
fn is_addressed_used(
27+
fn is_stake_address_used(
2828
&self,
29-
address: &Address,
29+
addr: &StakeAddress,
3030
) -> impl Future<Output = anyhow::Result<bool>> + Send;
3131

3232
/// Returns a corresponding to the RBAC chain's Catalyst ID corresponding by the given
@@ -36,10 +36,10 @@ pub trait RbacChainsState {
3636
key: &VerifyingKey,
3737
) -> impl Future<Output = anyhow::Result<Option<CatalystId>>> + Send;
3838

39-
/// Update the chain by "taking" the given `Address` for the corresponding
39+
/// Update the chain by "taking" the given `StakeAddress` for the corresponding
4040
/// RBAC chain's by the given `CatalystId`.
41-
fn take_address_from_chains(
41+
fn take_stake_address_from_chains(
4242
&mut self,
43-
addresses: impl Iterator<Item = Address>,
43+
addresses: impl Iterator<Item = StakeAddress>,
4444
) -> impl Future<Output = anyhow::Result<()>> + Send;
4545
}

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ use std::{
99

1010
use anyhow::Context;
1111
use c509_certificate::c509::C509;
12-
use cardano_blockchain_types::{
13-
hashes::TransactionId, pallas_addresses::Address, Point, StakeAddress, TxnIndex,
14-
};
12+
use cardano_blockchain_types::{hashes::TransactionId, Point, StakeAddress, TxnIndex};
1513
use catalyst_types::{
1614
catalyst_id::{key_rotation::KeyRotation, role_index::RoleId, CatalystId},
1715
conversion::zero_out_last_n_bytes,
@@ -78,7 +76,7 @@ impl RegistrationChain {
7876
}
7977

8078
state
81-
.take_address_from_chains(cip509.addresses().into_iter())
79+
.take_stake_address_from_chains(cip509.stake_addresses().into_iter())
8280
.await?;
8381

8482
Ok(Some(new_chain))
@@ -114,14 +112,14 @@ impl RegistrationChain {
114112
};
115113

116114
// Check that addresses from the new registration aren't used in other chains.
117-
let previous_addresses = self.addresses();
118-
let reg_addresses = cip509.addresses();
115+
let previous_addresses = self.stake_addresses();
116+
let reg_addresses = cip509.stake_addresses();
119117
let new_addresses: Vec<_> = reg_addresses.difference(&previous_addresses).collect();
120118
for address in &new_addresses {
121-
if state.is_addressed_used(address).await? {
119+
if state.is_stake_address_used(address).await? {
122120
cip509.report().functional_validation(
123-
&format!("{address} addresses is already used"),
124-
"It isn't allowed to use same address in multiple registration chains, if its not a new chain",
121+
&format!("{address} stake address is already used"),
122+
"It isn't allowed to use same stake address in multiple registration chains, if its not a new chain",
125123
);
126124
}
127125
}
@@ -313,12 +311,6 @@ impl RegistrationChain {
313311
.and_then(|rdr| rdr.encryption_key_from_rotation(rotation))
314312
}
315313

316-
/// Returns all addresses associated to this chain.
317-
#[must_use]
318-
pub fn addresses(&self) -> HashSet<Address> {
319-
self.inner.certificate_uris.addresses()
320-
}
321-
322314
/// Returns all stake addresses associated to this chain.
323315
#[must_use]
324316
pub fn stake_addresses(&self) -> HashSet<StakeAddress> {

0 commit comments

Comments
 (0)