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

TUI #28

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

TUI #28

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
789 changes: 756 additions & 33 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ members = [
"crates/extension/injected/",
"crates/extension/injector/",
"crates/extension/browser-ui/",
"crates/tui/",
]
default-members = ["bin/rpc"]
default-members = ["bin/rpc", "crates/tui"]

# Explicitly set the resolver to version 2, which is the default for packages with edition >= 2021
# https://doc.rust-lang.org/edition-guide/rust-2021/default-cargo-resolver.html
Expand Down Expand Up @@ -48,6 +49,9 @@ gloo-timers = { version = "0.3.0", features = ["futures"] }
console_error_panic_hook = "0.1.7"

alloy-chains = { version = "0.1.47", features = ["serde"] }
alloy-signer = { version = "0.8.3" }
alloy-signer-local = { version = "0.8.3", features = ["keystore"] }
alloy-primitives = { version = "0.8.3" }

chrome-sys = { path = "crates/extension/chrome-sys" }
worker = { path = "crates/extension/worker" }
Expand Down
14 changes: 12 additions & 2 deletions bin/rpc/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@ use clap::Parser;
#[command(about)]
pub struct Cli {
/// Address to listen for browser extension WebSocket requests
#[arg(short, long, value_name = "ADDR", default_value = "ws://localhost:1248")]
#[arg(
short,
long,
value_name = "ADDR",
default_value = "ws://localhost:1248"
)]
pub listen_addr: String,

/// Node JSON-RPC URL capable of supporting WebSockets
#[arg(short, long, value_name = "RPC_URL", default_value = "ws://localhost:8546")]
#[arg(
short,
long,
value_name = "RPC_URL",
default_value = "ws://localhost:8546"
)]
pub rpc_url: String,
}

Expand Down
8 changes: 8 additions & 0 deletions bin/rpc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mod cli;
mod config;
mod logging;
mod namespaces;
mod rpc;

pub use cli::Cli;
pub use rpc::run;
2 changes: 1 addition & 1 deletion bin/rpc/src/logging.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use tracing_error::ErrorLayer;
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
use anyhow::Result;

use crate::config;

Expand Down
2 changes: 1 addition & 1 deletion bin/rpc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use clap::Parser;
use cli::Cli;

mod cli;
mod logging;
mod config;
mod logging;
mod namespaces;
mod rpc;

Expand Down
2 changes: 1 addition & 1 deletion bin/rpc/src/namespaces.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod eth;
pub mod net;
pub mod wallet;
pub mod web3;
pub mod wallet;
16 changes: 9 additions & 7 deletions bin/rpc/src/namespaces/eth.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::sync::Arc;
use jsonrpsee::{core::RpcResult, ws_client::WsClient, RpcModule};
use std::sync::Arc;

use crate::rpc::upstream_request;

Expand Down Expand Up @@ -42,12 +42,14 @@ pub fn init(_: EthContext, client: Arc<WsClient>) -> RpcModule<EthContext> {
eth_methods.iter().for_each(|method| {
let _ = eth_module.register_async_method(method, upstream_request(method, client.clone()));
});

let _ = eth_module.register_method("eth_requestAccounts", |_, _, _| -> RpcResult<Vec<String>> {
let addresses: Vec<String> = vec!["0xE618050F1adb1F6bb7d03A3484346AC42F3E71EE".to_string()];
Ok(addresses)
});


let _ =
eth_module.register_method("eth_requestAccounts", |_, _, _| -> RpcResult<Vec<String>> {
let addresses: Vec<String> =
vec!["0xE618050F1adb1F6bb7d03A3484346AC42F3E71EE".to_string()];
Ok(addresses)
});

let _ = eth_module.register_method("eth_accounts", |_, _, _| -> RpcResult<Vec<String>> {
let addresses: Vec<String> = vec!["0xE618050F1adb1F6bb7d03A3484346AC42F3E71EE".to_string()];
Ok(addresses)
Expand Down
8 changes: 3 additions & 5 deletions bin/rpc/src/namespaces/net.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
use std::sync::Arc;
use jsonrpsee::{ws_client::WsClient, RpcModule};
use std::sync::Arc;

use crate::rpc::upstream_request;

pub type NetContext = ();

pub fn init(_: NetContext, client: Arc<WsClient>) -> RpcModule<NetContext> {
let mut net_module = RpcModule::new(());
let net_methods = vec![
"net_version",
];
let net_methods = vec!["net_version"];
net_methods.iter().for_each(|method| {
let _ = net_module.register_async_method(method, upstream_request(method, client.clone()));
});

net_module
}
}
5 changes: 3 additions & 2 deletions bin/rpc/src/namespaces/wallet.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::sync::Arc;
use jsonrpsee::{ws_client::WsClient, RpcModule};
use std::sync::Arc;

use crate::rpc::upstream_request;

Expand All @@ -9,7 +9,8 @@ pub fn init(_: WalletContext, client: Arc<WsClient>) -> RpcModule<WalletContext>
let mut wallet_module = RpcModule::new(());
let wallet_methods: Vec<&str> = vec![];
wallet_methods.iter().for_each(|method| {
let _ = wallet_module.register_async_method(method, upstream_request(method, client.clone()));
let _ =
wallet_module.register_async_method(method, upstream_request(method, client.clone()));
});

wallet_module
Expand Down
6 changes: 2 additions & 4 deletions bin/rpc/src/namespaces/web3.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::sync::Arc;
use jsonrpsee::{ws_client::WsClient, RpcModule};
use std::sync::Arc;

use crate::rpc::upstream_request;

Expand All @@ -8,9 +8,7 @@ pub type Web3Context = ();
pub fn init(c: Web3Context, client: Arc<WsClient>) -> RpcModule<Web3Context> {
let mut web3_module = RpcModule::new(c);

let web3_methods = vec![
"web3_clientVersion",
];
let web3_methods = vec!["web3_clientVersion"];
web3_methods.iter().for_each(|method| {
let _ = web3_module.register_async_method(method, upstream_request(method, client.clone()));
});
Expand Down
Loading