Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ page. See [DEVELOPMENT_CYCLE.md](DEVELOPMENT_CYCLE.md) for more details.
- Fixed `key generate` silently producing a 24-word mnemonic for any `--entropy` value other than 12; values other than 12 and 24 are now rejected
- Gated `full_scan`'s `--scan-stop-gap` to the Electrum and Esplora backends that use it; RPC and CBF wallets now reject the flag instead of silently ignoring it, while a `STOP_GAP` environment variable keeps working for supported backends and no longer breaks unsupported ones
- Changed `payjoin history` to return JSON instead of a rendered table
- Fixed the `rpc` backend failing against servers that send chunked responses ("The server replied with a chunked response which is not supported"); the RPC client now uses jsonrpc's `minreq_http` transport

## [4.0.0]

Expand Down
35 changes: 33 additions & 2 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,38 @@ fn esplora_proxy_url(proxy_opts: &ProxyOpts) -> Option<String> {
})
}

/// Create a bitcoind RPC client over the minreq HTTP transport, which reads
/// chunked responses. The default simple_http transport rejects them.
#[cfg(feature = "rpc")]
fn rpc_client(
url: &str,
auth: bdk_bitcoind_rpc::bitcoincore_rpc::Auth,
) -> Result<bdk_bitcoind_rpc::bitcoincore_rpc::Client, Error> {
use bdk_bitcoind_rpc::bitcoincore_rpc::{self, jsonrpc};

let rpc_error =
|e: jsonrpc::Error| Error::BitcoinCoreRpcError(bitcoincore_rpc::Error::JsonRpc(e));
let (user, pass) = auth.get_user_pass().map_err(Error::BitcoinCoreRpcError)?;

// simple_http accepts a url without a scheme, minreq requires one.
let url = if url.contains("://") {
url.to_string()
} else {
format!("http://{url}")
};

let mut builder = jsonrpc::minreq_http::Builder::new()
.url(&url)
.map_err(|e| rpc_error(e.into()))?;
if let Some(user) = user {
builder = builder.basic_auth(user, pass);
}

Ok(bitcoincore_rpc::Client::from_jsonrpc(
jsonrpc::Client::with_transport(builder.build()),
))
}

#[cfg(any(
feature = "electrum",
feature = "esplora",
Expand Down Expand Up @@ -300,8 +332,7 @@ pub(crate) fn new_blockchain_client(
wallet_opts.basic_auth.1.clone(),
),
};
let client = bdk_bitcoind_rpc::bitcoincore_rpc::Client::new(url, auth)
.map_err(Error::BitcoinCoreRpcError)?;
let client = rpc_client(url, auth)?;
BlockchainClient::RpcClient {
client: Box::new(client),
}
Expand Down