Skip to content

Commit fecdd65

Browse files
Update UUID names
1 parent 596b47d commit fecdd65

File tree

3 files changed

+23
-24
lines changed

3 files changed

+23
-24
lines changed

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

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use cardano_blockchain_types::{MetadatumLabel, MultiEraBlock, TxnIndex};
99
use catalyst_types::{
1010
hashes::{Blake2b256Hash, BLAKE_2B256_SIZE},
1111
problem_report::ProblemReport,
12-
uuid::V4,
12+
uuid::UuidV4,
1313
};
1414
use cbork_utils::decode_helper::{decode_bytes, decode_helper, decode_map_len};
1515
use minicbor::{
@@ -55,7 +55,7 @@ pub struct Cip509 {
5555
/// A registration purpose (`UUIDv4`).
5656
///
5757
/// The purpose is defined by the consuming dApp.
58-
purpose: Option<V4>,
58+
purpose: Option<UuidV4>,
5959
/// Transaction inputs hash.
6060
txn_inputs_hash: Option<TxInputHash>,
6161
/// An optional hash of the previous transaction.
@@ -247,7 +247,7 @@ impl Cip509 {
247247
/// # Errors
248248
///
249249
/// - `Err(ProblemReport)`
250-
pub fn consume(self) -> Result<(V4, Cip509RbacMetadata, PaymentHistory), ProblemReport> {
250+
pub fn consume(self) -> Result<(UuidV4, Cip509RbacMetadata, PaymentHistory), ProblemReport> {
251251
match (
252252
self.purpose,
253253
self.txn_inputs_hash,
@@ -436,7 +436,7 @@ fn payment_history(
436436
/// Decodes purpose.
437437
fn decode_purpose(
438438
d: &mut Decoder, context: &str, report: &ProblemReport,
439-
) -> Result<Option<V4>, ()> {
439+
) -> Result<Option<UuidV4>, ()> {
440440
let bytes = match decode_bytes(d, "Cip509 purpose") {
441441
Ok(v) => v,
442442
Err(e) => {
@@ -455,17 +455,12 @@ fn decode_purpose(
455455
);
456456
return Ok(None);
457457
};
458-
let uuid = V4::from(uuid);
459-
if uuid.is_valid() {
460-
Ok(Some(uuid))
461-
} else {
462-
report.invalid_value(
463-
"purpose",
464-
&format!("{uuid:?}"),
465-
"Invalid UUID version, UuidV4 expected",
466-
context,
467-
);
468-
Ok(None)
458+
match UuidV4::try_from(uuid) {
459+
Ok(v) => Ok(Some(v)),
460+
Err(e) => {
461+
report.other(&format!("Invalid purpose UUID: {e:?}"), context);
462+
Ok(None)
463+
},
469464
}
470465
}
471466

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{collections::HashMap, sync::Arc};
44

55
use anyhow::bail;
66
use c509_certificate::c509::C509;
7-
use catalyst_types::{hashes::Blake2b256Hash, uuid::V4};
7+
use catalyst_types::{hashes::Blake2b256Hash, uuid::UuidV4};
88
use ed25519_dalek::VerifyingKey;
99
use tracing::{error, warn};
1010
use x509_cert::certificate::Certificate as X509Certificate;
@@ -63,7 +63,7 @@ impl RegistrationChain {
6363

6464
/// Get a list of purpose for this registration chain.
6565
#[must_use]
66-
pub fn purpose(&self) -> &[V4] {
66+
pub fn purpose(&self) -> &[UuidV4] {
6767
&self.inner.purpose
6868
}
6969

@@ -110,7 +110,7 @@ struct RegistrationChainInner {
110110
/// The current transaction ID hash (32 bytes)
111111
current_tx_id_hash: Blake2b256Hash,
112112
/// List of purpose for this registration chain
113-
purpose: Vec<V4>,
113+
purpose: Vec<UuidV4>,
114114

115115
// RBAC
116116
/// Map of index in array to point, transaction index, and x509 certificate.

rust/rbac-registration/src/utils/test.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// cspell: words stake_test1urs8t0ssa3w9wh90ld5tprp3gurxd487rth2qlqk6ernjqcef4ugr
44

55
use cardano_blockchain_types::{MultiEraBlock, Network, Point, Slot, TxnIndex};
6-
use catalyst_types::{hashes::Blake2b256Hash, uuid::V4};
6+
use catalyst_types::{hashes::Blake2b256Hash, uuid::UuidV4};
77
use uuid::Uuid;
88

99
use crate::cardano::cip509::{Cip509, RoleNumber};
@@ -24,7 +24,7 @@ pub struct BlockTestData {
2424
/// Previous hash.
2525
pub prv_hash: Option<Blake2b256Hash>,
2626
/// Purpose.
27-
pub purpose: V4,
27+
pub purpose: UuidV4,
2828
/// Stake address.
2929
pub stake_addr: Option<String>,
3030
}
@@ -71,7 +71,8 @@ pub fn block_1() -> BlockTestData {
7171
purpose: "ca7a1457-ef9f-4c7f-9c74-7f8c4a4cfa6c"
7272
.parse::<Uuid>()
7373
.unwrap()
74-
.into(),
74+
.try_into()
75+
.unwrap(),
7576
stake_addr: Some(
7677
"stake_test1urs8t0ssa3w9wh90ld5tprp3gurxd487rth2qlqk6ernjqcef4ugr".to_string(),
7778
),
@@ -107,7 +108,8 @@ pub fn block_2() -> BlockTestData {
107108
purpose: "ca7a1457-ef9f-4c7f-9c74-7f8c4a4cfa6c"
108109
.parse::<Uuid>()
109110
.unwrap()
110-
.into(),
111+
.try_into()
112+
.unwrap(),
111113
stake_addr: None,
112114
}
113115
}
@@ -141,7 +143,8 @@ pub fn block_3() -> BlockTestData {
141143
purpose: "ca7a1457-ef9f-4c7f-9c74-7f8c4a4cfa6c"
142144
.parse::<Uuid>()
143145
.unwrap()
144-
.into(),
146+
.try_into()
147+
.unwrap(),
145148
stake_addr: Some(
146149
"stake_test1urs8t0ssa3w9wh90ld5tprp3gurxd487rth2qlqk6ernjqcef4ugr"
147150
.parse()
@@ -174,7 +177,8 @@ pub fn block_4() -> BlockTestData {
174177
purpose: "ca7a1457-ef9f-4c7f-9c74-7f8c4a4cfa6c"
175178
.parse::<Uuid>()
176179
.unwrap()
177-
.into(),
180+
.try_into()
181+
.unwrap(),
178182
stake_addr: Some(
179183
"stake_test1urs8t0ssa3w9wh90ld5tprp3gurxd487rth2qlqk6ernjqcef4ugr".to_string(),
180184
),

0 commit comments

Comments
 (0)