feat: Add entrypoint utils and define EntryPointParams (#211)
* feat: Add entrypoint utils and define EntryPointParams #time 23m #time 0m * fix: Make TraceData mandatory #time 2m * fix: Make component_id in EntryPointParams optional #time 1m
This commit is contained in:
@@ -168,7 +168,7 @@ message EntryPointParams {
|
|||||||
// The entrypoint id.
|
// The entrypoint id.
|
||||||
string entrypoint_id = 1;
|
string entrypoint_id = 1;
|
||||||
// [optional] The component that uses these entrypoint parameters. Currently used for debugging purposes only.
|
// [optional] The component that uses these entrypoint parameters. Currently used for debugging purposes only.
|
||||||
string component_id = 2;
|
optional string component_id = 2;
|
||||||
// The strategy and its corresponding data
|
// The strategy and its corresponding data
|
||||||
oneof trace_data {
|
oneof trace_data {
|
||||||
RPCTraceData rpc = 3;
|
RPCTraceData rpc = 3;
|
||||||
|
|||||||
@@ -5,7 +5,10 @@ plugins:
|
|||||||
opt:
|
opt:
|
||||||
- file_descriptor_set=false
|
- file_descriptor_set=false
|
||||||
- type_attribute=.tycho.evm.v1.Transaction=#[derive(Eq\, Hash)]
|
- type_attribute=.tycho.evm.v1.Transaction=#[derive(Eq\, Hash)]
|
||||||
|
- type_attribute=.tycho.evm.v1.TraceData=#[derive(Eq\, Hash)]
|
||||||
- type_attribute=.tycho.evm.v1.EntryPoint=#[derive(Eq\, Hash)]
|
- type_attribute=.tycho.evm.v1.EntryPoint=#[derive(Eq\, Hash)]
|
||||||
|
- type_attribute=.tycho.evm.v1.EntryPointParams=#[derive(Eq\, Hash)]
|
||||||
|
- type_attribute=.tycho.evm.v1.RPCTraceData=#[derive(Eq\, Hash)]
|
||||||
- remote: buf.build/community/neoeinstein-prost-crate:v0.3.1
|
- remote: buf.build/community/neoeinstein-prost-crate:v0.3.1
|
||||||
out: src/pb
|
out: src/pb
|
||||||
opt: no_features
|
opt: no_features
|
||||||
|
|||||||
52
substreams/crates/tycho-substreams/src/entrypoint.rs
Normal file
52
substreams/crates/tycho-substreams/src/entrypoint.rs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
use crate::models::{entry_point_params::TraceData, EntryPoint, EntryPointParams};
|
||||||
|
|
||||||
|
fn get_entrypoint_id(target: &[u8], signature: &str) -> String {
|
||||||
|
let target = hex::encode(target);
|
||||||
|
format!("{target}:{signature}")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates an entrypoint and its parameters.
|
||||||
|
pub fn create_entrypoint(
|
||||||
|
target: Vec<u8>,
|
||||||
|
signature: String,
|
||||||
|
component_id: String,
|
||||||
|
trace_data: TraceData,
|
||||||
|
) -> (EntryPoint, EntryPointParams) {
|
||||||
|
let entrypoint_id = get_entrypoint_id(&target, &signature);
|
||||||
|
let entrypoint = EntryPoint {
|
||||||
|
id: entrypoint_id.clone(),
|
||||||
|
target,
|
||||||
|
signature,
|
||||||
|
component_id: component_id.clone(),
|
||||||
|
};
|
||||||
|
let entrypoint_params = EntryPointParams {
|
||||||
|
entrypoint_id,
|
||||||
|
component_id: Some(component_id),
|
||||||
|
trace_data: Some(trace_data),
|
||||||
|
};
|
||||||
|
(entrypoint, entrypoint_params)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adds EntryPointParams associated with an already existing Entrypoint.
|
||||||
|
pub fn add_entrypoint_params(
|
||||||
|
target: Vec<u8>,
|
||||||
|
signature: String,
|
||||||
|
trace_data: TraceData,
|
||||||
|
component_id: Option<String>,
|
||||||
|
) -> EntryPointParams {
|
||||||
|
EntryPointParams {
|
||||||
|
entrypoint_id: get_entrypoint_id(&target, &signature),
|
||||||
|
component_id,
|
||||||
|
trace_data: Some(trace_data),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adds a component to an existing Entrypoint.
|
||||||
|
pub fn add_component_to_entrypoint(
|
||||||
|
target: Vec<u8>,
|
||||||
|
signature: String,
|
||||||
|
component_id: String,
|
||||||
|
) -> EntryPoint {
|
||||||
|
let entrypoint_id = get_entrypoint_id(&target, &signature);
|
||||||
|
EntryPoint { id: entrypoint_id, target, signature, component_id }
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ pub mod attributes;
|
|||||||
pub mod balances;
|
pub mod balances;
|
||||||
pub mod block_storage;
|
pub mod block_storage;
|
||||||
pub mod contract;
|
pub mod contract;
|
||||||
|
pub mod entrypoint;
|
||||||
mod mock_store;
|
mod mock_store;
|
||||||
pub mod models;
|
pub mod models;
|
||||||
pub mod pb;
|
pub mod pb;
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ pub struct TransactionChangesBuilder {
|
|||||||
component_changes: HashMap<String, ProtocolComponent>,
|
component_changes: HashMap<String, ProtocolComponent>,
|
||||||
balance_changes: HashMap<(Vec<u8>, Vec<u8>), BalanceChange>,
|
balance_changes: HashMap<(Vec<u8>, Vec<u8>), BalanceChange>,
|
||||||
entrypoints: HashSet<EntryPoint>,
|
entrypoints: HashSet<EntryPoint>,
|
||||||
|
entrypoint_params: HashSet<EntryPointParams>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TransactionChangesBuilder {
|
impl TransactionChangesBuilder {
|
||||||
@@ -159,6 +160,11 @@ impl TransactionChangesBuilder {
|
|||||||
.insert(entrypoint.clone());
|
.insert(entrypoint.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add_entrypoint_params(&mut self, entrypoint: &EntryPointParams) {
|
||||||
|
self.entrypoint_params
|
||||||
|
.insert(entrypoint.clone());
|
||||||
|
}
|
||||||
|
|
||||||
pub fn build(self) -> Option<TransactionChanges> {
|
pub fn build(self) -> Option<TransactionChanges> {
|
||||||
let tx_changes = TransactionChanges {
|
let tx_changes = TransactionChanges {
|
||||||
tx: self.tx,
|
tx: self.tx,
|
||||||
@@ -184,7 +190,10 @@ impl TransactionChangesBuilder {
|
|||||||
.entrypoints
|
.entrypoints
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
entrypoint_params: Vec::new(), // TODO: Add entrypoint params to builder
|
entrypoint_params: self
|
||||||
|
.entrypoint_params
|
||||||
|
.into_iter()
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
};
|
};
|
||||||
if tx_changes.is_empty() {
|
if tx_changes.is_empty() {
|
||||||
None
|
None
|
||||||
|
|||||||
@@ -194,6 +194,7 @@ pub struct EntryPoint {
|
|||||||
pub component_id: ::prost::alloc::string::String,
|
pub component_id: ::prost::alloc::string::String,
|
||||||
}
|
}
|
||||||
/// Parameters to trace the entrypoint
|
/// Parameters to trace the entrypoint
|
||||||
|
#[derive(Eq, Hash)]
|
||||||
#[allow(clippy::derive_partial_eq_without_eq)]
|
#[allow(clippy::derive_partial_eq_without_eq)]
|
||||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||||
pub struct EntryPointParams {
|
pub struct EntryPointParams {
|
||||||
@@ -201,8 +202,8 @@ pub struct EntryPointParams {
|
|||||||
#[prost(string, tag="1")]
|
#[prost(string, tag="1")]
|
||||||
pub entrypoint_id: ::prost::alloc::string::String,
|
pub entrypoint_id: ::prost::alloc::string::String,
|
||||||
/// \[optional\] The component that uses these entrypoint parameters. Currently used for debugging purposes only.
|
/// \[optional\] The component that uses these entrypoint parameters. Currently used for debugging purposes only.
|
||||||
#[prost(string, tag="2")]
|
#[prost(string, optional, tag="2")]
|
||||||
pub component_id: ::prost::alloc::string::String,
|
pub component_id: ::core::option::Option<::prost::alloc::string::String>,
|
||||||
/// The strategy and its corresponding data
|
/// The strategy and its corresponding data
|
||||||
#[prost(oneof="entry_point_params::TraceData", tags="3")]
|
#[prost(oneof="entry_point_params::TraceData", tags="3")]
|
||||||
pub trace_data: ::core::option::Option<entry_point_params::TraceData>,
|
pub trace_data: ::core::option::Option<entry_point_params::TraceData>,
|
||||||
@@ -210,6 +211,7 @@ pub struct EntryPointParams {
|
|||||||
/// Nested message and enum types in `EntryPointParams`.
|
/// Nested message and enum types in `EntryPointParams`.
|
||||||
pub mod entry_point_params {
|
pub mod entry_point_params {
|
||||||
/// The strategy and its corresponding data
|
/// The strategy and its corresponding data
|
||||||
|
#[derive(Eq, Hash)]
|
||||||
#[allow(clippy::derive_partial_eq_without_eq)]
|
#[allow(clippy::derive_partial_eq_without_eq)]
|
||||||
#[derive(Clone, PartialEq, ::prost::Oneof)]
|
#[derive(Clone, PartialEq, ::prost::Oneof)]
|
||||||
pub enum TraceData {
|
pub enum TraceData {
|
||||||
@@ -219,6 +221,7 @@ pub mod entry_point_params {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// RPC tracing strategy with its data
|
/// RPC tracing strategy with its data
|
||||||
|
#[derive(Eq, Hash)]
|
||||||
#[allow(clippy::derive_partial_eq_without_eq)]
|
#[allow(clippy::derive_partial_eq_without_eq)]
|
||||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||||
pub struct RpcTraceData {
|
pub struct RpcTraceData {
|
||||||
|
|||||||
Reference in New Issue
Block a user