Skip to content

Commit 8337a89

Browse files
committed
fix(client)!: use Amount and FeeRate instead of f64 for submit_package
1 parent 6ce4c61 commit 8337a89

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

src/async.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ use bitcoin::{Address, Block, BlockHash, FeeRate, MerkleBlock, Script, Transacti
4242
use reqwest::{header, Body, Client, Response};
4343

4444
use crate::{
45-
sat_per_vbyte_to_feerate, AddressStats, BlockInfo, BlockStatus, Builder, Error, EsploraTx,
46-
MempoolRecentTx, MempoolStats, MerkleProof, OutputStatus, ScriptHashStats, SubmitPackageResult,
47-
TxStatus, Utxo, BASE_BACKOFF_MILLIS, RETRYABLE_ERROR_CODES,
45+
sat_per_vbyte_to_feerate, AddressStats, Amount, BlockInfo, BlockStatus, Builder, Error,
46+
EsploraTx, MempoolRecentTx, MempoolStats, MerkleProof, OutputStatus, ScriptHashStats,
47+
SubmitPackageResult, TxStatus, Utxo, BASE_BACKOFF_MILLIS, RETRYABLE_ERROR_CODES,
4848
};
4949

5050
/// Returns `true` if the given HTTP status code should trigger a retry.
@@ -383,29 +383,33 @@ impl<S: Sleeper> AsyncClient<S> {
383383
/// Returns a [`SubmitPackageResult`] containing the result for each
384384
/// transaction in the package, keyed by [`Wtxid`](bitcoin::Wtxid).
385385
///
386-
/// Optionally, `maxfeerate` (in sat/vB) and `maxburnamount` (in BTC) can
387-
/// be provided to reject transactions that exceed these thresholds.
386+
/// Optionally, `maxfeerate` (as a [`FeeRate`]) and `maxburnamount`
387+
/// (as an [`Amount`]) can be provided to reject transactions that
388+
/// exceed these thresholds.
388389
///
389390
/// # Errors
390391
///
391392
/// Returns an [`Error`] if the request fails or the server rejects the package.
392393
pub async fn submit_package(
393394
&self,
394395
transactions: &[Transaction],
395-
maxfeerate: Option<f64>,
396-
maxburnamount: Option<f64>,
396+
maxfeerate: Option<FeeRate>,
397+
maxburnamount: Option<Amount>,
397398
) -> Result<SubmitPackageResult, Error> {
398399
let serialized_txs = transactions
399400
.iter()
400401
.map(|tx| serialize_hex(&tx))
401402
.collect::<Vec<_>>();
402403

403404
let mut queryparams = HashSet::<(&str, String)>::new();
405+
406+
// Esplora expects `maxfeerate` in sats/vB.
404407
if let Some(maxfeerate) = maxfeerate {
405-
queryparams.insert(("maxfeerate", maxfeerate.to_string()));
408+
queryparams.insert(("maxfeerate", maxfeerate.to_sat_per_vb_ceil().to_string()));
406409
}
410+
// Esplora expects `maxburnamount` in BTC.
407411
if let Some(maxburnamount) = maxburnamount {
408-
queryparams.insert(("maxburnamount", maxburnamount.to_string()));
412+
queryparams.insert(("maxburnamount", maxburnamount.to_btc().to_string()));
409413
}
410414

411415
let response = self

src/blocking.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use bitcoin::consensus::encode::serialize_hex;
3636
use bitcoin::consensus::{deserialize, serialize, Decodable};
3737
use bitcoin::hashes::{sha256, Hash};
3838
use bitcoin::hex::{DisplayHex, FromHex};
39-
use bitcoin::{Address, Block, BlockHash, FeeRate, MerkleBlock, Script, Transaction, Txid};
39+
use bitcoin::{Address, Amount, Block, BlockHash, FeeRate, MerkleBlock, Script, Transaction, Txid};
4040

4141
use crate::{
4242
sat_per_vbyte_to_feerate, AddressStats, BlockInfo, BlockStatus, Builder, Error, EsploraTx,
@@ -383,17 +383,18 @@ impl BlockingClient {
383383
/// Returns a [`SubmitPackageResult`] containing the result for each
384384
/// transaction in the package, keyed by [`Wtxid`](bitcoin::Wtxid).
385385
///
386-
/// Optionally, `maxfeerate` (in sat/vB) and `maxburnamount` (in BTC) can
387-
/// be provided to reject transactions that exceed these thresholds.
386+
/// Optionally, `maxfeerate` (as a [`FeeRate`]) and `maxburnamount`
387+
/// (as an [`Amount`]) can be provided to reject transactions that
388+
/// exceed these thresholds.
388389
///
389390
/// # Errors
390391
///
391392
/// Returns an [`Error`] if the request fails or the server rejects the package.
392393
pub fn submit_package(
393394
&self,
394395
transactions: &[Transaction],
395-
maxfeerate: Option<f64>,
396-
maxburnamount: Option<f64>,
396+
maxfeerate: Option<FeeRate>,
397+
maxburnamount: Option<Amount>,
397398
) -> Result<SubmitPackageResult, Error> {
398399
let serialized_txs = transactions
399400
.iter()
@@ -407,12 +408,14 @@ impl BlockingClient {
407408
.into_bytes(),
408409
)?;
409410

411+
// Esplora expects `maxfeerate` in sats/vB.
410412
if let Some(maxfeerate) = maxfeerate {
411-
request = request.with_param("maxfeerate", maxfeerate.to_string())
413+
request = request.with_param("maxfeerate", maxfeerate.to_sat_per_vb_ceil().to_string())
412414
}
413415

416+
// Esplora expects `maxburnamount` in BTC.
414417
if let Some(maxburnamount) = maxburnamount {
415-
request = request.with_param("maxburnamount", maxburnamount.to_string())
418+
request = request.with_param("maxburnamount", maxburnamount.to_btc().to_string())
416419
}
417420

418421
match request.send() {

0 commit comments

Comments
 (0)