Skip to content

Commit ef23920

Browse files
committed
rename state to Provider
1 parent f150a40 commit ef23920

File tree

3 files changed

+37
-39
lines changed

3 files changed

+37
-39
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
//! Cardano module
22
33
pub mod cip509;
4-
pub mod state;
4+
pub mod provider;
Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
//! Cardano RBAC state traits, which are used during different stateful validation
2-
//! procedures.
1+
//! Cardano RBAC provider trait, which are used during different stateful validation procedures.
32
43
use std::future::Future;
54

@@ -9,8 +8,8 @@ use ed25519_dalek::VerifyingKey;
98

109
use crate::registration::cardano::RegistrationChain;
1110

12-
/// RBAC chains state trait
13-
pub trait RbacChainsState {
11+
/// RBAC chains provider trait
12+
pub trait RbacChainsProvider: Send + Sync {
1413
/// Returns RBAC chain for the given Catalyst ID.
1514
fn chain(
1615
&self,
@@ -21,28 +20,33 @@ pub trait RbacChainsState {
2120
fn is_chain_known(
2221
&self,
2322
id: &CatalystId,
24-
) -> impl Future<Output = anyhow::Result<bool>> + Send;
23+
) -> impl Future<Output = anyhow::Result<bool>> + Send {
24+
async { self.chain(id).await.map(|v| v.is_some()) }
25+
}
26+
27+
/// Returns the Catalyst ID associated with the RBAC chain for the given stake
28+
/// address.
29+
fn chain_catalyst_id_from_stake_address(
30+
&self,
31+
addr: &StakeAddress,
32+
) -> impl Future<Output = anyhow::Result<Option<CatalystId>>> + Send;
2533

2634
/// Returns `true` if a provided address already used by any RBAC chain.
2735
fn is_stake_address_used(
2836
&self,
2937
addr: &StakeAddress,
30-
) -> impl Future<Output = anyhow::Result<bool>> + Send;
31-
32-
/// Returns the Catalyst ID associated with the RBAC chain for the given signing public key
33-
/// signing public key.
38+
) -> impl Future<Output = anyhow::Result<bool>> + Send {
39+
async {
40+
self.chain_catalyst_id_from_stake_address(addr)
41+
.await
42+
.map(|v| v.is_some())
43+
}
44+
}
45+
46+
/// Returns the Catalyst ID associated with the RBAC chain for the given signing
47+
/// public key.
3448
fn chain_catalyst_id_from_signing_public_key(
3549
&self,
3650
key: &VerifyingKey,
3751
) -> impl Future<Output = anyhow::Result<Option<CatalystId>>> + Send;
38-
39-
/// Update currently assosiated with the stake addresses chains by "taking" the given `StakeAddress` for the corresponding
40-
/// RBAC chain's by the given `CatalystId`.
41-
fn take_stake_address_from_chains<I>(
42-
&mut self,
43-
addresses: I,
44-
) -> impl Future<Output = anyhow::Result<()>> + Send
45-
where
46-
I: IntoIterator<Item = StakeAddress> + Send,
47-
<I as IntoIterator>::IntoIter: Send;
4852
}

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

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::cardano::{
2727
CertKeyHash, CertOrPk, Cip0134UriSet, Cip509, PaymentHistory, PointData, PointTxnIdx,
2828
RoleData, RoleDataRecord, ValidationSignature,
2929
},
30-
state::RbacChainsState,
30+
provider::RbacChainsProvider,
3131
};
3232

3333
/// Registration chains.
@@ -50,12 +50,10 @@ impl RegistrationChain {
5050
/// # Errors
5151
/// - Propagates any I/O or provider-level errors encountered while checking key
5252
/// ownership (e.g., database lookup failures).
53-
pub async fn new<State>(
53+
pub async fn new(
5454
cip509: &Cip509,
55-
state: &mut State,
55+
provider: &impl RbacChainsProvider,
5656
) -> anyhow::Result<Option<Self>>
57-
where
58-
State: RbacChainsState,
5957
{
6058
let Some(new_chain) = Self::new_stateless(cip509) else {
6159
return Ok(None);
@@ -64,24 +62,20 @@ impl RegistrationChain {
6462
// Verify that a Catalyst ID of this chain is unique.
6563
{
6664
let cat_id = new_chain.catalyst_id();
67-
if state.is_chain_known(cat_id).await? {
65+
if provider.is_chain_known(cat_id).await? {
6866
cip509.report().functional_validation(
6967
&format!("{} is already used", cat_id.as_short_id()),
7068
"It isn't allowed to use same Catalyst ID (certificate subject public key) in multiple registration chains",
7169
);
7270
}
7371

74-
check_signing_public_key(cat_id, cip509, state).await?;
72+
check_signing_public_key(cat_id, cip509, provider).await?;
7573
}
7674

7775
if cip509.report().is_problematic() {
7876
return Ok(None);
7977
}
8078

81-
state
82-
.take_stake_address_from_chains(cip509.stake_addresses())
83-
.await?;
84-
8579
Ok(Some(new_chain))
8680
}
8781

@@ -108,13 +102,11 @@ impl RegistrationChain {
108102
/// # Errors
109103
/// - Propagates any I/O or provider-level errors encountered while checking key
110104
/// ownership (e.g., database lookup failures).
111-
pub async fn update<State>(
105+
pub async fn update(
112106
&self,
113107
cip509: &Cip509,
114-
state: &State,
108+
provider: &impl RbacChainsProvider,
115109
) -> anyhow::Result<Option<Self>>
116-
where
117-
State: RbacChainsState,
118110
{
119111
let Some(new_chain) = self.update_stateless(cip509) else {
120112
return Ok(None);
@@ -123,17 +115,19 @@ impl RegistrationChain {
123115
// Check that addresses from the new registration aren't used in other chains.
124116
let previous_stake_addresses = self.stake_addresses();
125117
let reg_stake_addresses = cip509.stake_addresses();
126-
let new_stake_addresses: Vec<_> = reg_stake_addresses.difference(&previous_stake_addresses).collect();
118+
let new_stake_addresses: Vec<_> = reg_stake_addresses
119+
.difference(&previous_stake_addresses)
120+
.collect();
127121
for address in &new_stake_addresses {
128-
if state.is_stake_address_used(address).await? {
122+
if provider.is_stake_address_used(address).await? {
129123
cip509.report().functional_validation(
130124
&format!("{address} stake address is already used"),
131125
"It isn't allowed to use same stake address in multiple registration chains, if its not a new chain",
132126
);
133127
}
134128
}
135129

136-
check_signing_public_key(self.catalyst_id(), cip509, state).await?;
130+
check_signing_public_key(self.catalyst_id(), cip509, provider).await?;
137131

138132
if cip509.report().is_problematic() {
139133
Ok(None)
@@ -737,7 +731,7 @@ async fn check_signing_public_key<State>(
737731
state: &State,
738732
) -> anyhow::Result<()>
739733
where
740-
State: RbacChainsState,
734+
State: RbacChainsProvider,
741735
{
742736
for role in cip509.all_roles() {
743737
if let Some(key) = cip509.signing_public_key_for_role(role)

0 commit comments

Comments
 (0)