Skip to content

Commit

Permalink
feat: add contains for opcodegas container (#1695)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Nov 27, 2024
1 parent 36fd778 commit 911d310
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/rpc-types-trace/src/opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ pub struct BlockOpcodeGas {
pub transactions: Vec<TransactionOpcodeGas>,
}

impl BlockOpcodeGas {
/// Returns true if the block contains the given opcode.
pub fn contains(&self, opcode: &str) -> bool {
self.transactions.iter().any(|tx| tx.contains(opcode))
}
}

/// Opcode gas usage for a transaction.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand All @@ -28,6 +35,13 @@ pub struct TransactionOpcodeGas {
pub opcode_gas: Vec<OpcodeGas>,
}

impl TransactionOpcodeGas {
/// Returns true if the transaction contains the given opcode.
pub fn contains(&self, opcode: &str) -> bool {
self.opcode_gas.iter().any(|op| op.opcode.eq_ignore_ascii_case(opcode))
}
}

/// Gas information for a single opcode.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand Down

0 comments on commit 911d310

Please sign in to comment.