X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fconvert.rs;h=64039233e7d5800fc9c1c147c2e800c328ced0fd;hb=2dbe461743604d8ce8219e99ea337dd7b8b498df;hp=7dbd8cceb13caca3938a35077f205b1ff96aa386;hpb=6199433ab8f13e4f78b12e13a683eb33c999114b;p=ldk-sample diff --git a/src/convert.rs b/src/convert.rs index 7dbd8cc..6403923 100644 --- a/src/convert.rs +++ b/src/convert.rs @@ -51,7 +51,7 @@ impl TryInto for JsonResponse { } pub struct FeeResponse { - pub feerate: Option, + pub feerate_sat_per_kw: Option, pub errored: bool, } @@ -61,8 +61,13 @@ impl TryInto for JsonResponse { let errored = !self.0["errors"].is_null(); Ok(FeeResponse { errored, - feerate: match self.0["feerate"].as_f64() { - Some(fee) => Some((fee * 100_000_000.0).round() as u32), + 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, }, }) @@ -72,6 +77,7 @@ impl TryInto for JsonResponse { pub struct BlockchainInfo { pub latest_height: usize, pub latest_blockhash: BlockHash, + pub chain: String, } impl TryInto for JsonResponse { @@ -81,6 +87,7 @@ impl TryInto for JsonResponse { latest_height: self.0["blocks"].as_u64().unwrap() as usize, latest_blockhash: BlockHash::from_hex(self.0["bestblockhash"].as_str().unwrap()) .unwrap(), + chain: self.0["chain"].as_str().unwrap().to_string(), }) } }