Skip to content

Commit e016463

Browse files
storopoliZk2u
andauthored
feat: print strata explorer links if configured (#453) (#454)
* feat: print strata explorer links if configured * fix: don't rename the file name for bitcoin explorer Co-authored-by: Zk2u <[email protected]>
1 parent 435e3f8 commit e016463

File tree

8 files changed

+59
-28
lines changed

8 files changed

+59
-28
lines changed

bin/strata-cli/src/cmd/deposit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::{
2121
recovery::DescriptorRecovery,
2222
seed::Seed,
2323
settings::Settings,
24-
signet::{get_fee_rate, log_fee_rate, print_explorer_url, SignetWallet},
24+
signet::{get_fee_rate, log_fee_rate, print_bitcoin_explorer_url, SignetWallet},
2525
strata::StrataWallet,
2626
taproot::{ExtractP2trPubkey, NotTaprootAddress},
2727
};
@@ -148,7 +148,7 @@ pub async fn deposit(
148148
.expect("successful broadcast");
149149
let txid = tx.compute_txid();
150150
pb.finish_with_message(format!("Transaction {} broadcasted", txid));
151-
let _ = print_explorer_url(&txid, &term, &settings);
151+
let _ = print_bitcoin_explorer_url(&txid, &term, &settings);
152152
let _ = term.write_line(&format!(
153153
"Expect transaction confirmation in ~{:?}. Funds will take longer than this to be available on Strata.",
154154
SIGNET_BLOCK_TIME

bin/strata-cli/src/cmd/drain.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use crate::{
1212
constants::SATS_TO_WEI,
1313
seed::Seed,
1414
settings::Settings,
15-
signet::{get_fee_rate, log_fee_rate, print_explorer_url, SignetWallet},
16-
strata::StrataWallet,
15+
signet::{get_fee_rate, log_fee_rate, print_bitcoin_explorer_url, SignetWallet},
16+
strata::{print_strata_explorer_url, StrataWallet},
1717
};
1818

1919
/// Drains the internal wallet to the provided
@@ -83,7 +83,7 @@ pub async fn drain(
8383
l1w.sign(&mut psbt, Default::default()).unwrap();
8484
let tx = psbt.extract_tx().expect("fully signed tx");
8585
settings.signet_backend.broadcast_tx(&tx).await.unwrap();
86-
let _ = print_explorer_url(&tx.compute_txid(), &term, &settings);
86+
let _ = print_bitcoin_explorer_url(&tx.compute_txid(), &term, &settings);
8787
let _ = term.write_line(&format!("Drained signet wallet to {}", address,));
8888
}
8989

@@ -108,7 +108,9 @@ pub async fn drain(
108108

109109
let tx = l2w.transaction_request().to(address).value(max_send_amount);
110110

111-
let _ = l2w.send_transaction(tx).await.unwrap();
111+
let res = l2w.send_transaction(tx).await.unwrap();
112+
113+
let _ = print_strata_explorer_url(res.tx_hash(), &term, &settings);
112114

113115
let _ = term.write_line(&format!(
114116
"Drained {} from Strata wallet to {}",

bin/strata-cli/src/cmd/faucet.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::{
2323
use crate::{
2424
seed::Seed,
2525
settings::Settings,
26-
signet::{print_explorer_url, SignetWallet},
26+
signet::{print_bitcoin_explorer_url, SignetWallet},
2727
};
2828

2929
/// Request some bitcoin from the faucet
@@ -170,14 +170,14 @@ pub async fn faucet(args: FaucetArgs, seed: Seed, settings: Settings) {
170170
if status == StatusCode::OK {
171171
#[cfg(feature = "strata_faucet")]
172172
if network_type == NetworkType::Signet {
173-
let _ = print_explorer_url(
173+
let _ = print_bitcoin_explorer_url(
174174
&Txid::from_str(&body).expect("valid txid"),
175175
&term,
176176
&settings,
177177
);
178178
}
179179
#[cfg(not(feature = "strata_faucet"))]
180-
let _ = print_explorer_url(
180+
let _ = print_bitcoin_explorer_url(
181181
&Txid::from_str(&body).expect("valid txid"),
182182
&term,
183183
&settings,

bin/strata-cli/src/cmd/send.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use crate::{
1515
net_type::{net_type_or_exit, NetworkType},
1616
seed::Seed,
1717
settings::Settings,
18-
signet::{get_fee_rate, log_fee_rate, print_explorer_url, SignetWallet},
19-
strata::StrataWallet,
18+
signet::{get_fee_rate, log_fee_rate, print_bitcoin_explorer_url, SignetWallet},
19+
strata::{print_strata_explorer_url, StrataWallet},
2020
};
2121

2222
/// Send some bitcoin from the internal wallet.
@@ -72,7 +72,7 @@ pub async fn send(args: SendArgs, seed: Seed, settings: Settings) {
7272
.broadcast_tx(&tx)
7373
.await
7474
.expect("successful broadcast");
75-
let _ = print_explorer_url(&tx.compute_txid(), &term, &settings);
75+
let _ = print_bitcoin_explorer_url(&tx.compute_txid(), &term, &settings);
7676
}
7777
NetworkType::Strata => {
7878
let l2w = StrataWallet::new(&seed, &settings.strata_endpoint).expect("valid wallet");
@@ -84,7 +84,7 @@ pub async fn send(args: SendArgs, seed: Seed, settings: Settings) {
8484
.send_transaction(tx)
8585
.await
8686
.expect("successful broadcast");
87-
let _ = term.write_line(&format!("Transaction {} sent", res.tx_hash()));
87+
let _ = print_strata_explorer_url(res.tx_hash(), &term, &settings);
8888
}
8989
};
9090

bin/strata-cli/src/cmd/withdraw.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
seed::Seed,
1515
settings::Settings,
1616
signet::SignetWallet,
17-
strata::StrataWallet,
17+
strata::{print_strata_explorer_url, StrataWallet},
1818
taproot::ExtractP2trPubkey,
1919
};
2020

@@ -69,6 +69,6 @@ pub async fn withdraw(args: WithdrawArgs, seed: Seed, settings: Settings) {
6969
let pb = ProgressBar::new_spinner().with_message("Broadcasting transaction");
7070
pb.enable_steady_tick(Duration::from_millis(100));
7171
let res = l2w.send_transaction(tx).await.unwrap();
72-
let txid = res.tx_hash();
73-
pb.finish_with_message(format!("Broadcast successful. Txid: {}", txid));
72+
pb.finish_with_message("Broadcast successful");
73+
let _ = print_strata_explorer_url(res.tx_hash(), &term, &settings);
7474
}

bin/strata-cli/src/settings.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ pub struct SettingsFromFile {
2929
pub bitcoind_rpc_endpoint: Option<String>,
3030
pub strata_endpoint: String,
3131
pub faucet_endpoint: String,
32-
pub mempool_endpoint: String,
32+
pub mempool_endpoint: Option<String>,
33+
pub blockscout_endpoint: Option<String>,
3334
pub bridge_pubkey: Option<Hex<[u8; 32]>>,
3435
pub network: Option<Network>,
3536
}
@@ -44,7 +45,8 @@ pub struct Settings {
4445
pub faucet_endpoint: String,
4546
pub bridge_musig2_pubkey: XOnlyPublicKey,
4647
pub descriptor_db: PathBuf,
47-
pub mempool_endpoint: String,
48+
pub mempool_space_endpoint: Option<String>,
49+
pub blockscout_endpoint: Option<String>,
4850
pub bridge_strata_address: StrataAddress,
4951
pub linux_seed_file: PathBuf,
5052
pub network: Network,
@@ -106,7 +108,6 @@ impl Settings {
106108
strata_endpoint: from_file.strata_endpoint,
107109
data_dir: proj_dirs.data_dir().to_owned(),
108110
faucet_endpoint: from_file.faucet_endpoint,
109-
mempool_endpoint: from_file.mempool_endpoint,
110111
bridge_musig2_pubkey: XOnlyPublicKey::from_slice(&match from_file.bridge_pubkey {
111112
Some(key) => key.0,
112113
None => {
@@ -116,12 +117,14 @@ impl Settings {
116117
}
117118
})
118119
.expect("valid length"),
119-
config_file: CONFIG_FILE.clone(),
120-
network: from_file.network.unwrap_or(DEFAULT_NETWORK),
121120
descriptor_db: descriptor_file,
121+
mempool_space_endpoint: from_file.mempool_endpoint,
122+
blockscout_endpoint: from_file.blockscout_endpoint,
122123
bridge_strata_address: StrataAddress::from_str(BRIDGE_STRATA_ADDRESS)
123124
.expect("valid strata address"),
124125
linux_seed_file,
126+
network: from_file.network.unwrap_or(DEFAULT_NETWORK),
127+
config_file: CONFIG_FILE.clone(),
125128
signet_backend: sync_backend,
126129
})
127130
}

bin/strata-cli/src/signet.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,18 @@ pub async fn get_fee_rate(
4444
}
4545
}
4646

47-
pub fn print_explorer_url(txid: &Txid, term: &Term, settings: &Settings) -> Result<(), io::Error> {
48-
term.write_line(&format!(
49-
"View transaction at {}",
50-
style(format!("{}/tx/{txid}", settings.mempool_endpoint)).blue()
51-
))
47+
pub fn print_bitcoin_explorer_url(
48+
txid: &Txid,
49+
term: &Term,
50+
settings: &Settings,
51+
) -> Result<(), io::Error> {
52+
term.write_line(&match settings.mempool_space_endpoint {
53+
Some(ref url) => format!(
54+
"View transaction at {}",
55+
style(format!("{url}/tx/{txid}")).blue()
56+
),
57+
None => format!("Transaction ID: {txid}"),
58+
})
5259
}
5360

5461
#[derive(Clone, Debug)]

bin/strata-cli/src/strata.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
use std::ops::{Deref, DerefMut};
1+
use std::{
2+
io,
3+
ops::{Deref, DerefMut},
4+
};
25

36
use alloy::{
47
network::{Ethereum, EthereumWallet},
8+
primitives::TxHash,
59
providers::{
610
fillers::{
711
BlobGasFiller, ChainIdFiller, FillProvider, GasFiller, JoinFill, NonceFiller,
@@ -11,8 +15,23 @@ use alloy::{
1115
},
1216
transports::http::{Client, Http},
1317
};
18+
use console::{style, Term};
19+
20+
use crate::{seed::Seed, settings::Settings};
1421

15-
use crate::seed::Seed;
22+
pub fn print_strata_explorer_url(
23+
txid: &TxHash,
24+
term: &Term,
25+
settings: &Settings,
26+
) -> Result<(), io::Error> {
27+
term.write_line(&match settings.blockscout_endpoint {
28+
Some(ref url) => format!(
29+
"View transaction at {}",
30+
style(format!("{url}/tx/{txid}")).blue()
31+
),
32+
None => format!("Transaction ID: {txid}"),
33+
})
34+
}
1635

1736
// alloy moment 💀
1837
type Provider = FillProvider<

0 commit comments

Comments
 (0)