Skip to content

Commit eeb3b98

Browse files
committed
Merge branch 'master' into feat/add-completions-cmd
2 parents e173b47 + 46e1ab7 commit eeb3b98

File tree

8 files changed

+243
-212
lines changed

8 files changed

+243
-212
lines changed

.github/workflows/audit.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ jobs:
1313
security_audit:
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: actions/checkout@v4
16+
- uses: actions/checkout@v6
1717
- uses: actions-rust-lang/audit@v1
1818
with:
1919
token: ${{ secrets.GITHUB_TOKEN }}
20+
tool-version: 0.22.1

.github/workflows/cont_integration.yml

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ on: [push, pull_request]
22

33
name: CI
44

5+
permissions:
6+
contents: read
7+
env:
8+
CARGO_TERM_COLOR: always
59
jobs:
610

711
build-test:
@@ -17,30 +21,41 @@ jobs:
1721
- --all-features
1822
steps:
1923
- name: Checkout
20-
uses: actions/checkout@v4
21-
- name: Generate cache key
22-
run: echo "${{ matrix.rust }} ${{ matrix.features }}" | tee .cache_key
23-
- name: Cache
24-
uses: actions/cache@v4
25-
with:
26-
path: |
27-
~/.cargo/registry
28-
~/.cargo/git
29-
target
30-
key: ${{ runner.os }}-cargo-${{ hashFiles('.cache_key') }}-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }}
24+
uses: actions/checkout@v6
3125
- name: Setup Rust Toolchain
32-
uses: actions-rs/toolchain@v1
26+
uses: actions-rust-lang/setup-rust-toolchain@v1
3327
with:
3428
toolchain: ${{ matrix.rust }}
3529
profile: minimal
3630
override: true
3731
components: rustfmt, clippy
32+
cache: true
3833
- name: Build
3934
run: cargo build ${{ matrix.features }}
40-
- name: Clippy
41-
run: cargo clippy -- -D warnings
4235
- name: Test
4336
run: cargo test ${{ matrix.features }}
37+
clippy:
38+
name: Clippy (${{ matrix.features }})
39+
runs-on: ubuntu-latest
40+
strategy:
41+
matrix:
42+
features:
43+
- --no-default-features
44+
- --all-features
45+
steps:
46+
- name: Checkout
47+
uses: actions/checkout@v6
48+
49+
- name: Install Rust toolchain
50+
uses: actions-rust-lang/setup-rust-toolchain@v1
51+
with:
52+
toolchain: stable
53+
profile: minimal
54+
override: true
55+
components: clippy
56+
cache: true
57+
- name: Run Clippy
58+
run: cargo clippy ${{ matrix.features }} --all-targets -- -D warnings
4459

4560
# TODO: fix or remove this
4661
# wasm-build:
@@ -82,13 +97,14 @@ jobs:
8297
runs-on: ubuntu-latest
8398
steps:
8499
- name: Checkout
85-
uses: actions/checkout@v4
100+
uses: actions/checkout@v6
86101
- name: Setup Rust Toolchain
87-
uses: actions-rs/toolchain@v1
102+
uses: actions-rust-lang/setup-rust-toolchain@v1
88103
with:
89104
toolchain: stable
90105
profile: minimal
91106
override: true
92107
components: rustfmt, clippy
108+
cache: true
93109
- name: Check fmt
94110
run: cargo fmt --all -- --check

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Justfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ build: fmt
2525
test:
2626
cargo test --all-features --tests
2727

28+
# checks before pushing
29+
pre-push:
30+
cargo test --features default
31+
cargo test --no-default-features
32+
cargo test --all-features
33+
cargo clippy --no-default-features --all-targets -- -D warnings
34+
cargo clippy --all-features --all-targets -- -D warnings
35+
cargo fmt --all -- --check
36+
2837
# clean the project target directory
2938
clean:
3039
cargo clean

src/error.rs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ pub enum BDKCliError {
5959

6060
#[cfg(feature = "sqlite")]
6161
#[error("Rusqlite error: {0}")]
62-
RusqliteError(#[from] bdk_wallet::rusqlite::Error),
62+
RusqliteError(Box<bdk_wallet::rusqlite::Error>),
6363

6464
#[cfg(feature = "redb")]
6565
#[error("Redb StoreError: {0}")]
6666
RedbStoreError(Box<bdk_redb::error::StoreError>),
6767

6868
#[cfg(feature = "redb")]
6969
#[error("Redb dabtabase error: {0}")]
70-
RedbDatabaseError(#[from] bdk_redb::redb::DatabaseError),
70+
RedbDatabaseError(Box<bdk_redb::redb::DatabaseError>),
7171

7272
#[error("Serde json error: {0}")]
7373
SerdeJson(#[from] serde_json::Error),
@@ -112,6 +112,34 @@ pub enum BDKCliError {
112112
))]
113113
#[error("Reqwest error: {0}")]
114114
ReqwestError(#[from] reqwest::Error),
115+
116+
#[cfg(feature = "payjoin")]
117+
#[error("Payjoin URL parse error: {0}")]
118+
PayjoinUrlParse(#[from] payjoin::IntoUrlError),
119+
120+
#[cfg(feature = "payjoin")]
121+
#[error("Payjoin send response error: {0}")]
122+
PayjoinSendResponse(#[from] payjoin::send::ResponseError),
123+
124+
#[cfg(feature = "payjoin")]
125+
#[error("Payjoin sender build error: {0}")]
126+
PayjoinSenderBuild(#[from] payjoin::send::BuildSenderError),
127+
128+
#[cfg(feature = "payjoin")]
129+
#[error("Payjoin receive error: {0}")]
130+
PayjoinReceive(#[from] payjoin::receive::Error),
131+
132+
#[cfg(feature = "payjoin")]
133+
#[error("Payjoin selection error: {0}")]
134+
PayjoinSelection(#[from] payjoin::receive::SelectionError),
135+
136+
#[cfg(feature = "payjoin")]
137+
#[error("Payjoin input contribution error: {0}")]
138+
PayjoinInputContribution(#[from] payjoin::receive::InputContributionError),
139+
140+
#[cfg(feature = "payjoin")]
141+
#[error("Payjoin create request error: {0}")]
142+
PayjoinCreateRequest(#[from] payjoin::send::v2::CreateRequestError),
115143
}
116144

117145
impl From<ExtractTxError> for BDKCliError {
@@ -126,3 +154,17 @@ impl From<bdk_redb::error::StoreError> for BDKCliError {
126154
BDKCliError::RedbStoreError(Box::new(err))
127155
}
128156
}
157+
158+
#[cfg(feature = "redb")]
159+
impl From<bdk_redb::redb::DatabaseError> for BDKCliError {
160+
fn from(err: bdk_redb::redb::DatabaseError) -> Self {
161+
BDKCliError::RedbDatabaseError(Box::new(err))
162+
}
163+
}
164+
165+
#[cfg(feature = "sqlite")]
166+
impl From<bdk_wallet::rusqlite::Error> for BDKCliError {
167+
fn from(err: bdk_wallet::rusqlite::Error) -> Self {
168+
BDKCliError::RusqliteError(Box::new(err))
169+
}
170+
}

src/handlers.rs

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use crate::config::{WalletConfig, WalletConfigInner};
1515
use crate::error::BDKCliError as Error;
1616
#[cfg(any(feature = "sqlite", feature = "redb"))]
1717
use crate::persister::Persister;
18+
#[cfg(feature = "cbf")]
19+
use crate::utils::BlockchainClient::KyotoClient;
1820
use crate::utils::*;
1921
#[cfg(feature = "redb")]
2022
use bdk_redb::Store as RedbStore;
@@ -47,8 +49,6 @@ use bdk_wallet::{
4749
use clap::CommandFactory;
4850
use cli_table::{Cell, CellStruct, Style, Table, format::Justify};
4951
use serde_json::json;
50-
#[cfg(feature = "cbf")]
51-
use {crate::utils::BlockchainClient::KyotoClient, bdk_kyoto::LightClient, tokio::select};
5252

5353
#[cfg(feature = "electrum")]
5454
use crate::utils::BlockchainClient::Electrum;
@@ -606,7 +606,7 @@ pub fn handle_offline_wallet_subcommand(
606606
))]
607607
pub(crate) async fn handle_online_wallet_subcommand(
608608
wallet: &mut Wallet,
609-
client: BlockchainClient,
609+
client: &BlockchainClient,
610610
online_subcommand: OnlineWalletSubCommand,
611611
) -> Result<String, Error> {
612612
match online_subcommand {
@@ -633,7 +633,7 @@ pub(crate) async fn handle_online_wallet_subcommand(
633633
client
634634
.populate_tx_cache(wallet.tx_graph().full_txs().map(|tx_node| tx_node.tx));
635635

636-
let update = client.full_scan(request, _stop_gap, batch_size, false)?;
636+
let update = client.full_scan(request, _stop_gap, *batch_size, false)?;
637637
wallet.apply_update(update)?;
638638
}
639639
#[cfg(feature = "esplora")]
@@ -642,7 +642,7 @@ pub(crate) async fn handle_online_wallet_subcommand(
642642
parallel_requests,
643643
} => {
644644
let update = client
645-
.full_scan(request, _stop_gap, parallel_requests)
645+
.full_scan(request, _stop_gap, *parallel_requests)
646646
.await
647647
.map_err(|e| *e)?;
648648
wallet.apply_update(update)?;
@@ -659,7 +659,7 @@ pub(crate) async fn handle_online_wallet_subcommand(
659659
hash: genesis_block.block_hash(),
660660
});
661661
let mut emitter = Emitter::new(
662-
&*client,
662+
client.as_ref(),
663663
genesis_cp.clone(),
664664
genesis_cp.height(),
665665
NO_EXPECTED_MEMPOOL_TXS,
@@ -1157,6 +1157,7 @@ pub fn handle_wallets_subcommand(datadir: &Path, pretty: bool) -> Result<String,
11571157
.wallets
11581158
.iter()
11591159
.map(|(name, wallet_config)| {
1160+
#[allow(unused_mut)]
11601161
let mut wallet_json = json!({
11611162
"name": name,
11621163
"network": wallet_config.network,
@@ -1247,7 +1248,7 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
12471248

12481249
let result = handle_online_wallet_subcommand(
12491250
&mut wallet,
1250-
blockchain_client,
1251+
&blockchain_client,
12511252
online_subcommand,
12521253
)
12531254
.await?;
@@ -1259,7 +1260,7 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
12591260
let mut wallet = new_wallet(network, wallet_opts)?;
12601261
let blockchain_client =
12611262
crate::utils::new_blockchain_client(wallet_opts, &wallet, database_path)?;
1262-
handle_online_wallet_subcommand(&mut wallet, blockchain_client, online_subcommand)
1263+
handle_online_wallet_subcommand(&mut wallet, &blockchain_client, online_subcommand)
12631264
.await?
12641265
};
12651266
Ok(result)
@@ -1463,7 +1464,7 @@ async fn respond(
14631464
} => {
14641465
let blockchain =
14651466
new_blockchain_client(wallet_opts, wallet, _datadir).map_err(|e| e.to_string())?;
1466-
let value = handle_online_wallet_subcommand(wallet, blockchain, online_subcommand)
1467+
let value = handle_online_wallet_subcommand(wallet, &blockchain, online_subcommand)
14671468
.await
14681469
.map_err(|e| e.to_string())?;
14691470
Some(value)
@@ -1519,7 +1520,7 @@ async fn respond(
15191520
feature = "rpc"
15201521
))]
15211522
/// Syncs a given wallet using the blockchain client.
1522-
pub async fn sync_wallet(client: BlockchainClient, wallet: &mut Wallet) -> Result<(), Error> {
1523+
pub async fn sync_wallet(client: &BlockchainClient, wallet: &mut Wallet) -> Result<(), Error> {
15231524
#[cfg(any(feature = "electrum", feature = "esplora"))]
15241525
let request = wallet
15251526
.start_sync_with_revealed_spks()
@@ -1534,7 +1535,7 @@ pub async fn sync_wallet(client: BlockchainClient, wallet: &mut Wallet) -> Resul
15341535
// already have.
15351536
client.populate_tx_cache(wallet.tx_graph().full_txs().map(|tx_node| tx_node.tx));
15361537

1537-
let update = client.sync(request, batch_size, false)?;
1538+
let update = client.sync(request, *batch_size, false)?;
15381539
wallet
15391540
.apply_update(update)
15401541
.map_err(|e| Error::Generic(e.to_string()))
@@ -1545,7 +1546,7 @@ pub async fn sync_wallet(client: BlockchainClient, wallet: &mut Wallet) -> Resul
15451546
parallel_requests,
15461547
} => {
15471548
let update = client
1548-
.sync(request, parallel_requests)
1549+
.sync(request, *parallel_requests)
15491550
.await
15501551
.map_err(|e| *e)?;
15511552
wallet
@@ -1560,7 +1561,7 @@ pub async fn sync_wallet(client: BlockchainClient, wallet: &mut Wallet) -> Resul
15601561
// reload the last 200 blocks in case of a reorg
15611562
let emitter_height = wallet_cp.height().saturating_sub(200);
15621563
let mut emitter = Emitter::new(
1563-
&*client,
1564+
client.as_ref(),
15641565
wallet_cp,
15651566
emitter_height,
15661567
wallet
@@ -1611,7 +1612,7 @@ pub async fn sync_wallet(client: BlockchainClient, wallet: &mut Wallet) -> Resul
16111612
))]
16121613
/// Broadcasts a given transaction using the blockchain client.
16131614
pub async fn broadcast_transaction(
1614-
client: BlockchainClient,
1615+
client: &BlockchainClient,
16151616
tx: Transaction,
16161617
) -> Result<Txid, Error> {
16171618
match client {
@@ -1638,38 +1639,15 @@ pub async fn broadcast_transaction(
16381639

16391640
#[cfg(feature = "cbf")]
16401641
KyotoClient { client } => {
1641-
let LightClient {
1642-
requester,
1643-
mut info_subscriber,
1644-
mut warning_subscriber,
1645-
update_subscriber: _,
1646-
node,
1647-
} = *client;
1648-
1649-
let subscriber = tracing_subscriber::FmtSubscriber::new();
1650-
tracing::subscriber::set_global_default(subscriber)
1651-
.map_err(|e| Error::Generic(format!("SetGlobalDefault error: {e}")))?;
1652-
1653-
tokio::task::spawn(async move { node.run().await });
1654-
tokio::task::spawn(async move {
1655-
select! {
1656-
info = info_subscriber.recv() => {
1657-
if let Some(info) = info {
1658-
tracing::info!("{info}");
1659-
}
1660-
},
1661-
warn = warning_subscriber.recv() => {
1662-
if let Some(warn) = warn {
1663-
tracing::warn!("{warn}");
1664-
}
1665-
}
1666-
}
1667-
});
16681642
let txid = tx.compute_txid();
1669-
let wtxid = requester.broadcast_random(tx.clone()).await.map_err(|_| {
1670-
tracing::warn!("Broadcast was unsuccessful");
1671-
Error::Generic("Transaction broadcast timed out after 30 seconds".into())
1672-
})?;
1643+
let wtxid = client
1644+
.requester
1645+
.broadcast_random(tx.clone())
1646+
.await
1647+
.map_err(|_| {
1648+
tracing::warn!("Broadcast was unsuccessful");
1649+
Error::Generic("Transaction broadcast timed out after 30 seconds".into())
1650+
})?;
16731651
tracing::info!("Successfully broadcast WTXID: {wtxid}");
16741652
Ok(txid)
16751653
}

0 commit comments

Comments
 (0)