Skip to content

Commit 43aad01

Browse files
committed
scaffold remaining chains
1 parent 83b17dd commit 43aad01

File tree

14 files changed

+84
-26
lines changed

14 files changed

+84
-26
lines changed

src/filters/into_json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl From<&Stage> for Worker {
2727

2828
gasket::impl_mapper!(|_worker: Worker, stage: Stage, unit: ChainEvent| => {
2929
let out = unit.clone().map_record(|r| match r {
30-
Record::Cardano(record) => Record::Cardano(cardano::Record::GenericJson(JsonValue::from(record))),
30+
Record::Cardano(record) => Record::GenericJson(JsonValue::from(record)),
3131
x => x,
3232
});
3333

src/filters/select/eval/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,11 +609,14 @@ pub fn eval(record: &Record, predicate: &Predicate) -> MatchOutcome {
609609
cardano::Record::ParsedTx(x) => eval_tx(x, predicate),
610610
cardano::Record::ParsedBlock(x) => eval_block(x, predicate),
611611
_ => {
612-
warn!("The select filter is valid only with ParsedTx & ParsedBlock records");
612+
warn!("The select filter is valid only for ParsedTx / ParsedBlock records");
613613
MatchOutcome::Uncertain
614614
}
615615
},
616-
Record::Ethereum(_record) => todo!(),
616+
_ => {
617+
warn!("The select filter is valid only for Cardano ParsedTx / ParsedBlock records");
618+
MatchOutcome::Uncertain
619+
}
617620
}
618621
}
619622

src/filters/wasm_plugin.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use serde::Deserialize;
55

66
use crate::framework::*;
77

8+
pub type CardanoRecord = cardano::Record;
9+
810
#[derive(Stage)]
911
#[stage(name = "filter-wasm", unit = "ChainEvent", worker = "Worker")]
1012
pub struct Stage {
@@ -18,23 +20,20 @@ pub struct Stage {
1820
}
1921

2022
impl Stage {
21-
fn map_record(&mut self, r: Record) -> Result<Vec<Record>, Error> {
23+
fn map_cardano_record(&mut self, r: CardanoRecord) -> Result<Vec<Record>, Error> {
2224
let extism::convert::Json::<serde_json::Value>(output) = match r {
23-
Record::CborBlock(x) => self.plugin.call("map_cbor_block", x).unwrap(),
24-
Record::CborTx(x) => self.plugin.call("map_cbor_tx", x).unwrap(),
25-
Record::ParsedTx(x) => self
25+
CardanoRecord::CborBlock(x) => self.plugin.call("map_cbor_block", x).unwrap(),
26+
CardanoRecord::CborTx(x) => self.plugin.call("map_cbor_tx", x).unwrap(),
27+
CardanoRecord::ParsedTx(x) => self
2628
.plugin
2729
.call("map_u5c_tx", extism::convert::Json(x))
2830
.unwrap(),
29-
Record::ParsedBlock(x) => self
31+
CardanoRecord::ParsedBlock(x) => self
3032
.plugin
3133
.call("map_u5c_block", extism::convert::Json(x))
3234
.unwrap(),
33-
Record::GenericJson(x) => self
34-
.plugin
35-
.call("map_json", extism::convert::Json(x))
36-
.unwrap(),
37-
Record::OuraV1Event(x) => self
35+
36+
CardanoRecord::OuraV1Event(x) => self
3837
.plugin
3938
.call("map_json", extism::convert::Json(x))
4039
.unwrap(),
@@ -48,6 +47,13 @@ impl Stage {
4847

4948
Ok(output)
5049
}
50+
51+
fn map_record(&mut self, r: Record) -> Result<Vec<Record>, Error> {
52+
match r {
53+
Record::Cardano(x) => self.map_cardano_record(x),
54+
x => Ok(vec![x]),
55+
}
56+
}
5157
}
5258

5359
#[derive(Default)]

src/framework/bitcoin/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use serde_json::{json, Value as JsonValue};
2+
3+
#[derive(Debug, Clone)]
4+
pub enum Record {
5+
// Scaffold placeholder for now
6+
ParsedBlock(()),
7+
RawBlock(Vec<u8>),
8+
}
9+
10+
impl From<Record> for JsonValue {
11+
fn from(value: Record) -> Self {
12+
match value {
13+
Record::ParsedBlock(x) => json!(x),
14+
Record::RawBlock(x) => json!({ "hex": hex::encode(x) }),
15+
}
16+
}
17+
}

src/framework/cardano/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ impl From<ChainConfig> for GenesisValues {
4242
pub enum Record {
4343
CborBlock(Vec<u8>),
4444
CborTx(Vec<u8>),
45-
GenericJson(JsonValue),
4645
OuraV1Event(legacy_v1::Event),
4746
ParsedTx(ParsedTx),
4847
ParsedBlock(ParsedBlock),
@@ -56,7 +55,6 @@ impl From<Record> for JsonValue {
5655
Record::ParsedBlock(x) => json!(x),
5756
Record::ParsedTx(x) => json!(x),
5857
Record::OuraV1Event(x) => json!(x),
59-
Record::GenericJson(x) => x,
6058
}
6159
}
6260
}

src/framework/ethereum/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ use serde_json::{json, Value as JsonValue};
44
#[derive(Debug, Clone)]
55
pub enum Record {
66
ParsedBlock(Block),
7+
RawBlock(Vec<u8>),
78
}
89

910
impl From<Record> for JsonValue {
1011
fn from(value: Record) -> Self {
1112
match value {
1213
Record::ParsedBlock(x) => json!(x),
14+
Record::RawBlock(x) => json!({ "hex": hex::encode(x) }),
1315
}
1416
}
1517
}

src/framework/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ pub use pallas::interop::utxorpc::spec::cardano::Tx as ParsedTx;
1616
// we use GenesisValues from Pallas as our ChainConfig
1717
pub use pallas::ledger::traverse::wellknown::GenesisValues;
1818

19+
pub mod bitcoin;
1920
pub mod cardano;
2021
pub mod ethereum;
22+
pub mod substrate;
2123

2224
pub mod errors;
2325

@@ -79,14 +81,20 @@ impl Default for Chain {
7981

8082
#[derive(Debug, Clone)]
8183
pub enum Record {
84+
GenericJson(JsonValue),
8285
Cardano(cardano::Record),
8386
Ethereum(ethereum::Record),
87+
Bitcoin(bitcoin::Record),
88+
Substrate(substrate::Record),
8489
}
8590
impl From<Record> for JsonValue {
8691
fn from(value: Record) -> Self {
8792
match value {
93+
Record::GenericJson(x) => x,
8894
Record::Cardano(record) => record.into(),
8995
Record::Ethereum(record) => record.into(),
96+
Record::Bitcoin(record) => record.into(),
97+
Record::Substrate(record) => record.into(),
9098
}
9199
}
92100
}

src/framework/substrate/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use alloy::rpc::types::Block;
2+
use serde_json::{json, Value as JsonValue};
3+
4+
#[derive(Debug, Clone)]
5+
pub enum Record {
6+
ParsedBlock(Block),
7+
RawBlock(Vec<u8>),
8+
}
9+
10+
impl From<Record> for JsonValue {
11+
fn from(value: Record) -> Self {
12+
match value {
13+
Record::ParsedBlock(x) => json!(x),
14+
Record::RawBlock(x) => json!({ "hex": hex::encode(x) }),
15+
}
16+
}
17+
}

src/sinks/aws_s3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl gasket::framework::Worker<Stage> for Worker {
4141
}
4242

4343
let cbor = match record.unwrap() {
44-
Record::CborBlock(cbor) => Ok(cbor),
44+
Record::Cardano(cardano::Record::CborBlock(cbor)) => Ok(cbor),
4545
_ => Err(Error::config(String::from("Invalid configuration daemon"))),
4646
}
4747
.or_panic()?;

src/sinks/terminal/format.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,13 @@ impl LogLine {
9595

9696
log
9797
}
98-
cardano::Record::GenericJson(_json) => {
99-
todo!("GenericJson not implemented yet")
100-
}
10198
},
10299
Record::Ethereum(_record) => todo!(),
100+
Record::Bitcoin(record) => todo!(),
101+
Record::Substrate(record) => todo!(),
102+
Record::GenericJson(_json) => {
103+
todo!("GenericJson not implemented yet")
104+
}
103105
}
104106
}
105107

0 commit comments

Comments
 (0)