From c7227c02346cc00aaeab831f5dd22863b520ead7 Mon Sep 17 00:00:00 2001 From: Santiago Carmuega Date: Mon, 27 Jun 2022 18:01:48 -0300 Subject: [PATCH] feat(traverse): Expose block number value (#140) --- pallas-traverse/src/block.rs | 21 +++++++++++++++++++++ pallas-traverse/src/header.rs | 14 ++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/pallas-traverse/src/block.rs b/pallas-traverse/src/block.rs index fc32bf4..2f31de8 100644 --- a/pallas-traverse/src/block.rs +++ b/pallas-traverse/src/block.rs @@ -85,6 +85,27 @@ impl<'b> MultiEraBlock<'b> { } } + pub fn number(&self) -> u64 { + match self { + MultiEraBlock::EpochBoundary(x) => x + .header + .consensus_data + .difficulty + .first() + .cloned() + .unwrap_or_default(), + MultiEraBlock::AlonzoCompatible(x, _) => x.header.header_body.block_number, + MultiEraBlock::Babbage(x) => x.header.header_body.block_number, + MultiEraBlock::Byron(x) => x + .header + .consensus_data + .2 + .first() + .cloned() + .unwrap_or_default(), + } + } + pub fn era(&self) -> Era { match self { MultiEraBlock::EpochBoundary(_) => Era::Byron, diff --git a/pallas-traverse/src/header.rs b/pallas-traverse/src/header.rs index d302d8e..0e4dbb3 100644 --- a/pallas-traverse/src/header.rs +++ b/pallas-traverse/src/header.rs @@ -29,6 +29,20 @@ impl<'b> MultiEraHeader<'b> { } } + pub fn number(&self) -> u64 { + match self { + MultiEraHeader::EpochBoundary(x) => x + .consensus_data + .difficulty + .first() + .cloned() + .unwrap_or_default(), + MultiEraHeader::AlonzoCompatible(x) => x.header_body.block_number, + MultiEraHeader::Babbage(x) => x.header_body.block_number, + MultiEraHeader::Byron(x) => x.consensus_data.2.first().cloned().unwrap_or_default(), + } + } + pub fn slot(&self) -> u64 { match self { MultiEraHeader::EpochBoundary(x) => x.to_abs_slot(),