-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: extract wallet api to own service
- Loading branch information
Showing
9 changed files
with
431 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[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 | ||
reth-tracing.workspace = true | ||
clap = { workspace = true, features = ["derive", "env"] } | ||
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 = "relay" | ||
path = "src/main.rs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
//! # 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::{AlloyNode, OdysseyWallet, OdysseyWalletApiServer}; | ||
use reth_tracing::Tracer; | ||
use std::net::{IpAddr, Ipv4Addr}; | ||
use tracing::info; | ||
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 _guard = reth_tracing::RethTracer::new().init()?; | ||
|
||
// construct provider | ||
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); | ||
|
||
// get chain id | ||
let chain_id = provider.get_chain_id().await?; | ||
|
||
// construct rpc module | ||
let rpc = OdysseyWallet::new(AlloyNode::new(provider), chain_id).into_rpc(); | ||
|
||
// start server | ||
let server = Server::builder().http_only().build((args.address, args.port)).await?; | ||
info!(addr = ?server.local_addr().unwrap(), "Started relay service"); | ||
|
||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.