Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/serve/grpc/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,30 @@ fn apply_predicate(predicate: &u5c::watch::TxPredicate, tx: &u5c::cardano::Tx) -
}

fn block_to_txs<C: LedgerContext>(
block: &RawBlock,
raw_block: &RawBlock,
mapper: &interop::Mapper<C>,
request: &u5c::watch::WatchTxRequest,
) -> Vec<u5c::watch::AnyChainTx> {
let block = MultiEraBlock::decode(block).unwrap();
let include_block = request.field_mask.as_ref().is_some_and(|mask| {
mask.paths.iter().any(|p| p == "block" || p.starts_with("block."))
});

let body: &BlockBody = raw_block;
let block = match MultiEraBlock::decode(raw_block) {
Ok(b) => b,
Err(e) => {
tracing::warn!(error = %e, "Failed to decode block in WatchTx");
return vec![];
}
};

let mapped_block = include_block.then(|| u5c::watch::AnyChainBlock {
native_bytes: body.to_vec().into(),
chain: Some(u5c::watch::any_chain_block::Chain::Cardano(
mapper.map_block_cbor(body),
)),
});

let txs = block.txs();

txs.iter()
Expand All @@ -164,8 +183,7 @@ fn block_to_txs<C: LedgerContext>(
})
.map(|x| u5c::watch::AnyChainTx {
chain: Some(u5c::watch::any_chain_tx::Chain::Cardano(x)),
// TODO(p): should it be none?
block: None,
block: mapped_block.clone(),
})
.collect()
}
Expand Down