feat(interop): add block mapping to u5c (#261)

This commit is contained in:
Santiago Carmuega 2023-06-12 02:31:39 +02:00 committed by GitHub
parent 35dda4d40f
commit 227b903bcb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -469,3 +469,22 @@ pub fn map_tx(tx: &trv::MultiEraTx) -> u5c::Tx {
.into(),
}
}
pub fn map_block(block: &trv::MultiEraBlock) -> u5c::Block {
u5c::Block {
header: u5c::BlockHeader {
slot: block.slot(),
hash: block.hash().to_vec().into(),
}
.into(),
body: u5c::BlockBody {
tx: block.txs().iter().map(map_tx).collect(),
}
.into(),
}
}
pub fn map_block_cbor(raw: &[u8]) -> u5c::Block {
let block = trv::MultiEraBlock::decode(raw).unwrap();
map_block(&block)
}