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: misc improvements #26

Merged
merged 8 commits into from
Nov 14, 2023
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
6 changes: 3 additions & 3 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
* @danipopes @gakonst @prestwich @evalir
* @danipopes @evalir @gakonst @prestwich

crates/json-rpc @prestwich
crates/transports @prestwich @evalir
crates/transports @evalir @prestwich
crates/networks @prestwich
crates/providers @prestwich @evalir
crates/providers @evalir @prestwich
60 changes: 32 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,30 @@ jobs:
rust: ["stable", "beta", "nightly", "1.65"] # MSRV
flags: ["--no-default-features", "", "--all-features"]
exclude:
# Skip because some features have highest MSRV.
- rust: "1.65" # MSRV
flags: "--all-features"
# Skip because some features have highest MSRV.
- rust: "1.65" # MSRV
flags: "--all-features"
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- name: Install Anvil
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
# Only run tests on latest stable and above
- name: build
if: ${{ matrix.rust == '1.65' }} # MSRV
run: cargo build --workspace ${{ matrix.flags }}
- name: test
if: ${{ matrix.rust != '1.65' }} # MSRV
run: cargo test --workspace ${{ matrix.flags }}
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- name: Install Anvil
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
# Only run tests on latest stable and above
- name: build
if: ${{ matrix.rust == '1.65' }} # MSRV
run: cargo build --workspace ${{ matrix.flags }}
- name: test
if: ${{ matrix.rust != '1.65' }} # MSRV
run: cargo test --workspace ${{ matrix.flags }}

wasm:
name: check WASM
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
Expand All @@ -51,47 +51,51 @@ jobs:
with:
targets: wasm32-unknown-unknown
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: check
run: cargo check --workspace --target wasm32-unknown-unknown

feature-checks:
name: feature checks
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: taiki-e/install-action@cargo-hack
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: cargo hack
run: cargo hack check --feature-powerset --depth 2 --all-targets
run: cargo hack check --feature-powerset --depth 2

clippy:
name: clippy
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@clippy
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- run: cargo clippy --workspace --all-targets --all-features
env:
RUSTFLAGS: -Dwarnings

docs:
name: docs
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@nightly
- uses: Swatinem/rust-cache@v2
with:
components: rust-docs
cache-on-failure: true
- run: cargo doc --workspace --all-features --no-deps --document-private-items
env:
RUSTDOCFLAGS: "--cfg docsrs -D warnings"

fmt:
name: fmt
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
Expand Down
28 changes: 13 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,21 @@ alloy-rpc-types = { version = "0.1.0", path = "crates/rpc-types" }
alloy-rpc-client = { version = "0.1.0", path = "crates/rpc-client" }

alloy-primitives = { version = "0.4.2", features = ["serde"] }
alloy-rlp = "0.3.0"
alloy-rlp = "0.3"

# futures
async-trait = "0.1.74"
base64 = "0.21"
bimap = "0.6"
futures = "0.3.29"

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

# thiserror
thiserror = "1.0"

# transports
url = "2.4.0"
pin-project = "1.1.2"
reqwest = "0.11.18"
hyper = "0.14.27"
itertools = "0.11"
pin-project = "1.1"
reqwest = "0.11.18"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_with = "3.4"
thiserror = "1.0"
tokio = { version = "1.33", features = ["sync", "macros"] }
tower = { version = "0.4.13", features = ["util"] }
tokio = { version = "1.33.0", features = ["sync", "macros"] }
tracing = "0.1.40"
url = "2.4"
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
msrv = "1.65"
8 changes: 4 additions & 4 deletions crates/json-rpc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[package]
name = "alloy-json-rpc"
description = "Core types for JSON-RPC2.0 clients"

version.workspace = true
edition.workspace = true
rust-version.workspace = true
Expand All @@ -9,9 +11,7 @@ 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]
alloy-primitives.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json = { version = "1.0.103", features = ["raw_value"] }
serde.workspace = true
serde_json = { workspace = true, features = ["raw_value"] }
19 changes: 6 additions & 13 deletions crates/json-rpc/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,23 +158,16 @@ mod test {
#[test]
fn it_serializes_and_deserializes() {
let cases = [
TestCase { id: Id::Number(1) },
TestCase { id: Id::String("foo".to_string()) },
TestCase { id: Id::None },
(TestCase { id: Id::Number(1) }, r#"{"id":1}"#),
(TestCase { id: Id::String("foo".to_string()) }, r#"{"id":"foo"}"#),
(TestCase { id: Id::None }, r#"{"id":null}"#),
];

let serialized = [r#"{"id":1}"#, r#"{"id":"foo"}"#, r#"{"id":null}"#];

for i in 0..3 {
let case = &cases[i];
let expected = serialized[i];
dbg!(&expected);

let serialized = serde_json::to_string(case).unwrap();
for (case, expected) in cases {
let serialized = serde_json::to_string(&case).unwrap();
assert_eq!(serialized, expected);

let deserialized: TestCase = serde_json::from_str(expected).unwrap();
assert_eq!(&deserialized, case);
assert_eq!(deserialized, case);
}
}
}
40 changes: 22 additions & 18 deletions crates/json-rpc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
#![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
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![deny(unused_must_use, rust_2018_idioms)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

//! Alloy JSON-RPC data types.
//!
//! This crate provides data types for use with the JSON-RPC 2.0 protocol. It
Expand Down Expand Up @@ -54,6 +38,25 @@
//! with [`RpcResult::deserialize_success::<U>`], which will transform it to an
//! [`RpcResult<U>`]. Or the caller may use [`RpcResult::try_success_as::<U>`]
//! to attempt to deserialize without transforming the [`RpcResult`].

#![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
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![deny(unused_must_use, rust_2018_idioms)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

use serde::{de::DeserializeOwned, Serialize};

mod notification;
pub use notification::{EthNotification, PubSubItem};

Expand All @@ -75,13 +78,12 @@ pub use common::Id;
mod result;
pub use result::{BorrowedRpcResult, RpcResult};

use serde::{de::DeserializeOwned, Serialize};

/// An object that can be used as a JSON-RPC parameter.
///
/// This marker trait is blanket-implemented for every qualifying type. It is
/// used to indicate that a type can be used as a JSON-RPC parameter.
pub trait RpcParam: Serialize + Clone + Send + Sync + Unpin {}

impl<T> RpcParam for T where T: Serialize + Clone + Send + Sync + Unpin {}

/// An object that can be used as a JSON-RPC return value.
Expand All @@ -95,6 +97,7 @@ impl<T> RpcParam for T where T: Serialize + Clone + Send + Sync + Unpin {}
/// This is a simplification that makes it easier to use the types in client
/// code. It is not suitable for use in server code.
pub trait RpcReturn: DeserializeOwned + Send + Sync + Unpin + 'static {}

impl<T> RpcReturn for T where T: DeserializeOwned + Send + Sync + Unpin + 'static {}

/// An object that can be used as a JSON-RPC parameter and return value.
Expand All @@ -103,4 +106,5 @@ impl<T> RpcReturn for T where T: DeserializeOwned + Send + Sync + Unpin + 'stati
/// used to indicate that a type can be used as both a JSON-RPC parameter and
/// return value.
pub trait RpcObject: RpcParam + RpcReturn {}

impl<T> RpcObject for T where T: RpcParam + RpcReturn {}
3 changes: 1 addition & 2 deletions crates/json-rpc/src/notification.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::{Response, ResponsePayload};
use alloy_primitives::U256;
use serde::{
de::{MapAccess, Visitor},
Deserialize, Serialize,
};

use crate::{Response, ResponsePayload};

/// An ethereum-style notification, not to be confused with a JSON-RPC
/// notification.
#[derive(Debug, Clone, Deserialize, Serialize)]
Expand Down
1 change: 0 additions & 1 deletion crates/json-rpc/src/request.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::{common::Id, RpcParam};

use alloy_primitives::{keccak256, B256};
use serde::{de::DeserializeOwned, ser::SerializeMap, Deserialize, Serialize};
use serde_json::value::RawValue;
Expand Down
17 changes: 8 additions & 9 deletions crates/json-rpc/src/response/mod.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
mod error;
pub use error::{BorrowedErrorPayload, ErrorPayload};

mod payload;
pub use payload::{BorrowedResponsePayload, ResponsePayload};

use std::{borrow::Borrow, fmt, marker::PhantomData};

use crate::common::Id;
use serde::{
de::{DeserializeOwned, MapAccess, Visitor},
Deserialize, Deserializer,
};
use serde_json::value::RawValue;
use std::{borrow::Borrow, fmt, marker::PhantomData};

mod error;
pub use error::{BorrowedErrorPayload, ErrorPayload};

mod payload;
pub use payload::{BorrowedResponsePayload, ResponsePayload};

use crate::common::Id;
/// A JSONRPC-2.0 response object containing a [`ResponsePayload`].
///
/// This object is used to represent a JSONRPC-2.0 response. It may contain
Expand Down
6 changes: 2 additions & 4 deletions crates/json-rpc/src/response/payload.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::borrow::Borrow;

use crate::ErrorPayload;
use serde::{de::DeserializeOwned, Deserialize};
use serde_json::value::RawValue;

use crate::ErrorPayload;
use std::borrow::Borrow;

/// A JSONRPC-2.0 response payload.
///
Expand Down
3 changes: 1 addition & 2 deletions crates/json-rpc/src/result.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::{ErrorPayload, Response, ResponsePayload, RpcReturn};
use serde::Deserialize;
use serde_json::value::RawValue;
use std::{borrow::Borrow, fmt::Debug};

use crate::{ErrorPayload, Response, ResponsePayload, RpcReturn};

/// The result of a JSON-RPC request.
///
/// Either a success response, an error response, or a non-response error. The
Expand Down
6 changes: 2 additions & 4 deletions crates/networks/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[package]
name = "alloy-networks"
description = "Ethereum blockchain RPC behavior abstraction"

version.workspace = true
edition.workspace = true
rust-version.workspace = true
Expand All @@ -8,12 +10,8 @@ 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]
alloy-json-rpc.workspace = true
alloy-primitives.workspace = true
alloy-rlp.workspace = true
alloy-transport.workspace = true
pin-project.workspace = true
tower.workspace = true
2 changes: 1 addition & 1 deletion crates/networks/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# alloy-networks

Ethereum blockchain RPC behavior abstraction for Alloy.
Ethereum blockchain RPC behavior abstraction.

This crate contains a simple abstraction of the RPC behavior of an
Ethereum-like blockchain. It is intended to be used by the Alloy client to
Expand Down
Loading