Skip to content

Commit

Permalink
core: fix the estimationfeee response
Browse files Browse the repository at this point in the history
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: ElementsProject/lightning#7294 (comment)
Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo committed May 8, 2024
1 parent 0991d23 commit 34e2bf2
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions folgore-common/src/client/fee_estimator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -42,29 +41,22 @@ impl FeeEstimator {

pub fn build_estimate_fees(fees: &BTreeMap<u64, FeeRate>) -> Result<Value, PluginError> {
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<Value, PluginError> {
let mut resp = json_utils::init_payload();
json_utils::add_number(&mut resp, "feerate_floor", 1000);
json_utils::add_vec::<Value>(&mut resp, "feerates", vec![]);
Ok(resp)
Ok(serde_json::json!({
"feerate_floor": 1000,
"feerates": {},
}))
}
}

0 comments on commit 34e2bf2

Please sign in to comment.