1use hdp::primitives::task::{datalake::DatalakeCompute, module::Module};
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Serialize, Deserialize)]
5#[serde(tag = "type")]
6pub enum Task {
7 DatalakeCompute(DatalakeCompute),
8 Module(Module),
9}
10
11#[derive(Debug, Serialize, Deserialize)]
12#[serde(rename_all = "camelCase")]
13pub struct SubmitBatchQuery {
14 pub destination_chain_id: u64,
15 pub tasks: Vec<Task>,
16}
17
18#[test]
19fn test_serialize_submit_batch_query_datalake() {
20 let json_data = r#"
21 {
22 "destinationChainId": 11155111,
23 "tasks": [
24 {
25 "type": "DatalakeCompute",
26 "datalake": {
27 "type": "BlockSampled",
28 "chainId": 11155111,
29 "blockRangeStart": 5515020,
30 "blockRangeEnd": 5515039,
31 "increment": 10,
32 "sampledProperty": "header.base_fee_per_gas"
33 },
34 "compute": {
35 "aggregateFnId": "avg"
36 }
37 },
38 {
39 "type": "DatalakeCompute",
40 "datalake": {
41 "type": "TransactionsInBlock",
42
43 "chainId": 11155111,
44 "targetBlock": 5409986,
45 "startIndex": 10,
46 "endIndex": 40,
47 "increment": 10,
48 "includedTypes": {
49 "legacy": true,
50 "eip2930": true,
51 "eip1559": true,
52 "eip4844": true
53 },
54 "sampledProperty": "tx_receipt.success"
55 },
56 "compute": {
57 "aggregateFnId": "count",
58 "aggregateFnCtx": {
59 "operator": "gt",
60 "valueToCompare": "1000000000000000000"
61 }
62 }
63 }
64 ]
65 }
66 "#;
67
68 let parsed: SubmitBatchQuery = serde_json::from_str(json_data).unwrap();
69 println!("{:?}", parsed);
70}
71
72#[test]
73fn test_serialize_submit_batch_query_module() {
74 let json_data = r#"
75 {
76 "destinationChainId": 11155111,
77 "tasks": [
78 {
79 "type": "Module",
80 "programHash": "0xaf1333b8346c1ac941efe380f3122a71c1f7cbad19301543712e74f765bfca",
81 "inputs": ["0x4F21E5", "0x4F21E8", "0x13cb6ae34a13a0977f4d7101ebc24b87bb23f0d5"]
82 }
83 ]
84 }
85 "#;
86
87 let parsed: SubmitBatchQuery = serde_json::from_str(json_data).unwrap();
88 println!("{:?}", parsed);
89}