Skip to content

Commit 3d4686f

Browse files
authored
fix(parse_cbor): support mapping of CborBlock to ParsedBlock (txpipe#824)
1 parent f515e4c commit 3d4686f

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

docs/pages/v2/filters/parse_cbor.mdx

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Parse CBOR filter
22

3-
The `parse_cbor` filter aims to map cbor transactions to a structured transaction.
3+
The `parse_cbor` filter aims to map cbor blocks to structured blocks and cbor transactions to structured transactions.
44

5-
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.
5+
- 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.
6+
- 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.
7+
- Else, parse_cbor will ignore and pass the record to the next stage.
68

79
## Configuration
810

@@ -15,7 +17,23 @@ type = "ParseCbor"
1517

1618
## Examples
1719

18-
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.
20+
Below is an example of the data that will be sent to the sink when the filter received a CborBlock record.
21+
22+
```json
23+
{
24+
"event": "apply",
25+
"point": {
26+
"slot": 0,
27+
"hash": ""
28+
},
29+
"record": {
30+
"header": {},
31+
"body": {}
32+
}
33+
}
34+
```
35+
36+
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.
1937

2038
```json
2139
{

src/filters/parse_cbor.rs

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ impl From<&Stage> for Worker {
4040

4141
gasket::impl_mapper!(|_worker: Worker, stage: Stage, unit: ChainEvent| => {
4242
let output = unit.clone().try_map_record(|r| match r {
43+
Record::CborBlock(cbor) => {
44+
let block = trv::MultiEraBlock::decode(&cbor).or_panic()?;
45+
let block = stage.mapper.map_block(&block);
46+
Ok(Record::ParsedBlock(block))
47+
}
4348
Record::CborTx(cbor) => {
4449
let tx = trv::MultiEraTx::decode(&cbor).or_panic()?;
4550
let tx = stage.mapper.map_tx(&tx);

0 commit comments

Comments
 (0)