Skip to content

Commit

Permalink
feat: extract wallet api to own service
Browse files Browse the repository at this point in the history
  • Loading branch information
onbjerg committed Nov 26, 2024
1 parent 552ca9a commit ba0bc5b
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 118 deletions.
25 changes: 21 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
members = [
"bin/odyssey/",
"bin/relay/",
"crates/node",
"crates/e2e-tests",
"crates/wallet",
Expand Down Expand Up @@ -148,8 +149,11 @@ alloy-consensus = "0.6.4"
alloy-eips = "0.6.4"
alloy-network = "0.6.4"
alloy-primitives = "0.8.11"
alloy-provider = "0.6.4"
alloy-rpc-client = "0.6.4"
alloy-rpc-types = "0.6.4"
alloy-signer-local = { version = "0.6.4", features = ["mnemonic"] }
alloy-transport = "0.6.4"

# tokio
tokio = { version = "1.21", default-features = false }
Expand All @@ -159,7 +163,6 @@ reth-chainspec = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211a
reth-cli = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-cli-util = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-evm = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-rpc-eth-api = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-node-api = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-node-builder = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-node-core = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac", features = [
Expand All @@ -185,7 +188,6 @@ reth-provider = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aa
"optimism",
] }
reth-revm = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-storage-api = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-tracing = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-transaction-pool = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-trie-db = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
Expand All @@ -210,6 +212,7 @@ serde = "1"
serde_json = "1"
thiserror = "1"
futures = "0.3"
url = "2.5"

# misc-testing
rstest = "0.18.2"
2 changes: 2 additions & 0 deletions bin/odyssey/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ workspace = true
alloy-signer-local.workspace = true
alloy-network.workspace = true
alloy-primitives.workspace = true
alloy-provider.workspace = true
alloy-rpc-client.workspace = true
odyssey-node.workspace = true
odyssey-wallet.workspace = true
odyssey-walltime.workspace = true
Expand Down
20 changes: 17 additions & 3 deletions bin/odyssey/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
use alloy_network::EthereumWallet;
use alloy_primitives::Address;
use alloy_provider::ProviderBuilder;
use alloy_rpc_client::RpcClient;
use alloy_signer_local::PrivateKeySigner;
use clap::Parser;
use eyre::Context;
Expand Down Expand Up @@ -70,11 +72,23 @@ fn main() {
.collect::<Result<_, _>>()
.wrap_err("No valid EXP0001 delegations specified")?;

// construct a boxed rpc client
let rpc_client = RpcClient::new_http(
format!(
"http://{}:{}",
ctx.config().rpc.http_addr,
ctx.config().rpc.http_port
)
.parse()
.expect("invalid rpc url, this should not happen"),
)
.boxed();
ctx.modules.merge_configured(
OdysseyWallet::new(
ctx.provider().clone(),
wallet,
ctx.registry.eth_api().clone(),
ProviderBuilder::new()
.with_recommended_fillers()
.wallet(wallet)
.on_client(rpc_client),
ctx.config().chain.chain().id(),
valid_delegations,
)
Expand Down
36 changes: 36 additions & 0 deletions bin/relay/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[package]
name = "odyssey-relay"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
repository.workspace = true
description = "Odyssey Relay is an EIP-7702 native transaction batcher and sponsor."

[lints]
workspace = true

[dependencies]
alloy-signer-local.workspace = true
alloy-primitives.workspace = true
alloy-provider.workspace = true
alloy-rpc-client.workspace = true
odyssey-wallet.workspace = true
eyre.workspace = true
jsonrpsee = { workspace = true, features = ["server"] }
tracing.workspace = true
clap = { workspace = true, features = ["derive"] }
url.workspace = true
tokio = { workspace = true, features = ["rt", "macros"] }

[features]
default = []
min-error-logs = ["tracing/release_max_level_error"]
min-warn-logs = ["tracing/release_max_level_warn"]
min-info-logs = ["tracing/release_max_level_info"]
min-debug-logs = ["tracing/release_max_level_debug"]
min-trace-logs = ["tracing/release_max_level_trace"]

[[bin]]
name = "odyssey-relay"
path = "src/main.rs"
66 changes: 66 additions & 0 deletions bin/relay/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//! # Odyssey Relay
//!
//! TBD
use alloy_provider::{network::EthereumWallet, Provider, ProviderBuilder};
use alloy_rpc_client::RpcClient;
use alloy_signer_local::PrivateKeySigner;
use clap::Parser;
use eyre::Context;
use jsonrpsee::server::Server;
use odyssey_wallet::{OdysseyWallet, OdysseyWalletApiServer};
use std::net::{IpAddr, Ipv4Addr};
use url::Url;

/// The Odyssey relayer service sponsors transactions for EIP-7702 accounts.
#[derive(Debug, Parser)]
#[command(author, about = "Relay", long_about = None)]
struct Args {
/// The address to serve the RPC on.
#[arg(long = "http.addr", value_name = "ADDR", default_value_t = IpAddr::V4(Ipv4Addr::LOCALHOST))]
address: IpAddr,
/// The port to serve the RPC on.
#[arg(long = "http.port", value_name = "PORT", default_value_t = 9119)]
port: u16,
/// The RPC endpoint of the chain to send transactions to.
#[arg(long, value_name = "RPC_ENDPOINT")]
upstream: Url,
/// The secret key to sponsor transactions with.
#[arg(long, value_name = "SECRET_KEY", env = "RELAY_SK")]
secret_key: String,
}

/// Run the relayer service.
async fn run(args: Args) -> eyre::Result<()> {
let signer: PrivateKeySigner = args.secret_key.parse().wrap_err("Invalid signing key")?;
let wallet = EthereumWallet::from(signer);
let rpc_client = RpcClient::new_http(args.upstream).boxed();

let provider =
ProviderBuilder::new().with_recommended_fillers().wallet(wallet).on_client(rpc_client);
let chain_id = provider.get_chain_id().await?;

let rpc = OdysseyWallet::new(provider, chain_id, vec![]).into_rpc();

let server = Server::builder().http_only().build((args.address, args.port)).await?;
let handle = server.start(rpc);

handle.stopped().await;

Ok(())
}

#[doc(hidden)]
#[tokio::main]
async fn main() {
// Enable backtraces unless a RUST_BACKTRACE value has already been explicitly provided.
if std::env::var_os("RUST_BACKTRACE").is_none() {
std::env::set_var("RUST_BACKTRACE", "1");
}

let args = Args::parse();
if let Err(err) = run(args).await {
eprint!("Error: {err:?}");
std::process::exit(1);
}
}
7 changes: 2 additions & 5 deletions crates/wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@ keywords.workspace = true
categories.workspace = true

[dependencies]
alloy-eips.workspace = true
alloy-network.workspace = true
alloy-primitives.workspace = true
alloy-provider.workspace = true
alloy-rpc-types.workspace = true
alloy-transport.workspace = true

reth-storage-api.workspace = true
reth-rpc-eth-api.workspace = true
reth-optimism-rpc.workspace = true

revm-primitives.workspace = true

jsonrpsee = { workspace = true, features = ["server", "macros"] }
serde = { workspace = true, features = ["derive"] }
thiserror.workspace = true
Expand Down
Loading

0 comments on commit ba0bc5b

Please sign in to comment.