Skip to content

Commit 60321b9

Browse files
committed
Add estimate_fee to batch methods
1 parent 7b37037 commit 60321b9

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

src/batch.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ impl Batch {
4949
self.calls
5050
.push((String::from("blockchain.transaction.get"), params));
5151
}
52+
53+
/// Add one `blockchain.estimatefee` request to the batch queue
54+
pub fn estimate_fee(&mut self, number: usize) {
55+
let params = vec![Param::Usize(number)];
56+
self.calls
57+
.push((String::from("blockchain.estimatefee"), params));
58+
}
5259
}
5360

5461
impl std::iter::IntoIterator for Batch {

src/client.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ impl<S: Read + Write> Client<S> {
566566

567567
Ok(serde_json::from_value(result)?)
568568
}
569+
569570
/// Batch version of [`script_list_unspent`](#method.script_list_unspent).
570571
///
571572
/// Takes a list of scripts and returns a list of a list of utxos.
@@ -604,6 +605,17 @@ impl<S: Read + Write> Client<S> {
604605
impl_batch_call!(self, txids, transaction_get)
605606
}
606607

608+
/// Batch version of [`estimate_fee`](#method.estimate_fee).
609+
///
610+
/// Takes a list of `numbers` of blocks and returns a list of fee required in
611+
/// **Satoshis per kilobyte** to confirm a transaction in the given number of blocks.
612+
pub fn batch_estimate_fee<'s, I>(&mut self, numbers: I) -> Result<Vec<f64>, Error>
613+
where
614+
I: IntoIterator<Item = usize>,
615+
{
616+
impl_batch_call!(self, numbers, estimate_fee)
617+
}
618+
607619
/// Broadcasts a transaction to the network.
608620
pub fn transaction_broadcast(&mut self, tx: &Transaction) -> Result<Txid, Error> {
609621
let buffer: Vec<u8> = serialize(tx);
@@ -848,6 +860,18 @@ mod test {
848860
impl_test_conclusion!(test_case, client.stream);
849861
}
850862

863+
#[test]
864+
fn test_batch_estimate_fee() {
865+
let test_case = "batch_estimate_fee";
866+
let mut client = impl_test_prelude!(test_case);
867+
868+
let resp = client.batch_estimate_fee(vec![10, 20]).unwrap();
869+
assert_eq!(resp[0], 10.0);
870+
assert_eq!(resp[1], 20.0);
871+
872+
impl_test_conclusion!(test_case, client.stream);
873+
}
874+
851875
#[test]
852876
fn test_transaction_get() {
853877
use bitcoin::hashes::hex::FromHex;

test_data/batch_estimate_fee.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{"id":0,"jsonrpc":"2.0","result":10.0}
2+
{"id":0,"jsonrpc":"2.0","result":20.0}

test_data/batch_estimate_fee.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{"jsonrpc":"2.0","id":0,"method":"blockchain.estimatefee","params":[10]}
2+
{"jsonrpc":"2.0","id":1,"method":"blockchain.estimatefee","params":[20]}

0 commit comments

Comments
 (0)