Skip to content

Commit ca5ffc3

Browse files
committed
feat: multi era block
1 parent 9784eba commit ca5ffc3

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

rust/cardano-chain-follower/src/metadata/cip36.rs

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

55
use ed25519_dalek::Verifier;
66
use minicbor::Decoder;
7-
use pallas::ledger::traverse::MultiEraTx;
7+
use pallas::ledger::traverse::MultiEraTxWithRawAuxiliary;
88
use tracing::debug;
99

1010
use super::{
@@ -91,7 +91,7 @@ impl Cip36 {
9191
/// Nothing. IF CIP36 Metadata is found it will be updated in `decoded_metadata`.
9292
#[allow(clippy::too_many_lines)]
9393
pub(crate) fn decode_and_validate(
94-
decoded_metadata: &DecodedMetadata, slot: u64, txn: &MultiEraTx, raw_aux_data: &RawAuxData,
94+
decoded_metadata: &DecodedMetadata, slot: u64, txn: &MultiEraTxWithRawAuxiliary, raw_aux_data: &RawAuxData,
9595
catalyst_strict: bool, chain: Network,
9696
) {
9797
let k61284 = raw_aux_data.get_metadata(LABEL);
@@ -377,7 +377,7 @@ impl Cip36 {
377377
/// Decode the Payment Address Metadata in the CIP36 Metadata map.
378378
fn decode_payment_address(
379379
&mut self, decoder: &mut Decoder, validation_report: &mut ValidationReport,
380-
decoded_metadata: &DecodedMetadata, _txn: &MultiEraTx, chain: Network,
380+
decoded_metadata: &DecodedMetadata, _txn: &MultiEraTxWithRawAuxiliary, chain: Network,
381381
) -> Option<usize> {
382382
let raw_address = match decoder.bytes() {
383383
Ok(address) => address,
@@ -969,7 +969,7 @@ mod tests {
969969
let mut cip36 = create_empty_cip36(false);
970970
let mut decoder = Decoder::new(&hex_data);
971971
let mut report = ValidationReport::new();
972-
let multi_era_tx: *const MultiEraTx = std::ptr::null();
972+
let multi_era_tx: *const MultiEraTxWithRawAuxiliary = std::ptr::null();
973973
let multi_era_tx = unsafe { &*multi_era_tx };
974974

975975
let rc = cip36.decode_payment_address(

rust/cardano-chain-follower/src/metadata/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{fmt::Debug, sync::Arc};
55
use cip36::Cip36;
66
use cip509::Cip509;
77
use dashmap::DashMap;
8-
use pallas::ledger::traverse::{MultiEraBlock, MultiEraTx};
8+
use pallas::ledger::traverse::{MultiEraBlockWithRawAuxiliary, MultiEraTxWithRawAuxiliary};
99
use raw_aux_data::RawAuxData;
1010
use tracing::error;
1111

@@ -50,7 +50,7 @@ pub(crate) struct DecodedMetadata(DashMap<u64, Arc<DecodedMetadataItem>>);
5050
impl DecodedMetadata {
5151
/// Create new decoded metadata for a transaction.
5252
fn new(
53-
chain: Network, slot: u64, txn: &MultiEraTx, raw_aux_data: &RawAuxData, txn_idx: usize,
53+
chain: Network, slot: u64, txn: &MultiEraTxWithRawAuxiliary, raw_aux_data: &RawAuxData, txn_idx: usize,
5454
) -> Self {
5555
let decoded_metadata = Self(DashMap::new());
5656

@@ -98,7 +98,7 @@ impl DecodedTransaction {
9898
/// Insert another transaction worth of data into the Decoded Aux Data
9999
fn insert(
100100
&mut self, chain: Network, slot: u64, txn_idx: u32, cbor_data: &[u8],
101-
transactions: &[MultiEraTx],
101+
transactions: &[MultiEraTxWithRawAuxiliary],
102102
) {
103103
let txn_idx = usize_from_saturating(txn_idx);
104104

@@ -115,7 +115,7 @@ impl DecodedTransaction {
115115
}
116116

117117
/// Create a new `DecodedTransaction`.
118-
pub(crate) fn new(chain: Network, block: &MultiEraBlock) -> Self {
118+
pub(crate) fn new(chain: Network, block: &MultiEraBlockWithRawAuxiliary) -> Self {
119119
let mut decoded_aux_data = DecodedTransaction {
120120
raw: DashMap::new(),
121121
decoded: DashMap::new(),

rust/cardano-chain-follower/src/multi_era_block_data.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use std::{cmp::Ordering, fmt::Display, sync::Arc};
1111

1212
use ouroboros::self_referencing;
13+
use pallas::ledger::traverse::MultiEraBlockWithRawAuxiliary;
1314
use tracing::debug;
1415

1516
use crate::{
@@ -30,7 +31,7 @@ pub(crate) struct SelfReferencedMultiEraBlock {
3031
/// References the `raw_data` field.
3132
#[borrows(raw_data)]
3233
#[covariant]
33-
block: pallas::ledger::traverse::MultiEraBlock<'this>,
34+
block: MultiEraBlockWithRawAuxiliary<'this>,
3435
}
3536

3637
/// Multi-era block - inner.
@@ -89,7 +90,7 @@ impl MultiEraBlock {
8990
let builder = SelfReferencedMultiEraBlockTryBuilder {
9091
raw_data,
9192
block_builder: |raw_data| -> Result<_, Error> {
92-
pallas::ledger::traverse::MultiEraBlock::decode(raw_data)
93+
MultiEraBlockWithRawAuxiliary::decode(raw_data)
9394
.map_err(|err| Error::Codec(err.to_string()))
9495
},
9596
};
@@ -104,7 +105,7 @@ impl MultiEraBlock {
104105

105106
let byron_block = matches!(
106107
decoded_block,
107-
pallas::ledger::traverse::MultiEraBlock::Byron(_)
108+
MultiEraBlockWithRawAuxiliary::Byron(_)
108109
);
109110

110111
// debug!("New Block: {slot} {point} {}", *previous);
@@ -180,7 +181,7 @@ impl MultiEraBlock {
180181
/// The decoded block data, which can easily be processed by a consumer.
181182
#[must_use]
182183
#[allow(clippy::missing_panics_doc)]
183-
pub fn decode(&self) -> &pallas::ledger::traverse::MultiEraBlock {
184+
pub fn decode(&self) -> &MultiEraBlockWithRawAuxiliary {
184185
self.inner.data.borrow_block()
185186
}
186187

@@ -308,15 +309,15 @@ impl Display for MultiEraBlock {
308309
};
309310

310311
let block_era = match block {
311-
pallas::ledger::traverse::MultiEraBlock::EpochBoundary(_) => {
312+
MultiEraBlockWithRawAuxiliary::EpochBoundary(_) => {
312313
"Byron Epoch Boundary".to_string()
313314
},
314-
pallas::ledger::traverse::MultiEraBlock::AlonzoCompatible(_, era) => {
315+
MultiEraBlockWithRawAuxiliary::AlonzoCompatible(_, era) => {
315316
format!("{era}")
316317
},
317-
pallas::ledger::traverse::MultiEraBlock::Babbage(_) => "Babbage".to_string(),
318-
pallas::ledger::traverse::MultiEraBlock::Byron(_) => "Byron".to_string(),
319-
pallas::ledger::traverse::MultiEraBlock::Conway(_) => "Conway".to_string(),
318+
MultiEraBlockWithRawAuxiliary::Babbage(_) => "Babbage".to_string(),
319+
MultiEraBlockWithRawAuxiliary::Byron(_) => "Byron".to_string(),
320+
MultiEraBlockWithRawAuxiliary::Conway(_) => "Conway".to_string(),
320321
_ => "Unknown".to_string(),
321322
};
322323
write!(f, "{block_era} block : {}, Previous {} : Slot# {slot} : {fork} : Block# {block_number} : Size {size} : Txns {txns} : AuxData? {aux_data}",
@@ -373,6 +374,7 @@ pub(crate) mod tests {
373374

374375
use anyhow::Ok;
375376

377+
use super::*;
376378
use crate::{point::ORIGIN_POINT, MultiEraBlock, Network, Point};
377379

378380
struct TestRecord {
@@ -457,7 +459,7 @@ pub(crate) mod tests {
457459
fn test_multi_era_block_point_compare_1() -> anyhow::Result<()> {
458460
for (i, test_block) in test_blocks().into_iter().enumerate() {
459461
let pallas_block =
460-
pallas::ledger::traverse::MultiEraBlock::decode(test_block.raw.as_slice())?;
462+
MultiEraBlockWithRawAuxiliary::decode(test_block.raw.as_slice())?;
461463

462464
let previous_point = Point::new(
463465
pallas_block.slot().add(i as u64),
@@ -482,7 +484,7 @@ pub(crate) mod tests {
482484
fn test_multi_era_block_point_compare_2() -> anyhow::Result<()> {
483485
for test_block in test_blocks() {
484486
let pallas_block =
485-
pallas::ledger::traverse::MultiEraBlock::decode(test_block.raw.as_slice())?;
487+
MultiEraBlockWithRawAuxiliary::decode(test_block.raw.as_slice())?;
486488

487489
let previous_point = Point::new(pallas_block.slot() - 1, vec![0; 32]);
488490

@@ -500,7 +502,7 @@ pub(crate) mod tests {
500502
fn test_multi_era_block_point_compare_3() -> anyhow::Result<()> {
501503
for test_block in test_blocks() {
502504
let pallas_block =
503-
pallas::ledger::traverse::MultiEraBlock::decode(test_block.raw.as_slice())?;
505+
MultiEraBlockWithRawAuxiliary::decode(test_block.raw.as_slice())?;
504506

505507
let previous_point = Point::new(
506508
pallas_block.slot() - 1,
@@ -525,7 +527,7 @@ pub(crate) mod tests {
525527
raw_blocks
526528
.iter()
527529
.map(|block| {
528-
let prev_point = pallas::ledger::traverse::MultiEraBlock::decode(block.as_slice())
530+
let prev_point = MultiEraBlockWithRawAuxiliary::decode(block.as_slice())
529531
.map(|block| {
530532
Point::new(
531533
block.slot() - 1,
@@ -549,7 +551,7 @@ pub(crate) mod tests {
549551
raw_blocks
550552
.iter()
551553
.map(|block| {
552-
pallas::ledger::traverse::MultiEraBlock::decode(block.as_slice())
554+
MultiEraBlockWithRawAuxiliary::decode(block.as_slice())
553555
.map(|block| {
554556
Point::new(
555557
block.slot(),

0 commit comments

Comments
 (0)