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: op-rpc-types crate #6

Merged
merged 28 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0582d5c
chore: add serde and alloy_primitives to the dependencies
EmperorOrokuSaki Apr 10, 2024
dbdcda9
feat: add transaction receipt type without tests + several dependencies.
EmperorOrokuSaki Apr 10, 2024
1ebd0e0
feat: add log
EmperorOrokuSaki Apr 10, 2024
15eb436
feat: add txtype, deposit nonce, and receipt version.
EmperorOrokuSaki Apr 10, 2024
599c9a2
feat: add block.
EmperorOrokuSaki Apr 10, 2024
2def3b0
feat: add txType as a separate file under transactions and update rec…
EmperorOrokuSaki Apr 10, 2024
6b0c42a
refactor: update optimism specific fields and their (de)serialization…
EmperorOrokuSaki Apr 10, 2024
87742c3
docs: remove outdated documentation.
EmperorOrokuSaki Apr 10, 2024
516eb59
feat: add transaction, and request types. Adjust block to use the cra…
EmperorOrokuSaki Apr 10, 2024
fafe2aa
feat: add op-consensus and receiptEnvelope
EmperorOrokuSaki Apr 11, 2024
2599060
feat: add call.rs and update visibility of transaction requests, type…
EmperorOrokuSaki Apr 11, 2024
d5c9b78
lint: cargo fmt.
EmperorOrokuSaki Apr 11, 2024
b9169e9
feat: add pubsub.rs
EmperorOrokuSaki Apr 12, 2024
f1675b9
feat: fix imports, add TODO comments, organize the code.
EmperorOrokuSaki Apr 12, 2024
d939344
lint: cargo fmt
EmperorOrokuSaki Apr 12, 2024
5dbd2f5
fix: receipt.rs imports are fixed.
EmperorOrokuSaki Apr 12, 2024
2304918
feat: add filters.rs
EmperorOrokuSaki Apr 12, 2024
2ad3438
feat: re-export all eth types.
EmperorOrokuSaki Apr 12, 2024
6a72e80
feat: review changes.
EmperorOrokuSaki Apr 15, 2024
93141f0
refactor: re-import instead of redefining.
EmperorOrokuSaki Apr 18, 2024
b5005c9
chore: bump alloy version.
EmperorOrokuSaki Apr 20, 2024
577749e
feat: use generics, remove unnecessary types.
EmperorOrokuSaki Apr 20, 2024
0744884
lint: fmt
EmperorOrokuSaki Apr 20, 2024
12195e1
refactor: use native types
EmperorOrokuSaki Apr 25, 2024
cf248d4
chore: bump alloy version
EmperorOrokuSaki Apr 25, 2024
a6ce409
some cleanup
mattsse Apr 27, 2024
6e78b1e
allow git
mattsse Apr 27, 2024
8bb4138
allow
mattsse Apr 27, 2024
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
18 changes: 18 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ homepage = "https://github.com/alloy-rs/op-alloy"
repository = "https://github.com/alloy-rs/op-alloy"
exclude = ["benches/", "tests/"]

[workspace.dependencies]
# Alloy
alloy-primitives = { version = "0.7.1", default-features = false }
alloy = { git = "https://github.com/alloy-rs/alloy", rev = "55a278c" }
alloy-consensus = { git = "https://github.com/alloy-rs/alloy", rev = "55a278c" }
alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "55a278c" }
alloy-op-rpc-types = { version = "0.1.0", path = "crates/rpc-types" }

# Serde
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] }
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }

## misc-testing
arbitrary = { version = "1.3", features = ["derive"] }
rand = "0.8"
proptest = "1.4"
proptest-derive = "0.4"

[workspace.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
12 changes: 0 additions & 12 deletions crates/op-rpc-types/Cargo.toml

This file was deleted.

1 change: 0 additions & 1 deletion crates/op-rpc-types/src/lib.rs

This file was deleted.

39 changes: 39 additions & 0 deletions crates/rpc-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[package]
name = "alloy-op-rpc-types"
description = "Optimism RPC types"

version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
homepage.workspace = true
authors.workspace = true
repository.workspace = true
exclude.workspace = true

[dependencies]
alloy-primitives = { workspace = true, features = ["rlp", "serde", "std"] }
alloy-consensus = { workspace = true, features = ["std", "serde"] }
alloy-rpc-types.workspace = true

serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true

# arbitrary
arbitrary = { version = "1.3", features = ["derive"], optional = true }

[dev-dependencies]
alloy-primitives = { workspace = true, features = ["arbitrary"] }
alloy-consensus = { workspace = true, features = ["arbitrary"] }
alloy-rpc-types = { workspace = true, features = ["arbitrary"] }

arbitrary = { workspace = true, features = ["derive"] }
rand.workspace = true

[features]
arbitrary = [
"dep:arbitrary",
"alloy-primitives/arbitrary",
"alloy-consensus/arbitrary",
"alloy-rpc-types/arbitrary",
]
3 changes: 3 additions & 0 deletions crates/rpc-types/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# alloy-rpc-types

Ethereum RPC-related types for Alloy.
17 changes: 17 additions & 0 deletions crates/rpc-types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#![doc = include_str!("../README.md")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/alloy.jpg",
html_favicon_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/favicon.ico"
)]
#![warn(
missing_copy_implementations,
missing_debug_implementations,
missing_docs,
unreachable_pub,
clippy::missing_const_for_fn,
rustdoc::all
)]
#![deny(unused_must_use, rust_2018_idioms)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

pub mod transaction;
31 changes: 31 additions & 0 deletions crates/rpc-types/src/transaction/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//! Optimism specific types related to transactions.

use alloy_primitives::B256;
use serde::{Deserialize, Serialize};

pub use self::tx_type::TxType;

pub mod tx_type;

/// OP Transaction type
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[serde(rename_all = "camelCase")]
pub struct Transaction {
/// Ethereum Transaction Types
#[serde(flatten)]
pub inner: alloy_rpc_types::Transaction,
/// The ETH value to mint on L2
#[serde(rename = "mint", skip_serializing_if = "Option::is_none")]
pub mint: Option<u128>,
/// Hash that uniquely identifies the source of the deposit.
#[serde(rename = "sourceHash", skip_serializing_if = "Option::is_none")]
pub source_hash: Option<B256>,
/// 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>,
/// Deposit receipt version for deposit transactions post-canyon
#[serde(skip_serializing_if = "Option::is_none")]
pub deposit_receipt_version: Option<u64>,
}
49 changes: 49 additions & 0 deletions crates/rpc-types/src/transaction/tx_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//! OP transaction identifiers.

use serde::{Deserialize, Serialize};

/// Identifier for legacy transaction, however a legacy tx is technically not
/// typed.
pub const LEGACY_TX_TYPE_ID: u8 = 0;

/// Identifier for an EIP2930 transaction.
pub const EIP2930_TX_TYPE_ID: u8 = 1;

/// Identifier for an EIP1559 transaction.
pub const EIP1559_TX_TYPE_ID: u8 = 2;

/// Identifier for an EIP4844 transaction.
pub const EIP4844_TX_TYPE_ID: u8 = 3;

/// Identifier for an Optimism deposit transaction
pub const DEPOSIT_TX_TYPE_ID: u8 = 126;

/// Transaction Type
#[derive(
Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Default, Serialize, Deserialize, Hash,
)]
pub enum TxType {
/// Legacy transaction pre EIP-2929
#[default]
Legacy = 0_isize,
/// AccessList transaction
Eip2930 = 1_isize,
/// Transaction with Priority fee
Eip1559 = 2_isize,
/// Shard Blob Transactions - EIP-4844
Eip4844 = 3_isize,
/// Optimism Deposit transaction.
Deposit = 126_isize,
}

impl From<TxType> for u8 {
fn from(value: TxType) -> Self {
match value {
TxType::Legacy => LEGACY_TX_TYPE_ID,
TxType::Eip2930 => EIP2930_TX_TYPE_ID,
TxType::Eip1559 => EIP1559_TX_TYPE_ID,
TxType::Eip4844 => EIP4844_TX_TYPE_ID,
TxType::Deposit => DEPOSIT_TX_TYPE_ID,
}
}
}
7 changes: 4 additions & 3 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ notice = "warn"

[bans]
multiple-versions = "warn"
wildcards = "deny"
wildcards = "allow"
highlight = "all"

[licenses]
Expand Down Expand Up @@ -52,5 +52,6 @@ license-files = [{ path = "LICENSE", hash = 0x001c7e6c }]
[sources]
unknown-registry = "deny"
unknown-git = "deny"
# TODO: Remove once alloy-contract is stable. This is only used in tests for `sol!`.
allow-git = ["https://github.com/alloy-rs/core"]
allow-git = [
"https://github.com/alloy-rs/alloy",
]
Loading