Skip to content

Commit 0f1ed38

Browse files
committed
chore: return success object
1 parent be739fb commit 0f1ed38

File tree

2 files changed

+30
-68
lines changed

2 files changed

+30
-68
lines changed

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

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@ use cardano_blockchain_types::{
1515
pallas_traverse::MultiEraTx,
1616
MetadatumLabel, MultiEraBlock, TxnIndex,
1717
};
18-
use cardano_chain_follower::StakeAddress;
1918
use catalyst_types::{
2019
catalyst_id::{role_index::RoleId, CatalystId},
2120
cbor_utils::{report_duplicated_key, report_missing_keys},
2221
problem_report::ProblemReport,
2322
uuid::UuidV4,
2423
};
2524
use cbork_utils::decode_helper::{decode_bytes, decode_helper, decode_map_len};
26-
use ed25519_dalek::VerifyingKey;
2725
use minicbor::{
2826
decode::{self},
2927
Decode, Decoder,
@@ -84,15 +82,6 @@ pub struct Cip509 {
8482
///
8583
/// This field is only present in role 0 registrations.
8684
catalyst_id: Option<CatalystId>,
87-
/// A list of stake addresses that were added to the chain.
88-
stake_addresses: HashSet<StakeAddress>,
89-
/// A list of role public keys used in this registration.
90-
public_keys: HashSet<VerifyingKey>,
91-
/// A list of updates to other chains containing Catalyst IDs and removed stake
92-
/// addresses.
93-
///
94-
/// A new RBAC registration can take ownership of stake addresses of other chains.
95-
modified_chains: Vec<(CatalystId, HashSet<StakeAddress>)>,
9685
/// Raw aux data associated with the transaction that CIP509 is attached to,
9786
raw_aux_data: Vec<u8>,
9887
/// A report potentially containing all the issues occurred during `Cip509` decoding
@@ -219,23 +208,6 @@ impl Cip509 {
219208
result
220209
}
221210

222-
/// Updates and replaces information once it being processed by calling either
223-
/// `update_chain` or `start_new_chain`.
224-
#[must_use]
225-
pub(crate) fn put_validation_result(
226-
self,
227-
stake_addresses: HashSet<StakeAddress>,
228-
public_keys: HashSet<VerifyingKey>,
229-
modified_chains: Vec<(CatalystId, HashSet<StakeAddress>)>,
230-
) -> Self {
231-
Self {
232-
stake_addresses,
233-
public_keys,
234-
modified_chains,
235-
..self
236-
}
237-
}
238-
239211
/// Returns all role numbers present in this `Cip509` instance.
240212
#[must_use]
241213
pub fn all_roles(&self) -> Vec<RoleId> {
@@ -303,24 +275,6 @@ impl Cip509 {
303275
self.catalyst_id.as_ref()
304276
}
305277

306-
/// Returns stake addresses processed from either `update_chain` or `start_new_chain`.
307-
#[must_use]
308-
pub fn stake_addresses(&self) -> &HashSet<StakeAddress> {
309-
&self.stake_addresses
310-
}
311-
312-
/// Returns public keys processed from either `update_chain` or `start_new_chain`.
313-
#[must_use]
314-
pub fn public_keys(&self) -> &HashSet<VerifyingKey> {
315-
&self.public_keys
316-
}
317-
318-
/// Returns modified chains from either `update_chain` or `start_new_chain`.
319-
#[must_use]
320-
pub fn modified_chains(&self) -> &Vec<(CatalystId, HashSet<StakeAddress>)> {
321-
&self.modified_chains
322-
}
323-
324278
/// Returns a list of addresses extracted from certificate URIs of a specific role.
325279
#[must_use]
326280
pub fn certificate_addresses(
@@ -495,9 +449,6 @@ impl Decode<'_, DecodeContext<'_, '_>> for Cip509 {
495449
txn_hash,
496450
origin: decode_context.origin.clone(),
497451
catalyst_id: None,
498-
stake_addresses: HashSet::new(),
499-
public_keys: HashSet::new(),
500-
modified_chains: Vec::new(),
501452
raw_aux_data: Vec::new(),
502453
report: decode_context.report.clone(),
503454
})

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

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::{
1818
};
1919

2020
/// A return value of the `validate_rbac_registration` method.
21-
pub type RbacValidationResult = Result<(RegistrationChain, Cip509), RbacValidationError>;
21+
pub type RbacValidationResult = Result<RbacValidationSuccess, RbacValidationError>;
2222

2323
/// An error returned from the `validate_rbac_registration` method.
2424
#[allow(clippy::large_enum_variant)]
@@ -53,6 +53,21 @@ impl From<anyhow::Error> for RbacValidationError {
5353
}
5454
}
5555

56+
/// Represents the result yielded by `update_chain` or `start_new_chain` upon successful execution.
57+
pub struct RbacValidationSuccess {
58+
/// A list of stake addresses that were added to the chain.
59+
pub stake_addresses: HashSet<StakeAddress>,
60+
/// A list of role public keys used in this registration.
61+
pub public_keys: HashSet<VerifyingKey>,
62+
/// A list of updates to other chains containing Catalyst IDs and removed stake
63+
/// addresses.
64+
///
65+
/// A new RBAC registration can take ownership of stake addresses of other chains.
66+
pub modified_chains: Vec<(CatalystId, HashSet<StakeAddress>)>,
67+
/// An updated registration chain.
68+
pub chain: RegistrationChain,
69+
}
70+
5671
/// Attempts to update an existing RBAC registration chain
5772
/// with a new CIP-509 registration, validating address and key usage consistency.
5873
///
@@ -134,16 +149,14 @@ where
134149
});
135150
}
136151

137-
Ok((
138-
new_chain,
139-
reg.put_validation_result(
140-
stake_addresses,
141-
public_keys,
142-
// Only new chains can take ownership of stake addresses of existing chains, so in this
143-
// case other chains aren't affected.
144-
Vec::new(),
145-
),
146-
))
152+
Ok(RbacValidationSuccess {
153+
stake_addresses,
154+
public_keys,
155+
// Only new chains can take ownership of stake addresses of existing chains, so in this
156+
// case other chains aren't affected.
157+
modified_chains: Vec::new(),
158+
chain: new_chain,
159+
})
147160
}
148161

149162
/// Attempts to initialize a new RBAC registration chain
@@ -246,14 +259,12 @@ where
246259
});
247260
}
248261

249-
Ok((
250-
new_chain,
251-
reg.put_validation_result(
252-
new_addresses,
253-
public_keys,
254-
updated_chains.into_iter().collect(),
255-
),
256-
))
262+
Ok(RbacValidationSuccess {
263+
stake_addresses: new_addresses,
264+
public_keys,
265+
modified_chains: updated_chains.into_iter().collect(),
266+
chain: new_chain,
267+
})
257268
}
258269

259270
/// Validates that none of the signing keys in a given RBAC registration chain

0 commit comments

Comments
 (0)