Skip to content

Commit 595466a

Browse files
authored
Merge pull request #437 from alpenlabs/cli-updates
backport: CLI updates
2 parents afaf6b0 + 1fb1e1c commit 595466a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1467
-494
lines changed

.github/workflows/functional.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ on:
88

99
env:
1010
CARGO_TERM_COLOR: always
11-
1211
jobs:
1312
lint:
1413
name: Lint test files
@@ -55,11 +54,11 @@ jobs:
5554

5655
- name: Install bitcoind
5756
env:
58-
BITCOIND_VERSION: "27.0"
57+
BITCOIND_VERSION: "28.0"
5958
BITCOIND_ARCH: "x86_64-linux-gnu"
60-
SHASUM: "2a6974c5486f528793c79d42694b5987401e4a43c97f62b1383abf35bcee44a8"
59+
SHASUM: "7fe294b02b25b51acb8e8e0a0eb5af6bbafa7cd0c5b0e5fcbb61263104a82fbc"
6160
run: |
62-
wget -q "https://bitcoin.org/bin/bitcoin-core-${{ env.BITCOIND_VERSION }}/bitcoin-${{ env.BITCOIND_VERSION }}-${{ env.BITCOIND_ARCH }}.tar.gz"
61+
curl -fsSLO --proto "=https" --tlsv1.2 "https://bitcoincore.org/bin/bitcoin-core-${{ env.BITCOIND_VERSION }}/bitcoin-${{ env.BITCOIND_VERSION }}-${{ env.BITCOIND_ARCH }}.tar.gz"
6362
sha256sum -c <<< "$SHASUM bitcoin-${{ env.BITCOIND_VERSION }}-${{ env.BITCOIND_ARCH }}.tar.gz"
6463
tar xzf "bitcoin-${{ env.BITCOIND_VERSION }}-${{ env.BITCOIND_ARCH }}.tar.gz"
6564
sudo install -m 0755 -t /usr/local/bin bitcoin-${{ env.BITCOIND_VERSION }}/bin/*

Cargo.lock

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

Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,8 @@ argh = "0.1"
120120
async-trait = "0.1.80"
121121
base64 = "0.22.1"
122122
bincode = "1.3.3"
123-
bitcoin = { version = "=0.32.1", features = ["serde"] }
123+
bitcoin = { version = "=0.32.3", features = ["serde"] }
124124
bitcoind = { version = "0.36.0", features = ["26_0"] }
125-
bitcoind-json-rpc-types = "0.3.0"
126125
borsh = { version = "1.5.0", features = ["derive"] }
127126
bytes = "1.6.0"
128127
chrono = "0.4.38"

bin/strata-cli/Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ edition = "2021"
33
name = "strata-cli"
44
version = "0.1.0"
55

6+
[features]
7+
strata_faucet = []
8+
69
[[bin]]
710
name = "strata"
811
path = "src/main.rs"
@@ -20,6 +23,8 @@ alloy = { version = "0.3.5", features = [
2023
] }
2124
argh.workspace = true
2225
argon2 = "0.5.3"
26+
async-trait.workspace = true
27+
bdk_bitcoind_rpc = "0.16.0"
2328
bdk_esplora = { version = "0.19.0", features = [
2429
"async-https",
2530
"async-https-rustls",
@@ -42,6 +47,8 @@ sled = "0.34.7"
4247
strata-bridge-tx-builder.workspace = true
4348
terrors.workspace = true
4449
tokio.workspace = true
50+
zeroize = { version = "1.8.1", features = ["derive"] }
51+
zxcvbn = "3.1.0"
4552

4653
# sha2 fails to compile on windows with the "asm" feature
4754
[target.'cfg(not(target_os = "windows"))'.dependencies]

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

+14-9
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ use alloy::{
33
providers::{Provider, WalletProvider},
44
};
55
use argh::FromArgs;
6+
use bdk_wallet::bitcoin::Amount;
67
use console::Term;
78

89
use crate::{
9-
constants::NETWORK,
10+
constants::SATS_TO_WEI,
1011
net_type::{net_type_or_exit, NetworkType},
1112
seed::Seed,
1213
settings::Settings,
13-
signet::{EsploraClient, SignetWallet},
14+
signet::SignetWallet,
1415
strata::StrataWallet,
1516
};
1617

@@ -23,13 +24,14 @@ pub struct BalanceArgs {
2324
network_type: String,
2425
}
2526

26-
pub async fn balance(args: BalanceArgs, seed: Seed, settings: Settings, esplora: EsploraClient) {
27+
pub async fn balance(args: BalanceArgs, seed: Seed, settings: Settings) {
2728
let term = Term::stdout();
2829
let network_type = net_type_or_exit(&args.network_type, &term);
2930

3031
if let NetworkType::Signet = network_type {
31-
let mut l1w = SignetWallet::new(&seed, NETWORK).unwrap();
32-
l1w.sync(&esplora).await.unwrap();
32+
let mut l1w =
33+
SignetWallet::new(&seed, settings.network, settings.signet_backend.clone()).unwrap();
34+
l1w.sync().await.unwrap();
3335
let balance = l1w.balance();
3436
let _ = term.write_line(&format!("Total: {}", balance.total()));
3537
let _ = term.write_line(&format!(" Confirmed: {}", balance.confirmed));
@@ -42,11 +44,14 @@ pub async fn balance(args: BalanceArgs, seed: Seed, settings: Settings, esplora:
4244
}
4345

4446
if let NetworkType::Strata = network_type {
45-
let l2w = StrataWallet::new(&seed, &settings.l2_http_endpoint).unwrap();
47+
let l2w = StrataWallet::new(&seed, &settings.strata_endpoint).unwrap();
4648
let _ = term.write_line("Getting balance...");
4749
let balance = l2w.get_balance(l2w.default_signer_address()).await.unwrap();
48-
// 1 BTC = 1 ETH
49-
let balance_in_btc = balance / U256::from(10u64.pow(18));
50-
let _ = term.write_line(&format!("\nTotal: {} BTC", balance_in_btc));
50+
let balance = Amount::from_sat(
51+
(balance / U256::from(SATS_TO_WEI))
52+
.try_into()
53+
.expect("valid amount"),
54+
);
55+
let _ = term.write_line(&format!("\nTotal: {}", balance));
5156
}
5257
}

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use argh::FromArgs;
22
use console::Term;
3-
use rand::thread_rng;
3+
use rand::rngs::OsRng;
44

55
use crate::seed::{password::Password, EncryptedSeedPersister, Seed};
66

@@ -12,7 +12,11 @@ pub struct ChangePwdArgs {}
1212
pub async fn change_pwd(_args: ChangePwdArgs, seed: Seed, persister: impl EncryptedSeedPersister) {
1313
let term = Term::stdout();
1414
let mut new_pw = Password::read(true).unwrap();
15-
let encrypted_seed = seed.encrypt(&mut new_pw, &mut thread_rng()).unwrap();
15+
let password_validation: Result<(), String> = new_pw.validate();
16+
if let Err(feedback) = password_validation {
17+
let _ = term.write_line(&format!("Password is weak. {}", feedback));
18+
}
19+
let encrypted_seed = seed.encrypt(&mut new_pw, &mut OsRng).unwrap();
1620
persister.save(&encrypted_seed).unwrap();
1721
let _ = term.write_line("Password changed successfully");
1822
}

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

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use argh::FromArgs;
2+
3+
use crate::settings::CONFIG_FILE;
4+
5+
/// Prints the location of the CLI's TOML config file
6+
#[derive(FromArgs, PartialEq, Debug)]
7+
#[argh(subcommand, name = "config")]
8+
pub struct ConfigArgs {}
9+
10+
pub async fn config(_args: ConfigArgs) {
11+
println!("{}", CONFIG_FILE.to_string_lossy())
12+
}

0 commit comments

Comments
 (0)