From 3f1beeab7c9fe055dc71830c63d863589e34cf5f Mon Sep 17 00:00:00 2001 From: tvinagre Date: Mon, 16 Jun 2025 18:40:39 -0300 Subject: [PATCH] fix: Make get_block_storage_changes public (#214) * fix: Make get_block_storage_changes public * Make RpcTraceData caller optional * feat: Create function to decode list of addresses --- proto/tycho/evm/v1/common.proto | 2 +- .../crates/tycho-substreams/src/attributes.rs | 21 +++++++++++++++++++ .../tycho-substreams/src/block_storage.rs | 2 +- .../tycho-substreams/src/pb/tycho.evm.v1.rs | 4 ++-- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/proto/tycho/evm/v1/common.proto b/proto/tycho/evm/v1/common.proto index 22b3cfa..5c498b3 100644 --- a/proto/tycho/evm/v1/common.proto +++ b/proto/tycho/evm/v1/common.proto @@ -179,7 +179,7 @@ message EntryPointParams { // RPC tracing strategy with its data message RPCTraceData { // [optional] The caller to be used for the trace. If none is provided a chain default will be used. - bytes caller = 1; + optional bytes caller = 1; // The calldata to be used for the trace bytes calldata = 2; } diff --git a/substreams/crates/tycho-substreams/src/attributes.rs b/substreams/crates/tycho-substreams/src/attributes.rs index da4449e..4652a6b 100644 --- a/substreams/crates/tycho-substreams/src/attributes.rs +++ b/substreams/crates/tycho-substreams/src/attributes.rs @@ -1,3 +1,4 @@ +use serde_json::Value; use std::fmt::Debug; use substreams::prelude::BigInt; @@ -29,6 +30,26 @@ pub fn json_serialize_address_list(addresses: &[Vec]) -> Vec { ) } +/// Decodes a JSON-encoded list of 0x-prefixed hex strings into a list of addresses (in byte +/// representation). This function is the inverse of `json_serialize_address_list`. +/// +/// ## Panics +/// Panics if the input is not valid JSON, not an array, or contains invalid hex strings. +pub fn json_deserialize_address_list(json_bytes: &[u8]) -> Vec> { + let value: Value = + serde_json::from_slice(json_bytes).expect("Failed to parse JSON for address list"); + value + .as_array() + .expect("Expected a JSON array") + .iter() + .map(|v| { + let s = v.as_str().expect("Expected a string"); + let s = s.strip_prefix("0x").unwrap_or(s); + hex::decode(s).expect("Invalid hex in address list") + }) + .collect() +} + /// Encodes a list of BigInt values into json. /// /// Converts each integer to a 0x prefixed hex string and then serializes diff --git a/substreams/crates/tycho-substreams/src/block_storage.rs b/substreams/crates/tycho-substreams/src/block_storage.rs index 17e7bcb..7024168 100644 --- a/substreams/crates/tycho-substreams/src/block_storage.rs +++ b/substreams/crates/tycho-substreams/src/block_storage.rs @@ -23,7 +23,7 @@ use crate::{ /// ## Warning /// ⚠️ This function *only* works if the **extended block model** is available, /// more [here](https://streamingfastio.medium.com/new-block-model-to-accelerate-chain-integration-9f65126e5425) -fn get_block_storage_changes(block: ð::v2::Block) -> Vec { +pub fn get_block_storage_changes(block: ð::v2::Block) -> Vec { if block.detail_level != Into::::into(DetailLevel::DetaillevelExtended) { panic!("Only extended blocks are supported"); } diff --git a/substreams/crates/tycho-substreams/src/pb/tycho.evm.v1.rs b/substreams/crates/tycho-substreams/src/pb/tycho.evm.v1.rs index 23f169f..34a7208 100644 --- a/substreams/crates/tycho-substreams/src/pb/tycho.evm.v1.rs +++ b/substreams/crates/tycho-substreams/src/pb/tycho.evm.v1.rs @@ -226,8 +226,8 @@ pub mod entry_point_params { #[derive(Clone, PartialEq, ::prost::Message)] pub struct RpcTraceData { /// \[optional\] The caller to be used for the trace. If none is provided a chain default will be used. - #[prost(bytes="vec", tag="1")] - pub caller: ::prost::alloc::vec::Vec, + #[prost(bytes="vec", optional, tag="1")] + pub caller: ::core::option::Option<::prost::alloc::vec::Vec>, /// The calldata to be used for the trace #[prost(bytes="vec", tag="2")] pub calldata: ::prost::alloc::vec::Vec,