From a2fa82d010ff0fe74ce9ae158a421498dd21efb0 Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Wed, 8 May 2024 06:41:45 +0200 Subject: [PATCH] revert estimation fee change commit Signed-off-by: Vincenzo Palazzo --- folgore-common/src/client/fee_estimator.rs | 11 +++++-- folgore-esplora/src/lib.rs | 34 +++++++++++----------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/folgore-common/src/client/fee_estimator.rs b/folgore-common/src/client/fee_estimator.rs index c5ee242..07393b8 100644 --- a/folgore-common/src/client/fee_estimator.rs +++ b/folgore-common/src/client/fee_estimator.rs @@ -1,7 +1,6 @@ //! Generic Fee estimator for all the folgore backend. use std::collections::BTreeMap; -use crate::prelude::cln::json_utils; use crate::prelude::cln_plugin::error; use crate::prelude::cln_plugin::errors::PluginError; use crate::prelude::json::Value; @@ -40,9 +39,15 @@ impl FeeEstimator { } pub fn build_estimate_fees(fees: &BTreeMap) -> Result { - let mut resp = json_utils::init_payload(); + let mut resp = vec![]; for (height, rate) in fees.iter() { - json_utils::add_number(&mut resp, &format!("{height}"), *rate as i64); + if *height == 0 { + continue; + } + resp.push(serde_json::json!({ + "blocks": height, + "feerate": rate, + })) } let floor = *fees .get(&0) diff --git a/folgore-esplora/src/lib.rs b/folgore-esplora/src/lib.rs index 3c8b2a0..7956595 100644 --- a/folgore-esplora/src/lib.rs +++ b/folgore-esplora/src/lib.rs @@ -441,25 +441,25 @@ mod tests { #[derive(Deserialize, Debug)] struct FeeEstimation { - feerates: serde_json::Value, + feerates: Vec, + } + + #[derive(Deserialize, Debug)] + struct PerBlockFee { + blocks: u64, + feerate: u64, } let fee_estimation: FeeEstimation = serde_json::from_value(fee_estimation).unwrap(); - assert!(fee_estimation.feerates.get("0").is_some()); - assert!(fee_estimation.feerates.get("2").is_some()); - assert!(fee_estimation.feerates.get("6").is_some()); - assert!(fee_estimation.feerates.get("12").is_some()); - assert!(fee_estimation.feerates.get("100").is_some()); - - assert_eq!( - fee_estimation.feerates.get("0").unwrap(), - 15 * 1000, - "{:?}", - fee_estimation - ); - assert_eq!(fee_estimation.feerates.get("2").unwrap(), 45 * 1000); - assert_eq!(fee_estimation.feerates.get("6").unwrap(), 26 * 1000); - assert_eq!(fee_estimation.feerates.get("12").unwrap(), 21 * 1000); - assert_eq!(fee_estimation.feerates.get("100").unwrap(), 15 * 1000); + assert!(!fee_estimation.feerates.is_empty(), "{:?}", fee_ranges); + assert_eq!(fee_estimation.feerates[0].blocks, 2); + assert_eq!(fee_estimation.feerates[1].blocks, 6); + assert_eq!(fee_estimation.feerates[2].blocks, 12); + assert_eq!(fee_estimation.feerates[3].blocks, 100); + + assert_eq!(fee_estimation.feerates[0].feerate, 45 * 1000); + assert_eq!(fee_estimation.feerates[1].feerate, 26 * 1000); + assert_eq!(fee_estimation.feerates[2].feerate, 21 * 1000); + assert_eq!(fee_estimation.feerates[3].feerate, 15 * 1000); } }