diff --git a/parser/src/edge_payloads.rs b/parser/src/edge_payloads.rs index 6b85fc4..356afcd 100644 --- a/parser/src/edge_payloads.rs +++ b/parser/src/edge_payloads.rs @@ -61,13 +61,20 @@ pub struct TxnBytesAndTraces { /// The root of the txn trie after the txn has been executed. pub txn_root: H256, + // ReceiptNodeHash is the hash of the new txn node added by the txn. + pub txn_node_bytes: Vec, + /// The root of the receipt trie after the txn has been executed. pub receipt_root: H256, + // ReceiptNodeHash is the hash of the new receipt node added by the txn. + pub receipt_node_bytes: Vec, + // GasUsed is the amount of gas used by the transaction pub gas_used: u64, // Bloom is the bloom filter for the transaction + #[serde_as(as = "FromInto")] pub bloom: [U256; 8], #[serde(rename(deserialize = "delta"))] @@ -183,14 +190,14 @@ fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result, D: where E: Error, { - FromHex::from_hex(Self::remove_prefix_if_present(data)).map_err(Error::custom) + FromHex::from_hex(remove_hex_prefix_if_present(data)).map_err(Error::custom) } fn visit_borrowed_str(self, data: &'de str) -> Result where E: Error, { - FromHex::from_hex(Self::remove_prefix_if_present(data)).map_err(Error::custom) + FromHex::from_hex(remove_hex_prefix_if_present(data)).map_err(Error::custom) } fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { @@ -198,18 +205,33 @@ fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result, D: } } - impl PrefixHexStrVisitor { - fn remove_prefix_if_present(data: &str) -> &str { - let prefix = &data[..2]; + deserializer.deserialize_string(PrefixHexStrVisitor()) +} - match matches!(prefix, "0x" | "0X") { - false => data, - true => &data[2..], - } +#[derive(Debug, Deserialize)] +struct BloomWrapper(String); + +impl From for [U256; 8] { + fn from(v: BloomWrapper) -> Self { + let bytes = hex::decode(remove_hex_prefix_if_present(&v.0)).unwrap(); + let mut bloom = [U256::zero(); 8]; + + // Note that bloom can be empty. + for (i, v) in bytes.into_iter().array_chunks::<32>().enumerate() { + bloom[i] = U256::from_big_endian(v.as_slice()); } + + bloom } +} - deserializer.deserialize_string(PrefixHexStrVisitor()) +fn remove_hex_prefix_if_present(data: &str) -> &str { + let prefix = &data[..2]; + + match matches!(prefix, "0x" | "0X") { + false => data, + true => &data[2..], + } } #[derive(Clone, Debug)] diff --git a/parser/src/lib.rs b/parser/src/lib.rs index a20a0b5..711969e 100644 --- a/parser/src/lib.rs +++ b/parser/src/lib.rs @@ -1,3 +1,5 @@ +#![feature(iter_array_chunks)] + pub mod edge_payloads; pub mod plonky2; pub mod plonky3;