Skip to content

Commit ac4093c

Browse files
apskhemMr-Leshiy
andauthored
feat(rust/rbac-registration): Add provider trait for RegistrationChain (#586)
* initial * feat: provider * feat: update chain * feat: start_new_chain * feat: merge validation result struct into cip509 * feat: exports * feat: return new chain * chore: return success object * fix: older version * feat: cat id in payload * fix: new version * chore: lintfix * chore: remove persistent arguments * tmp * chore: complete moving to central module * feat: ref fn * chore: merge methods * chore: minor * feat: export modified chains * chore: minor comment * chore: rbac update logic * chore: isolation * chore: validation and lintfix * docs: remove error doc * chore: minor refactor * fix: comments * chore: validation function return * Update rust/rbac-registration/src/providers.rs Co-authored-by: Alex Pozhylenkov <[email protected]> --------- Co-authored-by: Alex Pozhylenkov <[email protected]>
1 parent b703f01 commit ac4093c

File tree

4 files changed

+304
-47
lines changed

4 files changed

+304
-47
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use cardano_blockchain_types::{
1313
pallas_addresses::{Address, ShelleyAddress},
1414
pallas_primitives::{conway, Nullable},
1515
pallas_traverse::MultiEraTx,
16-
MetadatumLabel, MultiEraBlock, TxnIndex,
16+
MetadatumLabel, MultiEraBlock, StakeAddress, TxnIndex,
1717
};
1818
use catalyst_types::{
1919
catalyst_id::{role_index::RoleId, CatalystId},
@@ -305,6 +305,14 @@ impl Cip509 {
305305
self.metadata.as_ref()
306306
}
307307

308+
/// Returns a set of stake addresses.
309+
#[must_use]
310+
pub fn stake_addresses(&self) -> HashSet<StakeAddress> {
311+
self.certificate_uris()
312+
.map(Cip0134UriSet::stake_addresses)
313+
.unwrap_or_default()
314+
}
315+
308316
/// Returns `Cip509` fields consuming the structure if it was successfully decoded and
309317
/// validated otherwise return the problem report that contains all the encountered
310318
/// issues.

rust/rbac-registration/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! This crate provides functionalities for RBAC registration.
22
33
pub mod cardano;
4+
pub mod providers;
45
pub mod registration;
56

67
mod utils;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//! Providers traits, which are used during different validation procedures.
2+
3+
use std::future::Future;
4+
5+
use cardano_blockchain_types::{hashes::TransactionId, StakeAddress};
6+
use catalyst_types::catalyst_id::CatalystId;
7+
use ed25519_dalek::VerifyingKey;
8+
9+
use crate::registration::cardano::RegistrationChain;
10+
11+
/// `RegistrationChain` Provider trait
12+
pub trait RbacRegistrationProvider {
13+
/// Returns registration chain
14+
/// for the given Catalyst ID.
15+
fn chain(
16+
&self,
17+
id: CatalystId,
18+
) -> impl Future<Output = anyhow::Result<Option<RegistrationChain>>> + Send;
19+
20+
/// Returns `true` if a chain with the given Catalyst ID already exists.
21+
///
22+
/// This function behaves in the same way as `latest_rbac_chain(...).is_some()` but
23+
/// the implementation is more optimized because we don't need to build the whole
24+
/// chain.
25+
fn is_chain_known(
26+
&self,
27+
id: CatalystId,
28+
) -> impl Future<Output = anyhow::Result<bool>> + Send;
29+
30+
/// Returns a Catalyst ID corresponding to the given stake address.
31+
fn catalyst_id_from_stake_address(
32+
&self,
33+
address: &StakeAddress,
34+
) -> impl Future<Output = anyhow::Result<Option<CatalystId>>> + Send;
35+
36+
/// Returns a Catalyst ID corresponding to the given public key.
37+
fn catalyst_id_from_public_key(
38+
&self,
39+
key: VerifyingKey,
40+
) -> impl Future<Output = anyhow::Result<Option<CatalystId>>> + Send;
41+
42+
/// Returns a Catalyst ID corresponding to the given transaction hash.
43+
fn catalyst_id_from_txn_id(
44+
&self,
45+
txn_id: TransactionId,
46+
) -> impl Future<Output = anyhow::Result<Option<CatalystId>>> + Send;
47+
}

0 commit comments

Comments
 (0)