Skip to content

Commit

Permalink
Updated trace format for Edge
Browse files Browse the repository at this point in the history
  • Loading branch information
BGluth committed Oct 4, 2023
1 parent 2baba66 commit d986d59
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
42 changes: 32 additions & 10 deletions parser/src/edge_payloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>,

/// 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<u8>,

// 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<BloomWrapper>")]
pub bloom: [U256; 8],

#[serde(rename(deserialize = "delta"))]
Expand Down Expand Up @@ -183,33 +190,48 @@ fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result<Vec<u8>, 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<E>(self, data: &'de str) -> Result<Self::Value, E>
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 {
write!(f, "a hex encoded string with a prefix")
}
}

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<BloomWrapper> 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)]
Expand Down
2 changes: 2 additions & 0 deletions parser/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(iter_array_chunks)]

pub mod edge_payloads;
pub mod plonky2;
pub mod plonky3;
Expand Down

0 comments on commit d986d59

Please sign in to comment.