Skip to content

Commit

Permalink
feat: add builder methods (alloy-rs#591)
Browse files Browse the repository at this point in the history
* feat: add trace filter builder methods

* feat: add builder methods for GethDebugTracingCallOptions

* refactor: rename methods to have the prefix "with"

* refactor: rename and ownership changes.

* fix: clippy ci
  • Loading branch information
EmperorOrokuSaki authored and ben186 committed Jul 27, 2024
1 parent 5d42077 commit 990ae60
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
42 changes: 42 additions & 0 deletions crates/rpc-types-trace/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,48 @@ pub struct TraceFilter {
// === impl TraceFilter ===

impl TraceFilter {
/// Sets the `from_block` field of the struct
pub const fn from_block(mut self, block: u64) -> Self {
self.from_block = Some(block);
self
}

/// Sets the `to_block` field of the struct
pub const fn to_block(mut self, block: u64) -> Self {
self.to_block = Some(block);
self
}

/// Sets the `from_address` field of the struct
pub fn from_address(mut self, addresses: Vec<Address>) -> Self {
self.from_address = addresses;
self
}

/// Sets the `to_address` field of the struct
pub fn to_address(mut self, addresses: Vec<Address>) -> Self {
self.to_address = addresses;
self
}

/// Sets the `after` field of the struct
pub const fn after(mut self, after: u64) -> Self {
self.after = Some(after);
self
}

/// Sets the `count` field of the struct
pub const fn count(mut self, count: u64) -> Self {
self.count = Some(count);
self
}

/// Sets the `from_address` field of the struct
pub const fn mode(mut self, mode: TraceFilterMode) -> Self {
self.mode = mode;
self
}

/// Returns a `TraceFilterMatcher` for this filter.
pub fn matcher(&self) -> TraceFilterMatcher {
let from_addresses = self.from_address.iter().cloned().collect();
Expand Down
20 changes: 20 additions & 0 deletions crates/rpc-types-trace/src/geth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,26 @@ pub struct GethDebugTracingCallOptions {
pub block_overrides: Option<BlockOverrides>,
}

impl GethDebugTracingCallOptions {
/// Enables state overrides
pub fn with_state_overrides(mut self, overrides: StateOverride) -> Self {
self.state_overrides = Some(overrides);
self
}

/// Enables block overrides
pub fn with_block_overrides(mut self, overrides: BlockOverrides) -> Self {
self.block_overrides = Some(overrides);
self
}

/// Sets the tracing options
pub fn with_tracing_options(mut self, options: GethDebugTracingOptions) -> Self {
self.tracing_options = options;
self
}
}

/// Serializes a storage map as a list of key-value pairs _without_ 0x-prefix
fn serialize_string_storage_map_opt<S: Serializer>(
storage: &Option<BTreeMap<B256, B256>>,
Expand Down

0 comments on commit 990ae60

Please sign in to comment.