Skip to content

Commit ace5850

Browse files
committed
Merge branch 'master' into chore/remove-msrv
2 parents 09b5b3b + 46e1ab7 commit ace5850

File tree

8 files changed

+254
-217
lines changed

8 files changed

+254
-217
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
@@ -24,6 +24,15 @@ build: fmt
2424
test:
2525
cargo test --all-features --tests
2626

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

src/error.rs

Lines changed: 52 additions & 3 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}")]
66-
RedbStoreError(#[from] bdk_redb::error::StoreError),
66+
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,10 +112,59 @@ 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 {
118146
fn from(value: ExtractTxError) -> Self {
119147
BDKCliError::PsbtExtractTxError(Box::new(value))
120148
}
121149
}
150+
151+
#[cfg(feature = "redb")]
152+
impl From<bdk_redb::error::StoreError> for BDKCliError {
153+
fn from(err: bdk_redb::error::StoreError) -> Self {
154+
BDKCliError::RedbStoreError(Box::new(err))
155+
}
156+
}
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;
@@ -46,8 +48,6 @@ use bdk_wallet::{
4648
};
4749
use cli_table::{Cell, CellStruct, Style, Table, format::Justify};
4850
use serde_json::json;
49-
#[cfg(feature = "cbf")]
50-
use {crate::utils::BlockchainClient::KyotoClient, bdk_kyoto::LightClient, tokio::select};
5151

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

635-
let update = client.full_scan(request, _stop_gap, batch_size, false)?;
635+
let update = client.full_scan(request, _stop_gap, *batch_size, false)?;
636636
wallet.apply_update(update)?;
637637
}
638638
#[cfg(feature = "esplora")]
@@ -641,7 +641,7 @@ pub(crate) async fn handle_online_wallet_subcommand(
641641
parallel_requests,
642642
} => {
643643
let update = client
644-
.full_scan(request, _stop_gap, parallel_requests)
644+
.full_scan(request, _stop_gap, *parallel_requests)
645645
.await
646646
.map_err(|e| *e)?;
647647
wallet.apply_update(update)?;
@@ -658,7 +658,7 @@ pub(crate) async fn handle_online_wallet_subcommand(
658658
hash: genesis_block.block_hash(),
659659
});
660660
let mut emitter = Emitter::new(
661-
&*client,
661+
client.as_ref(),
662662
genesis_cp.clone(),
663663
genesis_cp.height(),
664664
NO_EXPECTED_MEMPOOL_TXS,
@@ -1156,6 +1156,7 @@ pub fn handle_wallets_subcommand(datadir: &Path, pretty: bool) -> Result<String,
11561156
.wallets
11571157
.iter()
11581158
.map(|(name, wallet_config)| {
1159+
#[allow(unused_mut)]
11591160
let mut wallet_json = json!({
11601161
"name": name,
11611162
"network": wallet_config.network,
@@ -1246,7 +1247,7 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
12461247

12471248
let result = handle_online_wallet_subcommand(
12481249
&mut wallet,
1249-
blockchain_client,
1250+
&blockchain_client,
12501251
online_subcommand,
12511252
)
12521253
.await?;
@@ -1258,7 +1259,7 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
12581259
let mut wallet = new_wallet(network, wallet_opts)?;
12591260
let blockchain_client =
12601261
crate::utils::new_blockchain_client(wallet_opts, &wallet, database_path)?;
1261-
handle_online_wallet_subcommand(&mut wallet, blockchain_client, online_subcommand)
1262+
handle_online_wallet_subcommand(&mut wallet, &blockchain_client, online_subcommand)
12621263
.await?
12631264
};
12641265
Ok(result)
@@ -1452,7 +1453,7 @@ async fn respond(
14521453
} => {
14531454
let blockchain =
14541455
new_blockchain_client(wallet_opts, wallet, _datadir).map_err(|e| e.to_string())?;
1455-
let value = handle_online_wallet_subcommand(wallet, blockchain, online_subcommand)
1456+
let value = handle_online_wallet_subcommand(wallet, &blockchain, online_subcommand)
14561457
.await
14571458
.map_err(|e| e.to_string())?;
14581459
Some(value)
@@ -1508,7 +1509,7 @@ async fn respond(
15081509
feature = "rpc"
15091510
))]
15101511
/// Syncs a given wallet using the blockchain client.
1511-
pub async fn sync_wallet(client: BlockchainClient, wallet: &mut Wallet) -> Result<(), Error> {
1512+
pub async fn sync_wallet(client: &BlockchainClient, wallet: &mut Wallet) -> Result<(), Error> {
15121513
#[cfg(any(feature = "electrum", feature = "esplora"))]
15131514
let request = wallet
15141515
.start_sync_with_revealed_spks()
@@ -1523,7 +1524,7 @@ pub async fn sync_wallet(client: BlockchainClient, wallet: &mut Wallet) -> Resul
15231524
// already have.
15241525
client.populate_tx_cache(wallet.tx_graph().full_txs().map(|tx_node| tx_node.tx));
15251526

1526-
let update = client.sync(request, batch_size, false)?;
1527+
let update = client.sync(request, *batch_size, false)?;
15271528
wallet
15281529
.apply_update(update)
15291530
.map_err(|e| Error::Generic(e.to_string()))
@@ -1534,7 +1535,7 @@ pub async fn sync_wallet(client: BlockchainClient, wallet: &mut Wallet) -> Resul
15341535
parallel_requests,
15351536
} => {
15361537
let update = client
1537-
.sync(request, parallel_requests)
1538+
.sync(request, *parallel_requests)
15381539
.await
15391540
.map_err(|e| *e)?;
15401541
wallet
@@ -1549,7 +1550,7 @@ pub async fn sync_wallet(client: BlockchainClient, wallet: &mut Wallet) -> Resul
15491550
// reload the last 200 blocks in case of a reorg
15501551
let emitter_height = wallet_cp.height().saturating_sub(200);
15511552
let mut emitter = Emitter::new(
1552-
&*client,
1553+
client.as_ref(),
15531554
wallet_cp,
15541555
emitter_height,
15551556
wallet
@@ -1600,7 +1601,7 @@ pub async fn sync_wallet(client: BlockchainClient, wallet: &mut Wallet) -> Resul
16001601
))]
16011602
/// Broadcasts a given transaction using the blockchain client.
16021603
pub async fn broadcast_transaction(
1603-
client: BlockchainClient,
1604+
client: &BlockchainClient,
16041605
tx: Transaction,
16051606
) -> Result<Txid, Error> {
16061607
match client {
@@ -1627,38 +1628,15 @@ pub async fn broadcast_transaction(
16271628

16281629
#[cfg(feature = "cbf")]
16291630
KyotoClient { client } => {
1630-
let LightClient {
1631-
requester,
1632-
mut info_subscriber,
1633-
mut warning_subscriber,
1634-
update_subscriber: _,
1635-
node,
1636-
} = *client;
1637-
1638-
let subscriber = tracing_subscriber::FmtSubscriber::new();
1639-
tracing::subscriber::set_global_default(subscriber)
1640-
.map_err(|e| Error::Generic(format!("SetGlobalDefault error: {e}")))?;
1641-
1642-
tokio::task::spawn(async move { node.run().await });
1643-
tokio::task::spawn(async move {
1644-
select! {
1645-
info = info_subscriber.recv() => {
1646-
if let Some(info) = info {
1647-
tracing::info!("{info}");
1648-
}
1649-
},
1650-
warn = warning_subscriber.recv() => {
1651-
if let Some(warn) = warn {
1652-
tracing::warn!("{warn}");
1653-
}
1654-
}
1655-
}
1656-
});
16571631
let txid = tx.compute_txid();
1658-
let wtxid = requester.broadcast_random(tx.clone()).await.map_err(|_| {
1659-
tracing::warn!("Broadcast was unsuccessful");
1660-
Error::Generic("Transaction broadcast timed out after 30 seconds".into())
1661-
})?;
1632+
let wtxid = client
1633+
.requester
1634+
.broadcast_random(tx.clone())
1635+
.await
1636+
.map_err(|_| {
1637+
tracing::warn!("Broadcast was unsuccessful");
1638+
Error::Generic("Transaction broadcast timed out after 30 seconds".into())
1639+
})?;
16621640
tracing::info!("Successfully broadcast WTXID: {wtxid}");
16631641
Ok(txid)
16641642
}

0 commit comments

Comments
 (0)