Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rpc-types): add optimism module and refactor types #143

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions crates/rpc-types/src/eth/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ pub use access_list::{AccessList, AccessListItem, AccessListWithGasUsed};
use alloy_primitives::{Address, Bytes, B256, U128, U256, U64};
pub use blob::BlobTransactionSidecar;
pub use common::TransactionInfo;
pub use receipt::{OptimismTransactionReceiptFields, TransactionReceipt};
pub use optimism::OptimismTransactionReceiptFields;
pub use receipt::TransactionReceipt;
use serde::{Deserialize, Serialize};
pub use signature::{Parity, Signature};

mod access_list;
mod common;
pub mod kzg;
pub mod optimism;
mod receipt;
pub mod request;
mod signature;
Expand Down Expand Up @@ -83,27 +85,6 @@ pub struct Transaction {
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<B256>,
/// The ETH value to mint on L2
#[serde(rename = "mint", skip_serializing_if = "Option::is_none")]
pub mint: Option<U128>,
/// 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<bool>,
}

impl From<OptimismTransactionFields> for OtherFields {
fn from(value: OptimismTransactionFields) -> Self {
serde_json::to_value(value).unwrap().try_into().unwrap()
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
53 changes: 53 additions & 0 deletions crates/rpc-types/src/eth/transaction/optimism.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//! Misc Optimism-specific types
use alloy_primitives::{B256, U128, U256, U64};
use serde::{Deserialize, Serialize};

use crate::other::OtherFields;

/// Optimism specific transaction fields
#[derive(Debug, Copy, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct OptimismTransactionFields {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattsse prob follow-up refactor for op-rpc-types?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah maybe we want them separate, but perhaps not actually worth it

/// Hash that uniquely identifies the source of the deposit.
#[serde(rename = "sourceHash", skip_serializing_if = "Option::is_none")]
pub source_hash: Option<B256>,
/// The ETH value to mint on L2
#[serde(rename = "mint", skip_serializing_if = "Option::is_none")]
pub mint: Option<U128>,
/// 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<bool>,
}

/// Additional fields for Optimism transaction receipts
#[derive(Clone, Copy, Default, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct OptimismTransactionReceiptFields {
/// Deposit nonce for deposit transactions post-regolith
#[serde(skip_serializing_if = "Option::is_none")]
pub deposit_nonce: Option<U64>,
/// L1 fee for the transaction
#[serde(skip_serializing_if = "Option::is_none")]
pub l1_fee: Option<U256>,
/// L1 fee scalar for the transaction
#[serde(skip_serializing_if = "Option::is_none")]
pub l1_fee_scalar: Option<U256>,
/// L1 gas price for the transaction
#[serde(skip_serializing_if = "Option::is_none")]
pub l1_gas_price: Option<U256>,
/// L1 gas used for the transaction
#[serde(skip_serializing_if = "Option::is_none")]
pub l1_gas_used: Option<U256>,
}

impl From<OptimismTransactionFields> for OtherFields {
fn from(value: OptimismTransactionFields) -> Self {
serde_json::to_value(value).unwrap().try_into().unwrap()
}
}

impl From<OptimismTransactionReceiptFields> for OtherFields {
fn from(value: OptimismTransactionReceiptFields) -> Self {
serde_json::to_value(value).unwrap().try_into().unwrap()
}
}
27 changes: 0 additions & 27 deletions crates/rpc-types/src/eth/transaction/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,3 @@ pub struct TransactionReceipt {
#[serde(flatten)]
pub other: OtherFields,
}

/// Additional fields for Optimism transaction receipts
#[derive(Clone, Copy, Default, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct OptimismTransactionReceiptFields {
/// Deposit nonce for deposit transactions post-regolith
#[serde(skip_serializing_if = "Option::is_none")]
pub deposit_nonce: Option<U64>,
/// L1 fee for the transaction
#[serde(skip_serializing_if = "Option::is_none")]
pub l1_fee: Option<U256>,
/// L1 fee scalar for the transaction
#[serde(skip_serializing_if = "Option::is_none")]
pub l1_fee_scalar: Option<U256>,
/// L1 gas price for the transaction
#[serde(skip_serializing_if = "Option::is_none")]
pub l1_gas_price: Option<U256>,
/// L1 gas used for the transaction
#[serde(skip_serializing_if = "Option::is_none")]
pub l1_gas_used: Option<U256>,
}

impl From<OptimismTransactionReceiptFields> for OtherFields {
fn from(value: OptimismTransactionReceiptFields) -> Self {
serde_json::to_value(value).unwrap().try_into().unwrap()
}
}
23 changes: 1 addition & 22 deletions crates/rpc-types/src/eth/transaction/request.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Alloy basic Transaction Request type.
use crate::{eth::transaction::AccessList, other::OtherFields, BlobTransactionSidecar};
use alloy_primitives::{Address, Bytes, B256, U128, U256, U64, U8};
use alloy_primitives::{Address, Bytes, U128, U256, U64, U8};
use serde::{Deserialize, Serialize};

/// Represents _all_ transaction requests received from RPC
Expand Down Expand Up @@ -100,24 +100,3 @@ impl TransactionRequest {
self
}
}

/// 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<B256>,
/// The ETH value to mint on L2
#[serde(rename = "mint", skip_serializing_if = "Option::is_none")]
pub mint: Option<U128>,
/// 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<bool>,
}

impl From<OptimismTransactionFields> for OtherFields {
fn from(value: OptimismTransactionFields) -> Self {
serde_json::to_value(value).unwrap().try_into().unwrap()
}
}