From ea8d88a768fc4be51c02cfc427084f3ddab3714f Mon Sep 17 00:00:00 2001 From: Enrique Date: Mon, 15 Jan 2024 09:54:33 -0400 Subject: [PATCH] chore: add support for other fields in call/txrequest (#112) --- crates/rpc-types/src/eth/call.rs | 30 +++++++++++++++++-- .../rpc-types/src/eth/transaction/request.rs | 28 +++++++++++++++-- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/crates/rpc-types/src/eth/call.rs b/crates/rpc-types/src/eth/call.rs index f93e901dd0d..174ec1da91b 100644 --- a/crates/rpc-types/src/eth/call.rs +++ b/crates/rpc-types/src/eth/call.rs @@ -1,5 +1,5 @@ -use crate::{AccessList, BlockId, BlockOverrides}; -use alloy_primitives::{Address, Bytes, B256, U256, U64, U8}; +use crate::{other::OtherFields, AccessList, BlockId, BlockOverrides}; +use alloy_primitives::{Address, Bytes, B256, U128, U256, U64, U8}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; /// Bundle of transactions @@ -98,7 +98,7 @@ impl<'de> Deserialize<'de> for TransactionIndex { } /// Call request for `eth_call` and adjacent methods. -#[derive(Debug, Clone, Default, Eq, PartialEq, Serialize, Deserialize, Hash)] +#[derive(Debug, Clone, Default, Eq, PartialEq, Serialize, Deserialize)] #[serde(default, rename_all = "camelCase")] pub struct CallRequest { /// From @@ -133,6 +133,30 @@ pub struct CallRequest { /// EIP-2718 type #[serde(rename = "type", skip_serializing_if = "Option::is_none")] pub transaction_type: Option, + /// Support for arbitrary additional fields. + #[serde(flatten)] + pub other: OtherFields, +} + +/// Optimism specific transaction fields +#[derive(Debug, Copy, Default, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct OptimismTransactionFields { + /// Hash that uniquely identifies the source of the deposit. + #[serde(rename = "sourceHash", skip_serializing_if = "Option::is_none")] + pub source_hash: Option, + /// The ETH value to mint on L2 + #[serde(rename = "mint", skip_serializing_if = "Option::is_none")] + pub mint: Option, + /// Field indicating whether the transaction is a system transaction, and therefore + /// exempt from the L2 gas limit. + #[serde(rename = "isSystemTx", skip_serializing_if = "Option::is_none")] + pub is_system_tx: Option, +} + +impl From for OtherFields { + fn from(value: OptimismTransactionFields) -> Self { + serde_json::to_value(value).unwrap().try_into().unwrap() + } } impl CallRequest { diff --git a/crates/rpc-types/src/eth/transaction/request.rs b/crates/rpc-types/src/eth/transaction/request.rs index e88c847b0cf..4505b31616e 100644 --- a/crates/rpc-types/src/eth/transaction/request.rs +++ b/crates/rpc-types/src/eth/transaction/request.rs @@ -1,6 +1,6 @@ //! Alloy basic Transaction Request type. -use crate::eth::transaction::AccessList; -use alloy_primitives::{Address, Bytes, U128, U256, U64, U8}; +use crate::{eth::transaction::AccessList, other::OtherFields}; +use alloy_primitives::{Address, Bytes, B256, U128, U256, U64, U8}; use serde::{Deserialize, Serialize}; /// Represents _all_ transaction requests received from RPC @@ -36,6 +36,30 @@ pub struct TransactionRequest { /// EIP-2718 type #[serde(rename = "type")] pub transaction_type: Option, + /// Support for arbitrary additional fields. + #[serde(flatten)] + pub other: OtherFields, +} + +/// Optimism specific transaction fields +#[derive(Debug, Copy, Default, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct OptimismTransactionFields { + /// Hash that uniquely identifies the source of the deposit. + #[serde(rename = "sourceHash", skip_serializing_if = "Option::is_none")] + pub source_hash: Option, + /// The ETH value to mint on L2 + #[serde(rename = "mint", skip_serializing_if = "Option::is_none")] + pub mint: Option, + /// Field indicating whether the transaction is a system transaction, and therefore + /// exempt from the L2 gas limit. + #[serde(rename = "isSystemTx", skip_serializing_if = "Option::is_none")] + pub is_system_tx: Option, +} + +impl From for OtherFields { + fn from(value: OptimismTransactionFields) -> Self { + serde_json::to_value(value).unwrap().try_into().unwrap() + } } // == impl TransactionRequest ==