Skip to content

Commit 2afd1ff

Browse files
Move Cip0134Uri to the cardano-blockchain-types crate
1 parent b3be9b0 commit 2afd1ff

File tree

7 files changed

+39
-38
lines changed

7 files changed

+39
-38
lines changed

rust/rbac-registration/src/cardano/cip509/utils/cip134/uri.rs renamed to rust/cardano-blockchain-types/src/cip134_uri.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ use std::fmt::{Display, Formatter};
88
use anyhow::{anyhow, Context, Error, Result};
99
use pallas::ledger::addresses::Address;
1010

11-
use crate::utils::general::decode_utf8;
12-
1311
/// An URI in the CIP-0134 format.
1412
///
1513
/// See the [proposal] for more details.
@@ -33,7 +31,7 @@ impl Cip0134Uri {
3331
/// # Examples
3432
///
3533
/// ```
36-
/// use rbac_registration::cardano::cip509::utils::Cip0134Uri;
34+
/// use cardano_blockchain_types::Cip0134Uri;
3735
///
3836
/// let uri = "web+cardano://addr/stake1uyehkck0lajq8gr28t9uxnuvgcqrc6070x3k9r8048z8y5gh6ffgw";
3937
/// let cip0134_uri = Cip0134Uri::parse(uri).unwrap();
@@ -55,7 +53,7 @@ impl Cip0134Uri {
5553
/// # Examples
5654
///
5755
/// ```
58-
/// use rbac_registration::cardano::cip509::utils::Cip0134Uri;
56+
/// use cardano_blockchain_types::Cip0134Uri;
5957
///
6058
/// let uri = "web+cardano://addr/stake1uyehkck0lajq8gr28t9uxnuvgcqrc6070x3k9r8048z8y5gh6ffgw";
6159
/// let cip0134_uri = Cip0134Uri::parse(uri).unwrap();
@@ -71,8 +69,8 @@ impl Cip0134Uri {
7169
/// # Examples
7270
///
7371
/// ```
72+
/// use cardano_blockchain_types::Cip0134Uri;
7473
/// use pallas::ledger::addresses::{Address, Network};
75-
/// use rbac_registration::cardano::cip509::utils::Cip0134Uri;
7674
///
7775
/// let uri = "web+cardano://addr/stake1uyehkck0lajq8gr28t9uxnuvgcqrc6070x3k9r8048z8y5gh6ffgw";
7876
/// let cip0134_uri = Cip0134Uri::parse(uri).unwrap();
@@ -97,8 +95,9 @@ impl TryFrom<&[u8]> for Cip0134Uri {
9795
type Error = Error;
9896

9997
fn try_from(value: &[u8]) -> Result<Self> {
100-
let address = decode_utf8(value).context("Unable to convert bytes to string")?;
101-
Self::parse(&address)
98+
let address = std::str::from_utf8(value)
99+
.with_context(|| format!("Invalid utf8 string: '{value:?}'"))?;
100+
Self::parse(address)
102101
}
103102
}
104103

rust/cardano-blockchain-types/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub mod conversion;
44
pub mod hashes;
55

66
mod auxdata;
7+
mod cip134_uri;
78
mod fork;
89
mod multi_era_block_data;
910
mod network;
@@ -20,6 +21,7 @@ pub use auxdata::{
2021
metadatum_value::MetadatumValue,
2122
scripts::{Script, ScriptArray, ScriptType, TransactionScripts},
2223
};
24+
pub use cip134_uri::Cip0134Uri;
2325
pub use fork::Fork;
2426
pub use multi_era_block_data::MultiEraBlock;
2527
pub use network::Network;

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

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -168,23 +168,30 @@ impl Cip509 {
168168
}
169169
}
170170

171-
/// Returns a registration purpose.
172-
#[must_use]
173-
pub fn purpose(&self) -> Option<Uuid> {
174-
self.purpose
175-
}
176-
177-
/// Returns an identifier of the previous transaction.
178-
#[must_use]
179-
pub fn previous_transaction(&self) -> Option<&Blake2b256Hash> {
180-
self.prv_tx_id.as_ref()
181-
}
182-
183-
/// Returns CIP509 metadata.
184-
#[must_use]
185-
pub fn metadata(&self) -> Option<&Cip509RbacMetadata> {
186-
self.metadata.as_ref()
187-
}
171+
// TODO: FIXME: Consume fields in the registration chain, use methods everywhere else.
172+
// /// Returns a registration purpose.
173+
// #[must_use]
174+
// pub fn purpose(&self) -> Option<Uuid> {
175+
// self.purpose
176+
// }
177+
//
178+
// // TODO: FIXME:
179+
// // txn_inputs_hash?
180+
//
181+
// /// Returns an identifier of the previous transaction.
182+
// #[must_use]
183+
// pub fn previous_transaction(&self) -> Option<&Blake2b256Hash> {
184+
// self.prv_tx_id.as_ref()
185+
// }
186+
//
187+
// /// Returns CIP509 metadata.
188+
// #[must_use]
189+
// pub fn metadata(&self) -> Option<&Cip509RbacMetadata> {
190+
// self.metadata.as_ref()
191+
// }
192+
//
193+
// // TODO: FIXME:
194+
// // validation_signature?
188195
}
189196

190197
impl Decode<'_, ProblemReport> for Cip509 {

rust/rbac-registration/src/cardano/cip509/utils/cip134/mod.rs

Lines changed: 0 additions & 7 deletions
This file was deleted.

rust/rbac-registration/src/cardano/cip509/utils/cip134/uri_set.rs renamed to rust/rbac-registration/src/cardano/cip509/utils/cip134_uri_set.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use c509_certificate::{
77
general_names::general_name::{GeneralNameTypeRegistry, GeneralNameValue},
88
C509ExtensionType,
99
};
10+
use cardano_blockchain_types::Cip0134Uri;
1011
use catalyst_types::problem_report::ProblemReport;
1112
use der_parser::der::parse_der_sequence;
1213
use tracing::debug;
@@ -17,7 +18,6 @@ use crate::cardano::cip509::{
1718
certs::{C509Cert, X509DerCert},
1819
Cip509RbacMetadata,
1920
},
20-
utils::Cip0134Uri,
2121
validation::URI,
2222
};
2323

@@ -281,8 +281,7 @@ mod tests {
281281
#[allow(clippy::indexing_slicing)]
282282
#[test]
283283
fn set_new() {
284-
let block =
285-
hex::decode(include_str!("../../../../test_data/cardano/conway_1.block")).unwrap();
284+
let block = hex::decode(include_str!("../../../test_data/cardano/conway_1.block")).unwrap();
286285
let block = MultiEraBlock::decode(&block).unwrap();
287286
let tx = &block.txs()[3];
288287
let cip509 = cip509(tx);
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Utility functions for CIP-509
22
33
pub mod cip19;
4-
pub use cip134::{Cip0134Uri, Cip0134UriSet};
54

6-
mod cip134;
5+
pub use cip134_uri_set::Cip0134UriSet;
6+
7+
mod cip134_uri_set;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ fn extract_stake_addresses(cip509: &Cip509) -> Vec<Vec<u8>> {
183183
.certificate_uris
184184
.x_uris()
185185
.iter()
186-
.chain(cip509.metadata.certificate_uris.c_uris())
186+
.chain(metadata.certificate_uris.c_uris())
187187
.flat_map(|(_index, uris)| uris.iter())
188188
.filter_map(|uri| {
189189
if let Address::Stake(a) = uri.address() {
@@ -565,7 +565,7 @@ mod tests {
565565
let cip509 = Cip509::decode(&mut decoder, &mut report).expect("Failed to decode Cip509");
566566
assert!(!report.is_problematic());
567567

568-
let addresses = extract_stake_addresses(&cip);
568+
let addresses = extract_stake_addresses(&cip509);
569569
// TODO: FIXME:
570570
todo!();
571571
}

0 commit comments

Comments
 (0)