Skip to content

Commit c42f838

Browse files
committed
feat: extract wallet api to own service
1 parent 552ca9a commit c42f838

File tree

8 files changed

+223
-119
lines changed

8 files changed

+223
-119
lines changed

Cargo.lock

Lines changed: 21 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
[workspace]
22
members = [
33
"bin/odyssey/",
4+
"bin/relay/",
45
"crates/node",
56
"crates/e2e-tests",
67
"crates/wallet",
78
"crates/walltime",
89
]
9-
default-members = ["bin/odyssey/"]
10+
default-members = ["bin/odyssey/", "bin/relay/"]
1011
resolver = "2"
1112

1213
[workspace.package]
@@ -148,8 +149,11 @@ alloy-consensus = "0.6.4"
148149
alloy-eips = "0.6.4"
149150
alloy-network = "0.6.4"
150151
alloy-primitives = "0.8.11"
152+
alloy-provider = "0.6.4"
153+
alloy-rpc-client = "0.6.4"
151154
alloy-rpc-types = "0.6.4"
152155
alloy-signer-local = { version = "0.6.4", features = ["mnemonic"] }
156+
alloy-transport = "0.6.4"
153157

154158
# tokio
155159
tokio = { version = "1.21", default-features = false }
@@ -159,7 +163,6 @@ reth-chainspec = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211a
159163
reth-cli = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
160164
reth-cli-util = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
161165
reth-evm = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
162-
reth-rpc-eth-api = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
163166
reth-node-api = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
164167
reth-node-builder = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
165168
reth-node-core = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac", features = [
@@ -185,7 +188,6 @@ reth-provider = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aa
185188
"optimism",
186189
] }
187190
reth-revm = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
188-
reth-storage-api = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
189191
reth-tracing = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
190192
reth-transaction-pool = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
191193
reth-trie-db = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
@@ -210,6 +212,7 @@ serde = "1"
210212
serde_json = "1"
211213
thiserror = "1"
212214
futures = "0.3"
215+
url = "2.5"
213216

214217
# misc-testing
215218
rstest = "0.18.2"

bin/odyssey/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ workspace = true
1515
alloy-signer-local.workspace = true
1616
alloy-network.workspace = true
1717
alloy-primitives.workspace = true
18+
alloy-provider.workspace = true
19+
alloy-rpc-client.workspace = true
1820
odyssey-node.workspace = true
1921
odyssey-wallet.workspace = true
2022
odyssey-walltime.workspace = true

bin/odyssey/src/main.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
2626
use alloy_network::EthereumWallet;
2727
use alloy_primitives::Address;
28+
use alloy_provider::ProviderBuilder;
29+
use alloy_rpc_client::RpcClient;
2830
use alloy_signer_local::PrivateKeySigner;
2931
use clap::Parser;
3032
use eyre::Context;
@@ -70,11 +72,23 @@ fn main() {
7072
.collect::<Result<_, _>>()
7173
.wrap_err("No valid EXP0001 delegations specified")?;
7274

75+
// construct a boxed rpc client
76+
let rpc_client = RpcClient::new_http(
77+
format!(
78+
"http://{}:{}",
79+
ctx.config().rpc.http_addr,
80+
ctx.config().rpc.http_port
81+
)
82+
.parse()
83+
.expect("invalid rpc url, this should not happen"),
84+
)
85+
.boxed();
7386
ctx.modules.merge_configured(
7487
OdysseyWallet::new(
75-
ctx.provider().clone(),
76-
wallet,
77-
ctx.registry.eth_api().clone(),
88+
ProviderBuilder::new()
89+
.with_recommended_fillers()
90+
.wallet(wallet)
91+
.on_client(rpc_client),
7892
ctx.config().chain.chain().id(),
7993
valid_delegations,
8094
)

bin/relay/Cargo.toml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[package]
2+
name = "odyssey-relay"
3+
version.workspace = true
4+
edition.workspace = true
5+
rust-version.workspace = true
6+
license.workspace = true
7+
repository.workspace = true
8+
description = "Odyssey Relay is an EIP-7702 native transaction batcher and sponsor."
9+
10+
[lints]
11+
workspace = true
12+
13+
[dependencies]
14+
alloy-signer-local.workspace = true
15+
alloy-primitives.workspace = true
16+
alloy-provider.workspace = true
17+
alloy-rpc-client.workspace = true
18+
odyssey-wallet.workspace = true
19+
eyre.workspace = true
20+
jsonrpsee = { workspace = true, features = ["server"] }
21+
tracing.workspace = true
22+
clap = { workspace = true, features = ["derive", "env"] }
23+
url.workspace = true
24+
tokio = { workspace = true, features = ["rt", "macros"] }
25+
26+
[features]
27+
default = []
28+
min-error-logs = ["tracing/release_max_level_error"]
29+
min-warn-logs = ["tracing/release_max_level_warn"]
30+
min-info-logs = ["tracing/release_max_level_info"]
31+
min-debug-logs = ["tracing/release_max_level_debug"]
32+
min-trace-logs = ["tracing/release_max_level_trace"]
33+
34+
[[bin]]
35+
name = "relay"
36+
path = "src/main.rs"

bin/relay/src/main.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//! # Odyssey Relay
2+
//!
3+
//! TBD
4+
5+
use alloy_provider::{network::EthereumWallet, Provider, ProviderBuilder};
6+
use alloy_rpc_client::RpcClient;
7+
use alloy_signer_local::PrivateKeySigner;
8+
use clap::Parser;
9+
use eyre::Context;
10+
use jsonrpsee::server::Server;
11+
use odyssey_wallet::{OdysseyWallet, OdysseyWalletApiServer};
12+
use std::net::{IpAddr, Ipv4Addr};
13+
use url::Url;
14+
15+
/// The Odyssey relayer service sponsors transactions for EIP-7702 accounts.
16+
#[derive(Debug, Parser)]
17+
#[command(author, about = "Relay", long_about = None)]
18+
struct Args {
19+
/// The address to serve the RPC on.
20+
#[arg(long = "http.addr", value_name = "ADDR", default_value_t = IpAddr::V4(Ipv4Addr::LOCALHOST))]
21+
address: IpAddr,
22+
/// The port to serve the RPC on.
23+
#[arg(long = "http.port", value_name = "PORT", default_value_t = 9119)]
24+
port: u16,
25+
/// The RPC endpoint of the chain to send transactions to.
26+
#[arg(long, value_name = "RPC_ENDPOINT")]
27+
upstream: Url,
28+
/// The secret key to sponsor transactions with.
29+
#[arg(long, value_name = "SECRET_KEY", env = "RELAY_SK")]
30+
secret_key: String,
31+
}
32+
33+
/// Run the relayer service.
34+
async fn run(args: Args) -> eyre::Result<()> {
35+
let signer: PrivateKeySigner = args.secret_key.parse().wrap_err("Invalid signing key")?;
36+
let wallet = EthereumWallet::from(signer);
37+
let rpc_client = RpcClient::new_http(args.upstream).boxed();
38+
39+
let provider =
40+
ProviderBuilder::new().with_recommended_fillers().wallet(wallet).on_client(rpc_client);
41+
let chain_id = provider.get_chain_id().await?;
42+
43+
let rpc = OdysseyWallet::new(provider, chain_id, vec![]).into_rpc();
44+
45+
let server = Server::builder().http_only().build((args.address, args.port)).await?;
46+
let handle = server.start(rpc);
47+
48+
handle.stopped().await;
49+
50+
Ok(())
51+
}
52+
53+
#[doc(hidden)]
54+
#[tokio::main]
55+
async fn main() {
56+
// Enable backtraces unless a RUST_BACKTRACE value has already been explicitly provided.
57+
if std::env::var_os("RUST_BACKTRACE").is_none() {
58+
std::env::set_var("RUST_BACKTRACE", "1");
59+
}
60+
61+
let args = Args::parse();
62+
if let Err(err) = run(args).await {
63+
eprint!("Error: {err:?}");
64+
std::process::exit(1);
65+
}
66+
}

crates/wallet/Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,14 @@ keywords.workspace = true
1010
categories.workspace = true
1111

1212
[dependencies]
13-
alloy-eips.workspace = true
1413
alloy-network.workspace = true
1514
alloy-primitives.workspace = true
15+
alloy-provider.workspace = true
1616
alloy-rpc-types.workspace = true
17+
alloy-transport.workspace = true
1718

18-
reth-storage-api.workspace = true
19-
reth-rpc-eth-api.workspace = true
2019
reth-optimism-rpc.workspace = true
2120

22-
revm-primitives.workspace = true
23-
2421
jsonrpsee = { workspace = true, features = ["server", "macros"] }
2522
serde = { workspace = true, features = ["derive"] }
2623
thiserror.workspace = true

0 commit comments

Comments
 (0)