stratus/eth/primitives/
external_block_with_receipts.rs1use fake::Dummy;
2use fake::Faker;
3use serde::Deserialize;
4use serde::Serialize;
5
6use crate::alias::JsonValue;
7use crate::eth::primitives::ExternalBlock;
8use crate::eth::primitives::ExternalReceipt;
9use crate::log_and_err;
10
11#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
12pub struct ExternalBlockWithReceipts {
13 pub block: ExternalBlock,
14 pub receipts: Vec<ExternalReceipt>,
15}
16
17impl Dummy<Faker> for ExternalBlockWithReceipts {
18 fn dummy_with_rng<R: rand::Rng + ?Sized>(faker: &Faker, rng: &mut R) -> Self {
19 let block = ExternalBlock::dummy_with_rng(faker, rng);
20
21 let receipts = match &block.transactions {
22 alloy_rpc_types_eth::BlockTransactions::Full(txs) => txs.iter().map(|_| ExternalReceipt::dummy_with_rng(faker, rng)).collect(),
23 alloy_rpc_types_eth::BlockTransactions::Hashes(_) => Vec::new(),
24 alloy_rpc_types_eth::BlockTransactions::Uncle => Vec::new(),
25 };
26
27 Self { block, receipts }
28 }
29}
30
31impl TryFrom<JsonValue> for ExternalBlockWithReceipts {
36 type Error = anyhow::Error;
37
38 fn try_from(value: JsonValue) -> Result<Self, Self::Error> {
39 match ExternalBlockWithReceipts::deserialize(&value) {
40 Ok(v) => Ok(v),
41 Err(e) => log_and_err!(reason = e, payload = value, "failed to convert payload value to ExternalBlockWithReceipts"),
42 }
43 }
44}