mirror of
https://github.com/romanz/electrs.git
synced 2024-11-19 09:54:09 +01:00
Support (older) ETA-based fee estimation
This commit is contained in:
parent
fdff31a069
commit
a681334074
13
src/query.rs
13
src/query.rs
@ -310,5 +310,18 @@ impl<'a> Query<'a> {
|
||||
self.tracker.read().unwrap().fee_histogram().clone()
|
||||
}
|
||||
|
||||
// Fee rate [BTC/kB] to be confirmed in `blocks` from now.
|
||||
pub fn estimate_fee(&self, blocks: usize) -> f32 {
|
||||
let mut total_vsize = 0u32;
|
||||
let mut last_fee_rate = 0.0;
|
||||
let blocks_in_vbytes = (blocks * 1_000_000) as u32; // assume ~1MB blocks
|
||||
for (fee_rate, vsize) in self.tracker.read().unwrap().fee_histogram() {
|
||||
last_fee_rate = *fee_rate;
|
||||
total_vsize += vsize;
|
||||
if total_vsize >= blocks_in_vbytes {
|
||||
break; // under-estimate the fee rate a bit
|
||||
}
|
||||
}
|
||||
last_fee_rate * 1e-5 // [BTC/kB] = 10^5 [sat/B]
|
||||
}
|
||||
}
|
||||
|
@ -103,8 +103,11 @@ impl<'a> Connection<'a> {
|
||||
Ok(json!(jsonify_header(&headers[0], height)))
|
||||
}
|
||||
|
||||
fn blockchain_estimatefee(&self, _params: &[Value]) -> Result<Value> {
|
||||
Ok(json!(-1)) // see mempool_get_fee_histogram() instead.
|
||||
fn blockchain_estimatefee(&self, params: &[Value]) -> Result<Value> {
|
||||
let blocks = params.get(0).chain_err(|| "missing blocks")?;
|
||||
let blocks = blocks.as_u64().chain_err(|| "non-number blocks")? as usize;
|
||||
let fee_rate = self.query.estimate_fee(blocks); // in BTC/kB
|
||||
Ok(json!(fee_rate))
|
||||
}
|
||||
|
||||
fn blockchain_relayfee(&self) -> Result<Value> {
|
||||
|
Loading…
Reference in New Issue
Block a user