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

chore: move blob tx sidecar #129

Merged
merged 1 commit into from
Jan 18, 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
2 changes: 1 addition & 1 deletion crates/rpc-engine-types/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use alloy_primitives::{Address, Bloom, Bytes, B256, B64, U256};
use alloy_rpc_types::{
kzg::{Blob, Bytes48},
transaction::request::BlobTransactionSidecar,
transaction::BlobTransactionSidecar,
withdrawal::Withdrawal,
};
use serde::{ser::SerializeMap, Deserialize, Deserializer, Serialize, Serializer};
Expand Down
16 changes: 16 additions & 0 deletions crates/rpc-types/src/eth/transaction/blob.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//! EIP-4844 related types.

use crate::kzg::{Blob, Bytes48};
use serde::{Deserialize, Serialize};

/// This represents a set of blobs, and its corresponding commitments and proofs.
#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
#[repr(C)]
pub struct BlobTransactionSidecar {
/// The blob data.
pub blobs: Vec<Blob>,
/// The blob commitments.
pub commitments: Vec<Bytes48>,
/// The blob proofs.
pub proofs: Vec<Bytes48>,
}
3 changes: 3 additions & 0 deletions crates/rpc-types/src/eth/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use crate::eth::other::OtherFields;
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};
use serde::{Deserialize, Serialize};
Expand All @@ -15,6 +16,8 @@ mod receipt;
pub mod request;
mod signature;

mod blob;

/// Transaction object used in RPC
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand Down
59 changes: 22 additions & 37 deletions crates/rpc-types/src/eth/transaction/request.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
//! Alloy basic Transaction Request type.
use crate::{
eth::transaction::AccessList,
kzg::{Blob, Bytes48},
other::OtherFields,
};
use crate::{eth::transaction::AccessList, other::OtherFields, BlobTransactionSidecar};
use alloy_primitives::{Address, Bytes, B256, U128, U256, U64, U8};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -47,38 +43,6 @@ pub struct TransactionRequest {
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()
}
}

/// This represents a set of blobs, and its corresponding commitments and proofs.
#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
#[repr(C)]
pub struct BlobTransactionSidecar {
/// The blob data.
pub blobs: Vec<Blob>,
/// The blob commitments.
pub commitments: Vec<Bytes48>,
/// The blob proofs.
pub proofs: Vec<Bytes48>,
}
// == impl TransactionRequest ==

impl TransactionRequest {
Expand Down Expand Up @@ -136,3 +100,24 @@ 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()
}
}