From 911d3105fed9b4a2a976f6713641064465a18080 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 27 Nov 2024 10:23:59 +0100 Subject: [PATCH] feat: add contains for opcodegas container (#1695) --- crates/rpc-types-trace/src/opcode.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/rpc-types-trace/src/opcode.rs b/crates/rpc-types-trace/src/opcode.rs index a307308364b..bfb55c20919 100644 --- a/crates/rpc-types-trace/src/opcode.rs +++ b/crates/rpc-types-trace/src/opcode.rs @@ -16,6 +16,13 @@ pub struct BlockOpcodeGas { pub transactions: Vec, } +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")] @@ -28,6 +35,13 @@ pub struct TransactionOpcodeGas { pub opcode_gas: Vec, } +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")]