Skip to content

Commit

Permalink
MultiEraBlock::from_explicit_network_cbor_bytes EBB (#318)
Browse files Browse the repository at this point in the history
* MultiEraBlock::from_explicit_network_cbor_bytes EBB

Update the function to handle Byron EBBs.

We still need to figure out what to do in the general deserialize case #317 or if that behavior should just merge this function in there.

* Add comment for MultiEraBlock::hash()
  • Loading branch information
rooooooooob authored Mar 11, 2024
1 parent 28c9f4d commit 1a42686
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions multi-era/rust/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::allegra::{
};
use crate::alonzo::{AlonzoCostmdls, AlonzoProtocolParamUpdate};
use crate::babbage::{BabbageCostModels, BabbageProtocolParamUpdate, BabbageTransactionOutput};
use crate::byron::block::{ByronBlockHeader, EbbHead};
use crate::byron::block::{ByronBlockHeader, ByronEbBlock, ByronMainBlock, EbbHead};
use crate::byron::transaction::ByronTxIn;
use crate::mary::MaryTransactionOutput;
use crate::shelley::{
Expand Down Expand Up @@ -67,8 +67,11 @@ impl MultiEraBlock {
.unsigned_integer()
.map_err(|e| DeserializeError::from(e).annotate("block_era_tag"))?;
let block = match era {
1 => ByronBlock::deserialize(&mut raw)
.map(Self::Byron)
0 => ByronEbBlock::deserialize(&mut raw)
.map(|ebb| Self::Byron(ByronBlock::EpochBoundary(ebb)))
.map_err(|e| e.annotate("Byron EBB")),
1 => ByronMainBlock::deserialize(&mut raw)
.map(|mb| Self::Byron(ByronBlock::Main(mb)))
.map_err(|e| e.annotate("Byron")),
2 => ShelleyBlock::deserialize(&mut raw)
.map(Self::Shelley)
Expand Down Expand Up @@ -238,6 +241,11 @@ impl MultiEraBlock {
pub fn hash(&self) -> [u8; 32] {
let bytes = match self {
Self::Byron(block) => {
// The hash for Byron is not calculated on header directly but instead
// on the following CBOR structure: [0, ebb_head // 1, byron_block_header]
// 0x82 is a canonical CBOR 2 element array
// 0x00 and 0x01 are the integers 0 and 1
// See: https://cardano-ledger.cardano.intersectmbo.org/cardano-ledger-byron/src/Cardano.Chain.Block.Header.html#wrapBoundaryBytes
let mut tagged_bytes = vec![0x82];
match block {
ByronBlock::EpochBoundary(ebb) => {
Expand Down

0 comments on commit 1a42686

Please sign in to comment.