From 3d4686fec00ce68cb799817be84af1b6389a6ccf Mon Sep 17 00:00:00 2001 From: Smaug Date: Thu, 10 Oct 2024 19:29:46 +0200 Subject: [PATCH] fix(parse_cbor): support mapping of CborBlock to ParsedBlock (#824) --- docs/pages/v2/filters/parse_cbor.mdx | 24 +++++++++++++++++++++--- src/filters/parse_cbor.rs | 5 +++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/docs/pages/v2/filters/parse_cbor.mdx b/docs/pages/v2/filters/parse_cbor.mdx index c2fd8b98..2cbecc4d 100644 --- a/docs/pages/v2/filters/parse_cbor.mdx +++ b/docs/pages/v2/filters/parse_cbor.mdx @@ -1,8 +1,10 @@ # Parse CBOR filter -The `parse_cbor` filter aims to map cbor transactions to a structured transaction. +The `parse_cbor` filter aims to map cbor blocks to structured blocks and cbor transactions to structured transactions. -However, the filter will only work when the record received in the stage is CborTx in other words a transaction in Cbor format that was previously extracted from a block by another stage, otherwise, parse_cbor will ignore and pass the record to the next stage. When the record is CborTx, parse_cbor will decode and map the Cbor to a structure, so the next stage will receive the ParsedTx record. If no filter is enabled, the stages will receive the record in CborBlock format, and if only the parse_cbor filter is enabled in `daemon.toml`, it will be necessary to enable the [split_cbor](split_block) filter for the stage to receive the CborTx format. +- When the record received in the stage is CborBlock, the filter will decode and map it to ParsedBlock, which is passed to the next stage. +- When the record received in the stage is CborTx, the filter will decode and map it to ParsedTx, which is passed to the next stage. This will only happen when the record received in the stage is CborTx and therefore requires to enable the [split_cbor](split_block) filter before for the stage to receive the CborTx format. +- Else, parse_cbor will ignore and pass the record to the next stage. ## Configuration @@ -15,7 +17,23 @@ type = "ParseCbor" ## Examples -Below is an example of the data that will be sent to the sink. A block can contain many transactions, so the sink will receive an event for each transaction in json format. +Below is an example of the data that will be sent to the sink when the filter received a CborBlock record. + +```json +{ + "event": "apply", + "point": { + "slot": 0, + "hash": "" + }, + "record": { + "header": {}, + "body": {} + } +} +``` + +Below is an example of the data that will be sent to the sink when the filter received a CborTx record. A block can contain many transactions, so the sink will receive an event for each transaction. ```json { diff --git a/src/filters/parse_cbor.rs b/src/filters/parse_cbor.rs index d085781d..0908d48f 100644 --- a/src/filters/parse_cbor.rs +++ b/src/filters/parse_cbor.rs @@ -40,6 +40,11 @@ impl From<&Stage> for Worker { gasket::impl_mapper!(|_worker: Worker, stage: Stage, unit: ChainEvent| => { let output = unit.clone().try_map_record(|r| match r { + Record::CborBlock(cbor) => { + let block = trv::MultiEraBlock::decode(&cbor).or_panic()?; + let block = stage.mapper.map_block(&block); + Ok(Record::ParsedBlock(block)) + } Record::CborTx(cbor) => { let tx = trv::MultiEraTx::decode(&cbor).or_panic()?; let tx = stage.mapper.map_tx(&tx);