From 34e2bf28dbb94bfd0d1af3748079eaf2d74ba188 Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Tue, 7 May 2024 21:32:28 +0200 Subject: [PATCH] core: fix the estimationfeee response Core lightning was ignoring the request of my estimationfeee because was assuming that cln was accepting an array, but I was wrong. Now there is a proposal of changin the format but I do not want push it too much due that we already changes the format one time. Link: https://github.com/ElementsProject/lightning/issues/7294#issuecomment-2099079653 Signed-off-by: Vincenzo Palazzo --- folgore-common/src/client/fee_estimator.rs | 32 ++++++++-------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/folgore-common/src/client/fee_estimator.rs b/folgore-common/src/client/fee_estimator.rs index ec7b41f..c5ee242 100644 --- a/folgore-common/src/client/fee_estimator.rs +++ b/folgore-common/src/client/fee_estimator.rs @@ -4,7 +4,6 @@ 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::json; use crate::prelude::json::Value; /// Transaction fee rate in satoshis/vByte. @@ -42,29 +41,22 @@ impl FeeEstimator { pub fn build_estimate_fees(fees: &BTreeMap) -> Result { let mut resp = json_utils::init_payload(); - - json_utils::add_number( - &mut resp, - "feerate_floor", - *fees - .get(&0) - .ok_or(error!("impossible get the minimum feerate"))? as i64, - ); - let mut feerates = vec![]; for (height, rate) in fees.iter() { - feerates.push(json!({ - "blocks": height, - "feerate": rate, - })) + json_utils::add_number(&mut resp, &format!("{height}"), *rate as i64); } - json_utils::add_vec(&mut resp, "feerates", feerates); - Ok(resp) + let floor = *fees + .get(&0) + .ok_or(error!("impossible get the minimum feerate"))? as i64; + Ok(serde_json::json!({ + "feerate_floor": floor, + "feerates": resp, + })) } pub fn null_estimate_fees() -> Result { - let mut resp = json_utils::init_payload(); - json_utils::add_number(&mut resp, "feerate_floor", 1000); - json_utils::add_vec::(&mut resp, "feerates", vec![]); - Ok(resp) + Ok(serde_json::json!({ + "feerate_floor": 1000, + "feerates": {}, + })) } }