Skip to content

Commit

Permalink
feat: improve and complete alloy prelude crate feature flag compati…
Browse files Browse the repository at this point in the history
…blity (#421)

* add exports

* try re-exports

* add pubsub to provider

* add missing `native-keccak` re-export from `alloy/core`

* major refactor

* clean up

* create top-level configurations of reqwest, hyper

* fix missing json export

* top level definitions of hyper, reqwest

* remove imports, misunderstood how core was exporting

* fix clippy issues

* let top level `hyper` and `reqwest` defs flow to rpc-client and transport

* fix flag, reqwest-default-tls

* pull in latest main, use changes in `alloy-provider` reqwest and hyper fields

* fix nit
  • Loading branch information
zerosnacks authored Apr 2, 2024
1 parent 8acf6af commit 27d5ba9
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 83 deletions.
159 changes: 103 additions & 56 deletions crates/alloy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,33 @@ repository.workspace = true
exclude.workspace = true

[dependencies]
alloy-core = { workspace = true, default-features = false, features = ["std"] }
# core
alloy-core = { workspace = true, default-features = false }

# alloy
alloy-consensus = { workspace = true, default-features = false, optional = true }
alloy-contract = { workspace = true, default-features = false, optional = true }
alloy-eips = { workspace = true, default-features = false, optional = true }
alloy-genesis = { workspace = true, default-features = false, optional = true }
alloy-network = { workspace = true, default-features = false, optional = true }
alloy-node-bindings = { workspace = true, default-features = false, optional = true }

# providers
alloy-provider = { workspace = true, default-features = false, optional = true }
alloy-pubsub = { workspace = true, optional = true }

# pubsub
alloy-pubsub = { workspace = true, default-features = false, optional = true }

# rpc
alloy-json-rpc = { workspace = true, default-features = false, optional = true }
alloy-rpc-client = { workspace = true, optional = true }
alloy-rpc-client = { workspace = true, default-features = false, optional = true }
alloy-rpc-engine-types = { workspace = true, default-features = false, optional = true }
alloy-rpc-trace-types = { workspace = true, default-features = false, optional = true }
alloy-rpc-types = { workspace = true, default-features = false, optional = true }

# serde
alloy-serde = { workspace = true, default-features = false, optional = true }

# signer
alloy-signer = { workspace = true, default-features = false, optional = true }
alloy-signer-aws = { workspace = true, default-features = false, optional = true }
Expand All @@ -41,95 +50,133 @@ alloy-signer-wallet = { workspace = true, default-features = false, optional = t
# transport
alloy-transport = { workspace = true, default-features = false, optional = true }
alloy-transport-http = { workspace = true, default-features = false, optional = true }
reqwest = { workspace = true, default-features = false, optional = true }
alloy-transport-ipc = { workspace = true, default-features = false, optional = true }
alloy-transport-ws = { workspace = true, default-features = false, optional = true }

[features]
default = ["transport-http-reqwest", "default-tls"]
# optional
reqwest = { workspace = true, optional = true }
hyper = { workspace = true, optional = true }

# alloy-core
dyn-abi = ["alloy-core/dyn-abi"]
json-abi = ["alloy-core/json-abi"]
json = ["alloy-core/json"]
sol-types = ["alloy-core/sol-types"]
# ----------------------------------------- Configuration ---------------------------------------- #

tiny-keccak = ["alloy-core/tiny-keccak"]
asm-keccak = ["alloy-core/asm-keccak"]
[features]
default = ["std", "reqwest"]

# std
std = [
"alloy-core/std",
"alloy-eips?/std",
"alloy-genesis?/std",
"alloy-serde?/std",
]

postgres = ["alloy-core/postgres"]
getrandom = ["alloy-core/getrandom"]
rand = ["alloy-core/rand"]
rlp = ["alloy-core/rlp"]
serde = ["alloy-core/serde", "alloy-eips?/serde"]
ssz = ["alloy-core/ssz", "alloy-rpc-types?/ssz", "alloy-rpc-engine-types?/ssz"]
arbitrary = [
"alloy-core/arbitrary",
"alloy-consensus?/arbitrary",
"alloy-eips?/arbitrary",
"alloy-rpc-types?/arbitrary",
# configuration
reqwest = [
"dep:reqwest",
"alloy-rpc-client?/reqwest",
"alloy-provider?/reqwest",
"alloy-transport-http?/reqwest",
"alloy-transport-http?/reqwest-default-tls",
]
k256 = ["alloy-core/k256", "alloy-consensus?/k256", "alloy-network?/k256"]
eip712 = [
"alloy-core/eip712",
"alloy-signer?/eip712",
"alloy-signer-aws?/eip712",
"alloy-signer-gcp?/eip712",
"alloy-signer-ledger?/eip712",
# TODO: https://github.com/alloy-rs/alloy/issues/201
# "alloy-signer-trezor?/eip712",
hyper = [
"dep:hyper",
"alloy-rpc-client?/hyper",
"alloy-provider?/hyper",
"alloy-transport-http?/hyper",
]

# alloy
default-tls = ["reqwest?/default-tls"]
jsonrpsee-types = ["alloy-rpc-types?/jsonrpsee-types", "alloy-rpc-engine-types?/jsonrpsee-types"]
# ---------------------------------------- Main re-exports --------------------------------------- #

# general
consensus = ["dep:alloy-consensus"]
contract = ["dep:alloy-contract", "dyn-abi", "json-abi", "json", "sol-types"]
eips = ["dep:alloy-eips"]
network = ["dep:alloy-network"]
genesis = ["dep:alloy-genesis"]
network = ["dep:alloy-network"]
node-bindings = ["dep:alloy-node-bindings"]

contract = ["dep:alloy-contract", "dyn-abi", "json-abi", "json", "sol-types"]

## providers
# providers
providers = ["dep:alloy-provider"]
provider-http = ["providers", "transport-http"]
provider-ws = ["providers", "transport-ws"]
provider-ipc = ["providers", "transport-ipc"]

## pubsub
pubsub = ["dep:alloy-pubsub"]
provider-ws = ["providers", "alloy-provider?/pubsub", "transport-ws"]
provider-ipc = ["providers", "alloy-provider?/pubsub", "transport-ipc"]

# pubsub
pubsub = [
"dep:alloy-pubsub",
"alloy-provider?/pubsub",
"alloy-rpc-client?/pubsub",
]

## rpc
# rpc
rpc = []
json-rpc = ["rpc", "dep:alloy-json-rpc"]
rpc-client = ["rpc", "dep:alloy-rpc-client"]
rpc-client-ws = ["rpc", "alloy-rpc-client?/ws"]
rpc-client-ipc = ["rpc", "alloy-rpc-client?/ipc"]
rpc-types = ["rpc"]
rpc-types-eth = ["rpc-types", "dep:alloy-rpc-types"]
rpc-types-engine = ["rpc-types", "dep:alloy-rpc-engine-types"]
rpc-types-json = [
"alloy-rpc-types?/jsonrpsee-types",
"alloy-rpc-engine-types?/jsonrpsee-types",
]
rpc-types-trace = ["rpc-types", "dep:alloy-rpc-trace-types"]

## signers
# signers
signers = ["dep:alloy-signer"]
### Signer implementations
signer-wallet = ["signers", "dep:alloy-signer-wallet"]
signer-keystore = ["signer-wallet", "alloy-signer-wallet?/keystore"]
signer-mnemonic = ["signer-wallet", "alloy-signer-wallet?/mnemonic"]
signer-mnemonic-all-languages = ["signer-mnemonic", "alloy-signer-wallet?/mnemonic-all-languages"]
signer-yubihsm = ["signer-wallet", "alloy-signer-wallet?/yubihsm"]
signer-aws = ["signers", "dep:alloy-signer-aws"]
signer-gcp = ["signers", "dep:alloy-signer-gcp"]
signer-ledger = ["signers", "dep:alloy-signer-ledger"]
signer-ledger-browser = ["signer-ledger", "alloy-signer-ledger?/browser"]
signer-ledger-node = ["signer-ledger", "alloy-signer-ledger?/node"]
signer-trezor = ["signers", "dep:alloy-signer-trezor"]
signer-wallet = ["signers", "dep:alloy-signer-wallet"]
signer-keystore = ["signer-wallet", "alloy-signer-wallet?/keystore"]
signer-mnemonic = ["signer-wallet", "alloy-signer-wallet?/mnemonic"]
signer-mnemonic-all-languages = [
"signer-mnemonic",
"alloy-signer-wallet?/mnemonic-all-languages",
]
signer-yubihsm = ["signer-wallet", "alloy-signer-wallet?/yubihsm"]

## transports
# transports
transports = ["dep:alloy-transport"]
transport-http = ["transports", "dep:alloy-transport-http"]
transport-http-reqwest = ["dep:reqwest", "alloy-transport-http?/reqwest"]
transport-http-hyper = ["alloy-transport-http?/hyper"]
transport-ipc = ["transports", "pubsub", "dep:alloy-transport-ipc"]
transport-ipc-mock = ["alloy-transport-ipc?/mock"]
transport-ws = ["transports", "pubsub", "dep:alloy-transport-ws"]

# ---------------------------------------- Core re-exports --------------------------------------- #

dyn-abi = ["alloy-core/dyn-abi"]
json-abi = ["alloy-core/json-abi"]
json = ["alloy-core/json"]
sol-types = ["alloy-core/sol-types"]

tiny-keccak = ["alloy-core/tiny-keccak"]
native-keccak = ["alloy-core/native-keccak"]
asm-keccak = ["alloy-core/asm-keccak"]

postgres = ["alloy-core/postgres"]
getrandom = ["alloy-core/getrandom"]
rand = ["alloy-core/rand"]
rlp = ["alloy-core/rlp"]
serde = ["alloy-core/serde", "alloy-eips?/serde", "alloy-serde"]
ssz = ["alloy-core/ssz", "alloy-rpc-types?/ssz", "alloy-rpc-engine-types?/ssz"]
arbitrary = [
"alloy-core/arbitrary",
"alloy-consensus?/arbitrary",
"alloy-eips?/arbitrary",
"alloy-rpc-types?/arbitrary",
]
k256 = ["alloy-core/k256", "alloy-consensus?/k256", "alloy-network?/k256"]
eip712 = [
"alloy-core/eip712",
"alloy-signer?/eip712",
"alloy-signer-aws?/eip712",
"alloy-signer-gcp?/eip712",
"alloy-signer-ledger?/eip712",
# TODO: https://github.com/alloy-rs/alloy/issues/201
# "alloy-signer-trezor?/eip712",
]
66 changes: 39 additions & 27 deletions crates/alloy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,11 @@
#![deny(unused_must_use, rust_2018_idioms)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

// Just for features.
#[cfg(feature = "transport-http-reqwest")]
use reqwest as _;

/* --------------------------------------- Core re-exports -------------------------------------- */

// Re-export the core crate.
// This should generally not be used by downstream crates as we re-export everything else
// individually.
// It is acceptable to use this if an item has been added to `alloy-core` and it has not been added
// to the re-exports below.
// individually. It is acceptable to use this if an item has been added to `alloy-core`
// and it has not been added to the re-exports below.
#[doc(hidden)]
pub use alloy_core as core;

Expand All @@ -45,7 +39,9 @@ pub use self::core::json_abi;
#[cfg(feature = "sol-types")]
#[doc(inline)]
pub use self::core::sol_types;
#[cfg(all(doc, feature = "sol-types"))] // Show this re-export in docs instead of the wrapper below.

// Show this re-export in docs instead of the wrapper below.
#[cfg(all(doc, feature = "sol-types"))]
#[doc(no_inline)]
pub use sol_types::sol;

Expand All @@ -70,6 +66,12 @@ macro_rules! sol {

/* --------------------------------------- Main re-exports -------------------------------------- */

#[cfg(feature = "reqwest")]
use reqwest as _;

#[cfg(feature = "hyper")]
use hyper as _;

#[cfg(feature = "contract")]
#[doc(inline)]
pub use alloy_contract as contract;
Expand Down Expand Up @@ -103,6 +105,24 @@ pub mod providers {
pub use alloy_provider::*;
}

/// Ethereum JSON-RPC publish-subscribe tower service and type definitions.
///
/// You will likely not need to use this module;
/// see the [`providers`] module for high-level usage of pubsub.
///
/// See [`alloy_pubsub`] for more details.
#[doc = "\n"] // Empty doc line `///` gets deleted by rustfmt.
#[cfg_attr(feature = "providers", doc = "[`providers`]: crate::providers")]
#[cfg_attr(
not(feature = "providers"),
doc = "[`providers`]: https://github.com/alloy-rs/alloy/tree/main/crates/provider"
)]
#[cfg(feature = "pubsub")]
pub mod pubsub {
#[doc(inline)]
pub use alloy_pubsub::*;
}

/// Ethereum JSON-RPC client and types.
#[cfg(feature = "rpc")]
pub mod rpc {
Expand Down Expand Up @@ -131,6 +151,10 @@ pub mod rpc {
}
}

#[cfg(feature = "serde")]
#[doc(inline)]
pub use alloy_serde as serde;

/// Ethereum signer abstraction and implementations.
///
/// See [`alloy_signer`] for more details.
Expand All @@ -142,15 +166,19 @@ pub mod signers {
#[cfg(feature = "signer-aws")]
#[doc(inline)]
pub use alloy_signer_aws as aws;

#[cfg(feature = "signer-gcp")]
#[doc(inline)]
pub use alloy_signer_gcp as gcp;

#[cfg(feature = "signer-ledger")]
#[doc(inline)]
pub use alloy_signer_ledger as ledger;

#[cfg(feature = "signer-trezor")]
#[doc(inline)]
pub use alloy_signer_trezor as trezor;

#[cfg(feature = "signer-wallet")]
#[doc(inline)]
pub use alloy_signer_wallet as wallet;
Expand All @@ -176,28 +204,12 @@ pub mod transports {
#[cfg(feature = "transport-http")]
#[doc(inline)]
pub use alloy_transport_http as http;

#[cfg(feature = "transport-ipc")]
#[doc(inline)]
pub use alloy_transport_ipc as ipc;

#[cfg(feature = "transport-ws")]
#[doc(inline)]
pub use alloy_transport_ws as ws;
}

/// Ethereum JSON-RPC publish-subscribe tower service and type definitions.
///
/// You will likely not need to use this module;
/// see the [`providers`] module for high-level usage of pubsub.
///
/// See [`alloy_pubsub`] for more details.
#[doc = "\n"] // Empty doc line `///` gets deleted by rustfmt.
#[cfg_attr(feature = "providers", doc = "[`providers`]: crate::providers")]
#[cfg_attr(
not(feature = "providers"),
doc = "[`providers`]: https://github.com/alloy-rs/alloy/tree/main/crates/provider"
)]
#[cfg(feature = "pubsub")]
pub mod pubsub {
#[doc(inline)]
pub use alloy_pubsub::*;
}
1 change: 1 addition & 0 deletions crates/provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ alloy-node-bindings.workspace = true
alloy-rlp.workspace = true
alloy-signer.workspace = true
alloy-signer-wallet.workspace = true

tokio = { workspace = true, features = ["macros"] }
tracing-subscriber = { workspace = true, features = ["fmt"] }
tempfile.workspace = true
Expand Down

0 comments on commit 27d5ba9

Please sign in to comment.