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

backport: print strata explorer links if configured (#453) #454

Merged
merged 1 commit into from
Nov 6, 2024
Merged
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
4 changes: 2 additions & 2 deletions bin/strata-cli/src/cmd/deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
recovery::DescriptorRecovery,
seed::Seed,
settings::Settings,
signet::{get_fee_rate, log_fee_rate, print_explorer_url, SignetWallet},
signet::{get_fee_rate, log_fee_rate, print_bitcoin_explorer_url, SignetWallet},
strata::StrataWallet,
taproot::{ExtractP2trPubkey, NotTaprootAddress},
};
Expand Down Expand Up @@ -148,7 +148,7 @@
.expect("successful broadcast");
let txid = tx.compute_txid();
pb.finish_with_message(format!("Transaction {} broadcasted", txid));
let _ = print_explorer_url(&txid, &term, &settings);
let _ = print_bitcoin_explorer_url(&txid, &term, &settings);

Check warning on line 151 in bin/strata-cli/src/cmd/deposit.rs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L151 was not covered by tests
let _ = term.write_line(&format!(
"Expect transaction confirmation in ~{:?}. Funds will take longer than this to be available on Strata.",
SIGNET_BLOCK_TIME
Expand Down
10 changes: 6 additions & 4 deletions bin/strata-cli/src/cmd/drain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
constants::SATS_TO_WEI,
seed::Seed,
settings::Settings,
signet::{get_fee_rate, log_fee_rate, print_explorer_url, SignetWallet},
strata::StrataWallet,
signet::{get_fee_rate, log_fee_rate, print_bitcoin_explorer_url, SignetWallet},
strata::{print_strata_explorer_url, StrataWallet},
};

/// Drains the internal wallet to the provided
Expand Down Expand Up @@ -83,7 +83,7 @@
l1w.sign(&mut psbt, Default::default()).unwrap();
let tx = psbt.extract_tx().expect("fully signed tx");
settings.signet_backend.broadcast_tx(&tx).await.unwrap();
let _ = print_explorer_url(&tx.compute_txid(), &term, &settings);
let _ = print_bitcoin_explorer_url(&tx.compute_txid(), &term, &settings);

Check warning on line 86 in bin/strata-cli/src/cmd/drain.rs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L86 was not covered by tests
let _ = term.write_line(&format!("Drained signet wallet to {}", address,));
}

Expand All @@ -108,7 +108,9 @@

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

let _ = l2w.send_transaction(tx).await.unwrap();
let res = l2w.send_transaction(tx).await.unwrap();

let _ = print_strata_explorer_url(res.tx_hash(), &term, &settings);

Check warning on line 113 in bin/strata-cli/src/cmd/drain.rs

View check run for this annotation

Codecov / codecov/patch

bin/strata-cli/src/cmd/drain.rs#L111-L113

Added lines #L111 - L113 were not covered by tests

let _ = term.write_line(&format!(
"Drained {} from Strata wallet to {}",
Expand Down
6 changes: 3 additions & 3 deletions bin/strata-cli/src/cmd/faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use crate::{
seed::Seed,
settings::Settings,
signet::{print_explorer_url, SignetWallet},
signet::{print_bitcoin_explorer_url, SignetWallet},
};

/// Request some bitcoin from the faucet
Expand Down Expand Up @@ -170,14 +170,14 @@
if status == StatusCode::OK {
#[cfg(feature = "strata_faucet")]
if network_type == NetworkType::Signet {
let _ = print_explorer_url(
let _ = print_bitcoin_explorer_url(

Check warning on line 173 in bin/strata-cli/src/cmd/faucet.rs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L173 was not covered by tests
&Txid::from_str(&body).expect("valid txid"),
&term,
&settings,
);
}
#[cfg(not(feature = "strata_faucet"))]
let _ = print_explorer_url(
let _ = print_bitcoin_explorer_url(

Check warning on line 180 in bin/strata-cli/src/cmd/faucet.rs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L180 was not covered by tests
&Txid::from_str(&body).expect("valid txid"),
&term,
&settings,
Expand Down
8 changes: 4 additions & 4 deletions bin/strata-cli/src/cmd/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
net_type::{net_type_or_exit, NetworkType},
seed::Seed,
settings::Settings,
signet::{get_fee_rate, log_fee_rate, print_explorer_url, SignetWallet},
strata::StrataWallet,
signet::{get_fee_rate, log_fee_rate, print_bitcoin_explorer_url, SignetWallet},
strata::{print_strata_explorer_url, StrataWallet},
};

/// Send some bitcoin from the internal wallet.
Expand Down Expand Up @@ -72,7 +72,7 @@
.broadcast_tx(&tx)
.await
.expect("successful broadcast");
let _ = print_explorer_url(&tx.compute_txid(), &term, &settings);
let _ = print_bitcoin_explorer_url(&tx.compute_txid(), &term, &settings);

Check warning on line 75 in bin/strata-cli/src/cmd/send.rs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L75 was not covered by tests
}
NetworkType::Strata => {
let l2w = StrataWallet::new(&seed, &settings.strata_endpoint).expect("valid wallet");
Expand All @@ -84,7 +84,7 @@
.send_transaction(tx)
.await
.expect("successful broadcast");
let _ = term.write_line(&format!("Transaction {} sent", res.tx_hash()));
let _ = print_strata_explorer_url(res.tx_hash(), &term, &settings);

Check warning on line 87 in bin/strata-cli/src/cmd/send.rs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L87 was not covered by tests
}
};

Expand Down
6 changes: 3 additions & 3 deletions bin/strata-cli/src/cmd/withdraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
seed::Seed,
settings::Settings,
signet::SignetWallet,
strata::StrataWallet,
strata::{print_strata_explorer_url, StrataWallet},
taproot::ExtractP2trPubkey,
};

Expand Down Expand Up @@ -69,6 +69,6 @@
let pb = ProgressBar::new_spinner().with_message("Broadcasting transaction");
pb.enable_steady_tick(Duration::from_millis(100));
let res = l2w.send_transaction(tx).await.unwrap();
let txid = res.tx_hash();
pb.finish_with_message(format!("Broadcast successful. Txid: {}", txid));
pb.finish_with_message("Broadcast successful");
let _ = print_strata_explorer_url(res.tx_hash(), &term, &settings);

Check warning on line 73 in bin/strata-cli/src/cmd/withdraw.rs

View check run for this annotation

Codecov / codecov/patch

bin/strata-cli/src/cmd/withdraw.rs#L72-L73

Added lines #L72 - L73 were not covered by tests
}
13 changes: 8 additions & 5 deletions bin/strata-cli/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
pub bitcoind_rpc_endpoint: Option<String>,
pub strata_endpoint: String,
pub faucet_endpoint: String,
pub mempool_endpoint: String,
pub mempool_endpoint: Option<String>,
pub blockscout_endpoint: Option<String>,
pub bridge_pubkey: Option<Hex<[u8; 32]>>,
pub network: Option<Network>,
}
Expand All @@ -44,7 +45,8 @@
pub faucet_endpoint: String,
pub bridge_musig2_pubkey: XOnlyPublicKey,
pub descriptor_db: PathBuf,
pub mempool_endpoint: String,
pub mempool_space_endpoint: Option<String>,
pub blockscout_endpoint: Option<String>,
pub bridge_strata_address: StrataAddress,
pub linux_seed_file: PathBuf,
pub network: Network,
Expand Down Expand Up @@ -106,7 +108,6 @@
strata_endpoint: from_file.strata_endpoint,
data_dir: proj_dirs.data_dir().to_owned(),
faucet_endpoint: from_file.faucet_endpoint,
mempool_endpoint: from_file.mempool_endpoint,
bridge_musig2_pubkey: XOnlyPublicKey::from_slice(&match from_file.bridge_pubkey {
Some(key) => key.0,
None => {
Expand All @@ -116,12 +117,14 @@
}
})
.expect("valid length"),
config_file: CONFIG_FILE.clone(),
network: from_file.network.unwrap_or(DEFAULT_NETWORK),
descriptor_db: descriptor_file,
mempool_space_endpoint: from_file.mempool_endpoint,
blockscout_endpoint: from_file.blockscout_endpoint,

Check warning on line 122 in bin/strata-cli/src/settings.rs

View check run for this annotation

Codecov / codecov/patch

bin/strata-cli/src/settings.rs#L121-L122

Added lines #L121 - L122 were not covered by tests
bridge_strata_address: StrataAddress::from_str(BRIDGE_STRATA_ADDRESS)
.expect("valid strata address"),
linux_seed_file,
network: from_file.network.unwrap_or(DEFAULT_NETWORK),
config_file: CONFIG_FILE.clone(),

Check warning on line 127 in bin/strata-cli/src/settings.rs

View check run for this annotation

Codecov / codecov/patch

bin/strata-cli/src/settings.rs#L126-L127

Added lines #L126 - L127 were not covered by tests
signet_backend: sync_backend,
})
}
Expand Down
17 changes: 12 additions & 5 deletions bin/strata-cli/src/signet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,18 @@
}
}

pub fn print_explorer_url(txid: &Txid, term: &Term, settings: &Settings) -> Result<(), io::Error> {
term.write_line(&format!(
"View transaction at {}",
style(format!("{}/tx/{txid}", settings.mempool_endpoint)).blue()
))
pub fn print_bitcoin_explorer_url(
txid: &Txid,
term: &Term,
settings: &Settings,
) -> Result<(), io::Error> {
term.write_line(&match settings.mempool_space_endpoint {
Some(ref url) => format!(
"View transaction at {}",
style(format!("{url}/tx/{txid}")).blue()
),
None => format!("Transaction ID: {txid}"),

Check warning on line 57 in bin/strata-cli/src/signet.rs

View check run for this annotation

Codecov / codecov/patch

bin/strata-cli/src/signet.rs#L47-L57

Added lines #L47 - L57 were not covered by tests
})
}

#[derive(Clone, Debug)]
Expand Down
23 changes: 21 additions & 2 deletions bin/strata-cli/src/strata.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use std::ops::{Deref, DerefMut};
use std::{
io,
ops::{Deref, DerefMut},
};

use alloy::{
network::{Ethereum, EthereumWallet},
primitives::TxHash,
providers::{
fillers::{
BlobGasFiller, ChainIdFiller, FillProvider, GasFiller, JoinFill, NonceFiller,
Expand All @@ -11,8 +15,23 @@
},
transports::http::{Client, Http},
};
use console::{style, Term};

use crate::{seed::Seed, settings::Settings};

use crate::seed::Seed;
pub fn print_strata_explorer_url(
txid: &TxHash,
term: &Term,
settings: &Settings,
) -> Result<(), io::Error> {
term.write_line(&match settings.blockscout_endpoint {
Some(ref url) => format!(
"View transaction at {}",
style(format!("{url}/tx/{txid}")).blue()
),
None => format!("Transaction ID: {txid}"),

Check warning on line 32 in bin/strata-cli/src/strata.rs

View check run for this annotation

Codecov / codecov/patch

bin/strata-cli/src/strata.rs#L22-L32

Added lines #L22 - L32 were not covered by tests
})
}

Check warning on line 34 in bin/strata-cli/src/strata.rs

View check run for this annotation

Codecov / codecov/patch

bin/strata-cli/src/strata.rs#L34

Added line #L34 was not covered by tests

// alloy moment 💀
type Provider = FillProvider<
Expand Down
Loading