Skip to content

Commit

Permalink
revert estimation fee change commit
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo committed May 8, 2024
1 parent 34e2bf2 commit 99e2926
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
8 changes: 5 additions & 3 deletions folgore-common/src/client/fee_estimator.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -40,9 +39,12 @@ impl FeeEstimator {
}

pub fn build_estimate_fees(fees: &BTreeMap<u64, FeeRate>) -> Result<Value, PluginError> {
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);
resp.push(serde_json::json!({
"blocks": height,
"feerate": rate,
}))
}
let floor = *fees
.get(&0)
Expand Down
36 changes: 19 additions & 17 deletions folgore-esplora/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,25 +441,27 @@ mod tests {

#[derive(Deserialize, Debug)]
struct FeeEstimation {
feerates: serde_json::Value,
feerates: Vec<PerBlockFee>,
}

#[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, 0);
assert_eq!(fee_estimation.feerates[1].blocks, 2);
assert_eq!(fee_estimation.feerates[2].blocks, 6);
assert_eq!(fee_estimation.feerates[3].blocks, 12);
assert_eq!(fee_estimation.feerates[4].blocks, 100);

assert_eq!(fee_estimation.feerates[0].feerate, 15 * 1000);
assert_eq!(fee_estimation.feerates[1].feerate, 45 * 1000);
assert_eq!(fee_estimation.feerates[2].feerate, 26 * 1000);
assert_eq!(fee_estimation.feerates[3].feerate, 21 * 1000);
assert_eq!(fee_estimation.feerates[4].feerate, 15 * 1000);
}
}

0 comments on commit 99e2926

Please sign in to comment.