Skip to content

Commit d9817e0

Browse files
authored
Merge pull request #4 from LayerTwo-Labs/2025-02-13-backport-thunder-0.11.3
Backport Thunder 0.11.3
2 parents 8527704 + 04f9519 commit d9817e0

13 files changed

+97
-70
lines changed

Cargo.lock

+7-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+8-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ members = [
88
"rpc-api",
99
]
1010

11+
[workspace.package]
12+
authors = [ "Ash Manning <ash@layertwolabs.com>" ]
13+
edition = "2021"
14+
license-file = "LICENSE.txt"
15+
publish = false
16+
version = "0.11.3"
17+
1118
[workspace.dependencies]
1219
anyhow = "1.0.72"
1320
bincode = "1.3.3"
@@ -33,6 +40,7 @@ tokio-util = "0.7.10"
3340
tonic = "0.12.3"
3441
tracing = "0.1.40"
3542
tracing-subscriber = "0.3.18"
43+
url = "2.5.4"
3644
utoipa = { version = "5.2.0", default-features = false }
3745

3846
[workspace.dependencies.bip300301_enforcer_lib]
@@ -61,13 +69,6 @@ wildcard_imports = "deny"
6169
[workspace.lints.rust]
6270
let_underscore_drop = "deny"
6371

64-
[workspace.package]
65-
authors = [ "Ash Manning <ash@layertwolabs.com>" ]
66-
edition = "2021"
67-
license-file = "LICENSE.txt"
68-
publish = false
69-
version = "0.11.2"
70-
7172
# temp-dir does not leak correctly after clone
7273
# https://gitlab.com/leonhard-llc/ops/-/issues/17
7374
[patch.crates-io.temp-dir]

app/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ tonic-health = "0.12.3"
4040
tracing = { workspace = true }
4141
tracing-appender = "0.2.3"
4242
tracing-subscriber = { workspace = true, features = ["env-filter", "json"] }
43+
url = { workspace = true }
4344
utoipa = { workspace = true }
4445

4546
[dependencies.libes]

app/app.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ pub enum Error {
4242
#[error(transparent)]
4343
Other(#[from] anyhow::Error),
4444
#[error(
45-
"Unable to verify existence of CUSF mainchain service(s) at {address}"
45+
"Unable to verify existence of CUSF mainchain service(s) at {url}"
4646
)]
4747
VerifyMainchainServices {
48-
address: std::net::SocketAddr,
48+
url: url::Url,
4949
source: tonic::Status,
5050
},
5151
#[error("wallet error")]
@@ -217,18 +217,21 @@ impl App {
217217
let mnemonic = std::fs::read_to_string(seed_phrase_path)?;
218218
let () = wallet.set_seed_from_mnemonic(mnemonic.as_str())?;
219219
}
220-
tracing::info!("Connecting to mainchain at {}", config.main_addr);
220+
tracing::info!(
221+
url = %config.mainchain_grpc_url,
222+
"Connecting to mainchain"
223+
);
221224
let rt_guard = runtime.enter();
222225
let transport = tonic::transport::channel::Channel::from_shared(
223-
format!("https://{}", config.main_addr),
226+
config.mainchain_grpc_url.to_string(),
224227
)
225228
.unwrap()
226229
.concurrency_limit(256)
227230
.connect_lazy();
228231
let (cusf_mainchain, cusf_mainchain_wallet) = if runtime
229232
.block_on(Self::check_proto_support(transport.clone()))
230233
.map_err(|err| Error::VerifyMainchainServices {
231-
address: config.main_addr,
234+
url: config.mainchain_grpc_url.clone(),
232235
source: err,
233236
})? {
234237
(

app/cli.rs

+37-22
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::{
77

88
use clap::{Arg, Parser};
99
use plain_bitassets::types::{Network, THIS_SIDECHAIN};
10+
use url::{Host, Url};
1011

1112
const fn ipv4_socket_addr(ipv4_octets: [u8; 4], port: u16) -> SocketAddr {
1213
let [a, b, c, d] = ipv4_octets;
@@ -23,7 +24,9 @@ static DEFAULT_DATA_DIR: LazyLock<Option<PathBuf>> =
2324
Some(data_dir) => Some(data_dir.join("plain_bitassets")),
2425
});
2526

26-
const DEFAULT_MAIN_ADDR: SocketAddr = ipv4_socket_addr([127, 0, 0, 1], 50051);
27+
const DEFAULT_MAIN_HOST: Host = Host::Ipv4(Ipv4Addr::LOCALHOST);
28+
29+
const DEFAULT_MAIN_PORT: u16 = 50051;
2730

2831
const DEFAULT_NET_ADDR: SocketAddr =
2932
ipv4_socket_addr([0, 0, 0, 0], 4000 + THIS_SIDECHAIN as u16);
@@ -121,9 +124,12 @@ pub(super) struct Cli {
121124
/// Log level
122125
#[arg(default_value_t = tracing::Level::DEBUG, long)]
123126
log_level: tracing::Level,
124-
/// Socket address to connect to mainchain node gRPC server
125-
#[arg(default_value_t = DEFAULT_MAIN_ADDR, long, short)]
126-
main_addr: SocketAddr,
127+
/// Connect to mainchain node gRPC server running on this host/port
128+
#[arg(default_value_t = DEFAULT_MAIN_HOST, long, value_parser = Host::parse)]
129+
mainchain_grpc_host: Host,
130+
/// Connect to mainchain node gRPC server running on this host/port
131+
#[arg(default_value_t = DEFAULT_MAIN_PORT, long)]
132+
mainchain_grpc_port: u16,
127133
/// Path to a mnemonic seed phrase
128134
#[arg(long)]
129135
mnemonic_seed_phrase_path: Option<PathBuf>,
@@ -142,25 +148,17 @@ pub(super) struct Cli {
142148
pub zmq_addr: SocketAddr,
143149
}
144150

145-
#[derive(Clone, Debug)]
146-
pub struct Config {
147-
pub datadir: PathBuf,
148-
pub file_log_level: tracing::Level,
149-
pub headless: bool,
150-
/// If None, logging to file should be disabled.
151-
pub log_dir: Option<PathBuf>,
152-
pub log_level: tracing::Level,
153-
pub main_addr: SocketAddr,
154-
pub mnemonic_seed_phrase_path: Option<PathBuf>,
155-
pub net_addr: SocketAddr,
156-
pub network: Network,
157-
pub rpc_addr: SocketAddr,
158-
#[cfg(feature = "zmq")]
159-
pub zmq_addr: SocketAddr,
160-
}
161-
162151
impl Cli {
152+
pub fn mainchain_grpc_url(&self) -> Url {
153+
Url::parse(&format!(
154+
"http://{}:{}",
155+
self.mainchain_grpc_host, self.mainchain_grpc_port
156+
))
157+
.unwrap()
158+
}
159+
163160
pub fn get_config(self) -> anyhow::Result<Config> {
161+
let mainchain_grpc_url = self.mainchain_grpc_url();
164162
let log_dir = match self.log_dir {
165163
None => {
166164
let version_dir_name =
@@ -183,7 +181,7 @@ impl Cli {
183181
headless: self.headless,
184182
log_dir,
185183
log_level: self.log_level,
186-
main_addr: self.main_addr,
184+
mainchain_grpc_url,
187185
mnemonic_seed_phrase_path: self.mnemonic_seed_phrase_path,
188186
net_addr: self.net_addr,
189187
network: self.network,
@@ -193,3 +191,20 @@ impl Cli {
193191
})
194192
}
195193
}
194+
195+
#[derive(Clone, Debug)]
196+
pub struct Config {
197+
pub datadir: PathBuf,
198+
pub file_log_level: tracing::Level,
199+
pub headless: bool,
200+
/// If None, logging to file should be disabled.
201+
pub log_dir: Option<PathBuf>,
202+
pub log_level: tracing::Level,
203+
pub mainchain_grpc_url: url::Url,
204+
pub mnemonic_seed_phrase_path: Option<PathBuf>,
205+
pub net_addr: SocketAddr,
206+
pub network: Network,
207+
pub rpc_addr: SocketAddr,
208+
#[cfg(feature = "zmq")]
209+
pub zmq_addr: SocketAddr,
210+
}

app/gui/console_logs.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
use std::{
2-
net::SocketAddr,
3-
sync::{
4-
atomic::{self, AtomicBool},
5-
Arc,
6-
},
1+
use std::sync::{
2+
atomic::{self, AtomicBool},
3+
Arc,
74
};
85

96
use clap::Parser;
@@ -32,16 +29,16 @@ pub struct ConsoleCommand {
3229
pub struct ConsoleLogs {
3330
line_buffer: LineBuffer,
3431
command_input: String,
35-
rpc_addr: SocketAddr,
32+
rpc_url: url::Url,
3633
running_command: Arc<AtomicBool>,
3734
}
3835

3936
impl ConsoleLogs {
40-
pub fn new(line_buffer: LineBuffer, rpc_addr: SocketAddr) -> Self {
37+
pub fn new(line_buffer: LineBuffer, rpc_url: url::Url) -> Self {
4138
Self {
4239
line_buffer,
4340
command_input: String::new(),
44-
rpc_addr,
41+
rpc_url,
4542
running_command: Arc::new(AtomicBool::new(false)),
4643
}
4744
}
@@ -70,8 +67,11 @@ impl ConsoleLogs {
7067
return;
7168
}
7269
};
73-
let cli =
74-
plain_bitassets_app_cli_lib::Cli::new(command, self.rpc_addr, None);
70+
let cli = plain_bitassets_app_cli_lib::Cli::new(
71+
command,
72+
self.rpc_url.clone(),
73+
None,
74+
);
7575
app.runtime.spawn({
7676
let running_command = self.running_command.clone();
7777
running_command.store(true, atomic::Ordering::SeqCst);

app/gui/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{net::SocketAddr, task::Poll};
1+
use std::task::Poll;
22

33
use eframe::egui::{self, Color32, RichText};
44
use plain_bitassets::{util::Watchable, wallet::Wallet};
@@ -190,7 +190,7 @@ impl EguiApp {
190190
app: Option<App>,
191191
cc: &eframe::CreationContext<'_>,
192192
logs_capture: LineBuffer,
193-
rpc_addr: SocketAddr,
193+
rpc_addr: url::Url,
194194
) -> Self {
195195
// Customize egui here with cc.egui_ctx.set_fonts and cc.egui_ctx.set_visuals.
196196
// Restore app state using cc.storage (requires the "persistence" feature).

app/main.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,13 @@ fn run_egui_app(
144144
app: Option<crate::app::App>,
145145
) -> Result<(), eframe::Error> {
146146
let native_options = eframe::NativeOptions::default();
147+
let rpc_addr = url::Url::parse(&format!("http://{}", config.rpc_addr))
148+
.expect("failed to parse rpc addr");
147149
eframe::run_native(
148150
"Plain Bitassets",
149151
native_options,
150152
Box::new(move |cc| {
151-
Ok(Box::new(gui::EguiApp::new(
152-
app,
153-
cc,
154-
line_buffer,
155-
config.rpc_addr,
156-
)))
153+
Ok(Box::new(gui::EguiApp::new(app, cc, line_buffer, rpc_addr)))
157154
}),
158155
)
159156
}

cli/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ plain_bitassets = { path = "../lib", features = ["clap"] }
1515
plain_bitassets_app_rpc_api = { path = "../rpc-api" }
1616
serde_json = { workspace = true }
1717
tokio = { workspace = true }
18+
url = { workspace = true }
1819
utoipa = { workspace = true }
1920

2021
[lib]
@@ -23,4 +24,4 @@ path = "lib.rs"
2324

2425
[[bin]]
2526
name = "plain_bitassets_app_cli"
26-
path = "main.rs"
27+
path = "main.rs"

cli/lib.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::{
22
net::{IpAddr, Ipv4Addr, SocketAddr},
3+
sync::LazyLock,
34
time::Duration,
45
};
56

@@ -10,6 +11,7 @@ use plain_bitassets::types::{
1011
DutchAuctionParams, THIS_SIDECHAIN,
1112
};
1213
use plain_bitassets_app_rpc_api::RpcClient;
14+
use url::Url;
1315

1416
#[derive(Clone, Debug, Subcommand)]
1517
#[command(arg_required_else_help(true))]
@@ -152,16 +154,20 @@ const DEFAULT_RPC_ADDR: SocketAddr = SocketAddr::new(
152154
6000 + THIS_SIDECHAIN as u16,
153155
);
154156

157+
static DEFAULT_RPC_URL: LazyLock<Url> = LazyLock::new(|| {
158+
Url::parse(&format!("http://{DEFAULT_RPC_ADDR}")).unwrap()
159+
});
160+
155161
const DEFAULT_TIMEOUT_SECS: u64 = 60;
156162

157163
#[derive(Clone, Debug, Parser)]
158164
#[command(author, version, about, long_about = None)]
159165
pub struct Cli {
160166
#[command(subcommand)]
161167
pub command: Command,
162-
/// address for use by the RPC server
163-
#[arg(default_value_t = DEFAULT_RPC_ADDR, long)]
164-
pub rpc_addr: SocketAddr,
168+
/// Base URL used for requests to the RPC server.
169+
#[arg(default_value_t = DEFAULT_RPC_URL.clone(), long)]
170+
pub rpc_url: Url,
165171
/// Timeout for RPC requests in seconds.
166172
#[arg(default_value_t = DEFAULT_TIMEOUT_SECS, long = "timeout")]
167173
timeout_secs: u64,
@@ -170,12 +176,12 @@ pub struct Cli {
170176
impl Cli {
171177
pub fn new(
172178
command: Command,
173-
rpc_addr: SocketAddr,
179+
rpc_url: Url,
174180
timeout_secs: Option<u64>,
175181
) -> Self {
176182
Self {
177183
command,
178-
rpc_addr,
184+
rpc_url,
179185
timeout_secs: timeout_secs.unwrap_or(DEFAULT_TIMEOUT_SECS),
180186
}
181187
}
@@ -185,7 +191,7 @@ impl Cli {
185191
pub async fn run(self) -> anyhow::Result<String> {
186192
let rpc_client: HttpClient = HttpClientBuilder::default()
187193
.request_timeout(Duration::from_secs(self.timeout_secs))
188-
.build(format!("http://{}", self.rpc_addr))?;
194+
.build(self.rpc_url)?;
189195
let res = match self.command {
190196
Command::AmmBurn {
191197
asset0,

0 commit comments

Comments
 (0)