- type Error = std::io::Error;
- fn try_into(self) -> std::io::Result<FeeResponse> {
- let errored = !self.0["errors"].is_null();
- Ok(FeeResponse {
- errored,
- feerate: match errored {
- true => None,
- // The feerate from bitcoind is in BTC/kb, and we want satoshis/kb.
- false => Some((self.0["feerate"].as_f64().unwrap() * 100_000_000.0).round() as u32)
- }
- })
- }
+ type Error = std::io::Error;
+ fn try_into(self) -> std::io::Result<FeeResponse> {
+ let errored = !self.0["errors"].is_null();
+ Ok(FeeResponse {
+ errored,
+ feerate_sat_per_kw: match self.0["feerate"].as_f64() {
+ // Bitcoin Core gives us a feerate in BTC/KvB, which we need to convert to
+ // satoshis/KW. Thus, we first multiply by 10^8 to get satoshis, then divide by 4
+ // to convert virtual-bytes into weight units.
+ Some(feerate_btc_per_kvbyte) => {
+ Some((feerate_btc_per_kvbyte * 100_000_000.0 / 4.0).round() as u32)
+ }
+ None => None,
+ },
+ })
+ }