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: split rpc types into trace types and rpc types #96

Merged
merged 1 commit into from
Jan 4, 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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ alloy-networks = { version = "0.1.0", path = "crates/networks" }
alloy-pubsub = { version = "0.1.0", path = "crates/pubsub" }
alloy-rpc-client = { version = "0.1.0", path = "crates/rpc-client" }
alloy-rpc-types = { version = "0.1.0", path = "crates/rpc-types" }
alloy-trace-rpc-types = { version = "0.1.0", path = "crates/trace-rpc-types" }
alloy-signer = { version = "0.1.0", path = "crates/signer" }
alloy-signer-aws = { version = "0.1.0", path = "crates/signer-aws" }
alloy-signer-ledger = { version = "0.1.0", path = "crates/signer-ledger" }
Expand Down
1 change: 1 addition & 0 deletions crates/providers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ alloy-networks.workspace = true
alloy-primitives.workspace = true
alloy-rpc-client.workspace = true
alloy-rpc-types.workspace = true
alloy-trace-rpc-types.workspace = true
alloy-transport-http.workspace = true
alloy-transport.workspace = true
async-trait.workspace = true
Expand Down
8 changes: 4 additions & 4 deletions crates/providers/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use crate::utils::{self, EstimatorFunction};
use alloy_primitives::{Address, BlockHash, Bytes, StorageKey, StorageValue, TxHash, U256, U64};
use alloy_rpc_client::{ClientBuilder, RpcClient};
use alloy_rpc_types::{
trace::{
geth::{GethDebugTracingOptions, GethTrace},
parity::LocalizedTransactionTrace,
},
AccessListWithGasUsed, Block, BlockId, BlockNumberOrTag, CallRequest,
EIP1186AccountProofResponse, FeeHistory, Filter, Log, SyncStatus, Transaction,
TransactionReceipt,
};
use alloy_trace_rpc_types::{
geth::{GethDebugTracingOptions, GethTrace},
parity::LocalizedTransactionTrace,
};
use alloy_transport::{BoxTransport, Transport, TransportErrorKind, TransportResult};
use alloy_transport_http::Http;
use auto_impl::auto_impl;
Expand Down
1 change: 0 additions & 1 deletion crates/rpc-types/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pub mod pubsub;
pub mod raw_log;
pub mod state;
mod syncing;
pub mod trace;
pub mod transaction;
pub mod txpool;
pub mod withdrawal;
Expand Down
48 changes: 48 additions & 0 deletions crates/trace-rpc-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[package]
name = "alloy-trace-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.

this should be called alloy-rpc-trace-types

and the folder name rpc-trace-types

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

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
# ethereum
alloy-rlp = { workspace = true, features = ["arrayvec", "derive"] }
alloy-primitives = { workspace = true, features = ["rlp", "serde"] }
alloy-rpc-types.workspace = true
ethereum_ssz_derive = { version = "0.5", optional = true }
ethereum_ssz = { version = "0.5", optional = true }

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

# arbitrary
arbitrary = { version = "1.3", features = ["derive"], optional = true }
proptest = { version = "1.4", optional = true }
proptest-derive = { version = "0.4", optional = true }

# jsonrpsee
jsonrpsee-types = { version = "0.20", optional = true }


[features]
arbitrary = ["dep:arbitrary", "dep:proptest-derive", "dep:proptest", "alloy-primitives/arbitrary"]
jsonrpsee-types = ["dep:jsonrpsee-types"]
ssz = ["dep:ethereum_ssz" ,"dep:ethereum_ssz_derive", "alloy-primitives/ssz"]

[dev-dependencies]
alloy-primitives = { workspace = true, features = ["rand", "rlp", "serde", "arbitrary"] }

arbitrary = { workspace = true, features = ["derive"] }
proptest.workspace = true
proptest-derive.workspace = true
rand.workspace = true
similar-asserts.workspace = true
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! `trace_filter` types and support
use crate::serde_helpers::num::u64_hex_or_decimal_opt;
use alloy_primitives::Address;
use alloy_rpc_types::serde_helpers::num::u64_hex_or_decimal_opt;
use serde::{Deserialize, Serialize};
use std::collections::HashSet;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::serde_helpers::num::from_int_or_hex;
use alloy_primitives::{Address, Bytes, B256, U256};
use alloy_rpc_types::serde_helpers::num::from_int_or_hex;
use serde::{Deserialize, Serialize};

/// The response object for `debug_traceTransaction` with `"tracer": "callTracer"`
Expand Down Expand Up @@ -82,14 +82,13 @@ impl CallConfig {
#[cfg(test)]
mod tests {
use super::*;
use crate::trace::geth::*;
use crate::geth::*;

// See <https://github.com/ethereum/go-ethereum/tree/master/eth/tracers/internal/tracetest/testdata>
const DEFAULT: &str = include_str!("../../../../test_data/call_tracer/default.json");
const LEGACY: &str = include_str!("../../../../test_data/call_tracer/legacy.json");
const ONLY_TOP_CALL: &str =
include_str!("../../../../test_data/call_tracer/only_top_call.json");
const WITH_LOG: &str = include_str!("../../../../test_data/call_tracer/with_log.json");
const DEFAULT: &str = include_str!("../../test_data/call_tracer/default.json");
const LEGACY: &str = include_str!("../../test_data/call_tracer/legacy.json");
const ONLY_TOP_CALL: &str = include_str!("../../test_data/call_tracer/only_top_call.json");
const WITH_LOG: &str = include_str!("../../test_data/call_tracer/with_log.json");

#[test]
fn test_serialize_call_trace() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct FourByteFrame(pub BTreeMap<String, u64>);
#[cfg(test)]
mod tests {
use super::*;
use crate::trace::geth::*;
use crate::geth::*;

const DEFAULT: &str = r#"{
"0x27dc297e-128": 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#![allow(missing_docs)]
//! Geth tracing types

use crate::{state::StateOverride, BlockOverrides};
use alloy_primitives::{Bytes, B256, U256};
use alloy_rpc_types::{state::StateOverride, BlockOverrides};
use serde::{de::DeserializeOwned, ser::SerializeMap, Deserialize, Serialize, Serializer};
use std::{collections::BTreeMap, time::Duration};

Expand All @@ -23,7 +23,7 @@ pub mod noop;
pub mod pre_state;

/// Result type for geth style transaction trace
pub type TraceResult = crate::trace::common::TraceResult<GethTrace, String>;
pub type TraceResult = crate::common::TraceResult<GethTrace, String>;

/// blockTraceResult represents the results of tracing a single block when an entire chain is being
/// traced. ref <https://github.com/ethereum/go-ethereum/blob/ee530c0d5aa70d2c00ab5691a89ab431b73f8165/eth/tracers/api.go#L218-L222>
Expand All @@ -48,7 +48,7 @@ pub struct DefaultFrame {
/// How much gas was used.
pub gas: u64,
/// Output of the transaction
#[serde(serialize_with = "crate::serde_helpers::serialize_hex_string_no_prefix")]
#[serde(serialize_with = "alloy_rpc_types::serde_helpers::serialize_hex_string_no_prefix")]
pub return_value: Bytes,
/// Recorded traces of the transaction
pub struct_logs: Vec<StructLog>,
Expand Down Expand Up @@ -548,7 +548,7 @@ mod tests {
// <https://etherscan.io/tx/0xd01212e8ab48d2fd2ea9c4f33f8670fd1cf0cfb09d2e3c6ceddfaf54152386e5>
#[test]
fn serde_default_frame() {
let input = include_str!("../../../../test_data/default/structlogs_01.json");
let input = include_str!("../../test_data/default/structlogs_01.json");
let _frame: DefaultFrame = serde_json::from_str(input).unwrap();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct Null;
#[cfg(test)]
mod tests {
use super::*;
use crate::trace::geth::*;
use crate::geth::*;

const DEFAULT: &str = r"{}";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::serde_helpers::num::from_int_or_hex_opt;
use alloy_primitives::{Address, Bytes, B256, U256};
use alloy_rpc_types::serde_helpers::num::from_int_or_hex_opt;
use serde::{Deserialize, Serialize};
use std::collections::{btree_map, BTreeMap};

Expand Down Expand Up @@ -225,12 +225,12 @@ impl PreStateConfig {
#[cfg(test)]
mod tests {
use super::*;
use crate::trace::geth::*;
use crate::geth::*;

// See <https://github.com/ethereum/go-ethereum/tree/master/eth/tracers/internal/tracetest/testdata>
const DEFAULT: &str = include_str!("../../../../test_data/pre_state_tracer/default.json");
const LEGACY: &str = include_str!("../../../../test_data/pre_state_tracer/legacy.json");
const DIFF_MODE: &str = include_str!("../../../../test_data/pre_state_tracer/diff_mode.json");
const DEFAULT: &str = include_str!("../../test_data/pre_state_tracer/default.json");
const LEGACY: &str = include_str!("../../test_data/pre_state_tracer/legacy.json");
const DIFF_MODE: &str = include_str!("../../test_data/pre_state_tracer/diff_mode.json");

#[test]
fn test_serialize_pre_state_trace() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//! Builder style functions for `trace_call`

use crate::{
eth::block::BlockId, state::StateOverride, trace::parity::TraceType, BlockOverrides,
CallRequest,
};
use crate::parity::TraceType;
use alloy_rpc_types::{state::StateOverride, BlockId, BlockOverrides, CallRequest};
use serde::{Deserialize, Serialize};
use std::collections::HashSet;

Expand Down
Loading