Skip to content

Commit 1100dd2

Browse files
committed
remove ulid from immutable ledger crate
1 parent 63a7d60 commit 1100dd2

File tree

2 files changed

+26
-32
lines changed

2 files changed

+26
-32
lines changed

rust/immutable-ledger/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ license.workspace = true
1111
ed25519-dalek = "2.1.1"
1212
anyhow = "1.0.86"
1313
minicbor = { version = "0.24", features = ["std"] }
14-
uuid = { version = "1.10.0", features = ["v4", "serde"] }
15-
ulid = { version = "1.1.3", features = ["serde", "uuid"] }
14+
uuid = { version = "1.10.0", features = ["v4", "v7", "serde"] }
1615
hex = "0.4.3"
1716
blake2b_simd = "1.0.2"
1817
blake3 = "=0.1.3"

rust/immutable-ledger/src/serialize.rs

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
55
use anyhow::{bail, Ok};
66
use blake2b_simd::{self, Params};
7-
use ulid::Ulid;
87
use uuid::Uuid;
98

109
/// Genesis block MUST have 0 value height.
@@ -70,9 +69,6 @@ const TIMESTAMP_CBOR_TAG: u64 = 1;
7069
/// CBOR tag for UUID
7170
const UUID_CBOR_TAG: u64 = 37;
7271

73-
/// CBOR tag for UUID
74-
const ULID_CBOR_TAG: u64 = 32780;
75-
7672
/// CBOR tags for BLAKE2 and BLAKE3 hash functions
7773
/// `https://github.com/input-output-hk/catalyst-voices/blob/main/docs/src/catalyst-standards/cbor_tags/blake.md`
7874
@@ -292,7 +288,7 @@ impl Block {
292288
#[derive(Debug, Clone, PartialEq)]
293289
pub struct BlockHeader {
294290
/// Unique identifier of the chain.
295-
pub chain_id: Ulid,
291+
pub chain_id: Uuid,
296292
/// Block height.
297293
pub height: i64,
298294
/// Block epoch-based date/time.
@@ -305,7 +301,7 @@ pub struct BlockHeader {
305301
pub ledger_type: Uuid,
306302
/// unique identifier of the purpose, each Ledger instance will have a strict time
307303
/// boundaries, so each of them will run for different purposes.
308-
pub purpose_id: Ulid,
304+
pub purpose_id: Uuid,
309305
/// Identifier or identifiers of the entity who was produced and processed a block.
310306
pub validator: Vec<Kid>,
311307
/// Add arbitrary metadata to the block.
@@ -317,8 +313,8 @@ impl BlockHeader {
317313
#[must_use]
318314
#[allow(clippy::too_many_arguments)]
319315
pub fn new(
320-
chain_id: Ulid, height: i64, block_time_stamp: i64,
321-
previous_block_hash: (HashFunction, Vec<u8>), ledger_type: Uuid, purpose_id: Ulid,
316+
chain_id: Uuid, height: i64, block_time_stamp: i64,
317+
previous_block_hash: (HashFunction, Vec<u8>), ledger_type: Uuid, purpose_id: Uuid,
322318
validator: Vec<Kid>, metadata: Vec<u8>,
323319
) -> Self {
324320
Self {
@@ -347,8 +343,8 @@ impl BlockHeader {
347343
encoder.array(BLOCK_HEADER_SIZE)?;
348344

349345
// Chain id
350-
encoder.tag(minicbor::data::Tag::new(ULID_CBOR_TAG))?;
351-
encoder.bytes(&self.chain_id.to_bytes())?;
346+
encoder.tag(minicbor::data::Tag::new(UUID_CBOR_TAG))?;
347+
encoder.bytes(self.chain_id.as_bytes())?;
352348

353349
// Block height
354350
encoder.int(self.height.into())?;
@@ -372,8 +368,8 @@ impl BlockHeader {
372368
encoder.bytes(self.ledger_type.as_bytes())?;
373369

374370
// Purpose id
375-
encoder.tag(minicbor::data::Tag::new(ULID_CBOR_TAG))?;
376-
encoder.bytes(&self.purpose_id.to_bytes())?;
371+
encoder.tag(minicbor::data::Tag::new(UUID_CBOR_TAG))?;
372+
encoder.bytes(self.purpose_id.as_bytes())?;
377373

378374
// Validators
379375
encoder.array(self.validator.len().try_into()?)?;
@@ -405,7 +401,7 @@ impl BlockHeader {
405401

406402
// Raw chain_id
407403
cbor_decoder.tag()?;
408-
let chain_id = Ulid::from_bytes(
404+
let chain_id = Uuid::from_bytes(
409405
cbor_decoder
410406
.bytes()
411407
.map_err(|e| anyhow::anyhow!(format!("Invalid cbor for chain id : {e}")))?
@@ -443,7 +439,7 @@ impl BlockHeader {
443439

444440
// Raw purpose id
445441
cbor_decoder.tag()?;
446-
let purpose_id = Ulid::from_bytes(
442+
let purpose_id = Uuid::from_bytes(
447443
cbor_decoder
448444
.bytes()
449445
.map_err(|e| anyhow::anyhow!(format!("Invalid cbor for purpose id : {e}")))?
@@ -489,7 +485,7 @@ impl BlockHeader {
489485
/// Genesis block previous identifier type i.e hash of itself
490486
pub struct GenesisPreviousHash {
491487
/// Unique identifier of the chain.
492-
pub chain_id: Ulid,
488+
pub chain_id: Uuid,
493489
/// Block epoch-based date/time.
494490
pub block_time_stamp: i64,
495491
/// unique identifier of the ledger type.
@@ -498,7 +494,7 @@ pub struct GenesisPreviousHash {
498494
pub ledger_type: Uuid,
499495
/// unique identifier of the purpose, each Ledger instance will have a strict time
500496
/// boundaries, so each of them will run for different purposes.
501-
pub purpose_id: Ulid,
497+
pub purpose_id: Uuid,
502498
/// Identifier or identifiers of the entity who was produced and processed a block.
503499
pub validator: Vec<Kid>,
504500
}
@@ -507,7 +503,7 @@ impl GenesisPreviousHash {
507503
/// Create previous block id
508504
#[must_use]
509505
pub fn new(
510-
chain_id: Ulid, block_time_stamp: i64, ledger_type: Uuid, purpose_id: Ulid,
506+
chain_id: Uuid, block_time_stamp: i64, ledger_type: Uuid, purpose_id: Uuid,
511507
validator: Vec<Kid>,
512508
) -> Self {
513509
Self {
@@ -532,8 +528,8 @@ impl GenesisPreviousHash {
532528
encoder.array(GENESIS_TO_PREV_HASH_SIZE)?;
533529

534530
// Chain id
535-
encoder.tag(minicbor::data::Tag::new(ULID_CBOR_TAG))?;
536-
encoder.bytes(&self.chain_id.to_bytes())?;
531+
encoder.tag(minicbor::data::Tag::new(UUID_CBOR_TAG))?;
532+
encoder.bytes(self.chain_id.as_bytes())?;
537533

538534
// Block timestamp
539535
encoder.tag(minicbor::data::Tag::new(TIMESTAMP_CBOR_TAG))?;
@@ -549,8 +545,8 @@ impl GenesisPreviousHash {
549545
encoder.bytes(self.ledger_type.as_bytes())?;
550546

551547
// Purpose id
552-
encoder.tag(minicbor::data::Tag::new(ULID_CBOR_TAG))?;
553-
encoder.bytes(&self.purpose_id.to_bytes())?;
548+
encoder.tag(minicbor::data::Tag::new(UUID_CBOR_TAG))?;
549+
encoder.bytes(self.purpose_id.as_bytes())?;
554550

555551
// Validators
556552
encoder.array(self.validator.len().try_into()?)?;
@@ -586,7 +582,6 @@ mod tests {
586582

587583
use ed25519_dalek::{Signature, Signer, SigningKey, SECRET_KEY_LENGTH};
588584
use test_strategy::proptest;
589-
use ulid::Ulid;
590585
use uuid::Uuid;
591586

592587
use super::{BlockHeader, Kid};
@@ -609,12 +604,12 @@ mod tests {
609604
.unwrap();
610605

611606
let block_hdr = BlockHeader::new(
612-
Ulid::new(),
607+
Uuid::now_v7(),
613608
block_height,
614609
block_timestamp,
615610
(Blake2b, prev_block_hash),
616611
Uuid::new_v4(),
617-
Ulid::new(),
612+
Uuid::now_v7(),
618613
vec![Kid(kid_a), Kid(kid_b)],
619614
metadata,
620615
);
@@ -660,12 +655,12 @@ mod tests {
660655
.unwrap();
661656

662657
let block_hdr = BlockHeader::new(
663-
Ulid::new(),
658+
Uuid::now_v7(),
664659
block_height,
665660
block_timestamp,
666661
(Blake2b, prev_block_hash),
667662
Uuid::new_v4(),
668-
Ulid::new(),
663+
Uuid::now_v7(),
669664
vec![Kid(kid_a), Kid(kid_b)],
670665
metadata,
671666
);
@@ -751,9 +746,9 @@ mod tests {
751746
.try_into()
752747
.unwrap();
753748

754-
let chain_id = Ulid::new();
749+
let chain_id = Uuid::now_v7();
755750
let ledger_type = Uuid::new_v4();
756-
let purpose_id = Ulid::new();
751+
let purpose_id = Uuid::now_v7();
757752

758753
let block_hdr = BlockHeader::new(
759754
chain_id,
@@ -824,9 +819,9 @@ mod tests {
824819
073, 197, 105, 123, 050, 105, 025, 112, 059, 172, 003, 028, 174, 127, 096,
825820
];
826821

827-
let chain_id = Ulid::new();
822+
let chain_id = Uuid::now_v7();
828823
let ledger_type = Uuid::new_v4();
829-
let purpose_id = Ulid::new();
824+
let purpose_id = Uuid::now_v7();
830825
let block_time_stamp = 1_728_474_515;
831826

832827
let kid_a: [u8; 16] = hex::decode("00112233445566778899aabbccddeeff")

0 commit comments

Comments
 (0)