Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 90fafd4

Browse files
committed
LSPS1: Use bitcoin::FeeRate instead of u8
1 parent d3c03f9 commit 90fafd4

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/lsps0/ser.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,3 +653,26 @@ pub(crate) mod string_amount_option {
653653
}
654654
}
655655
}
656+
657+
#[cfg(lsps1)]
658+
pub(crate) mod u32_fee_rate {
659+
use bitcoin::FeeRate;
660+
use serde::{Deserialize, Deserializer, Serializer};
661+
662+
pub(crate) fn serialize<S>(x: &FeeRate, s: S) -> Result<S::Ok, S::Error>
663+
where
664+
S: Serializer,
665+
{
666+
let fee_rate_sat_kwu = x.to_sat_per_kwu();
667+
s.serialize_u32(fee_rate_sat_kwu as u32)
668+
}
669+
670+
pub(crate) fn deserialize<'de, D>(deserializer: D) -> Result<FeeRate, D::Error>
671+
where
672+
D: Deserializer<'de>,
673+
{
674+
let fee_rate_sat_kwu = u32::deserialize(deserializer)?;
675+
676+
Ok(FeeRate::from_sat_per_kwu(fee_rate_sat_kwu as u64))
677+
}
678+
}

src/lsps1/msgs.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//! Message, request, and other primitive types used to implement LSPS1.
22
33
use crate::lsps0::ser::{
4-
string_amount, string_amount_option, LSPSMessage, RequestId, ResponseError,
4+
string_amount, string_amount_option, u32_fee_rate, LSPSMessage, RequestId, ResponseError,
55
};
66

77
use crate::prelude::{String, Vec};
88

99
use bitcoin::address::{Address, NetworkUnchecked};
10-
use bitcoin::OutPoint;
10+
use bitcoin::{FeeRate, OutPoint};
1111

1212
use lightning_invoice::Bolt11Invoice;
1313

@@ -170,7 +170,8 @@ pub struct PaymentInfo {
170170
pub min_onchain_payment_confirmations: Option<u16>,
171171
/// The minimum fee rate for the on-chain payment in case the client wants the payment to be
172172
/// confirmed without a confirmation.
173-
pub min_fee_for_0conf: u8,
173+
#[serde(with = "u32_fee_rate")]
174+
pub min_fee_for_0conf: FeeRate,
174175
/// Details regarding a detected on-chain payment.
175176
pub onchain_payment: Option<OnchainPayment>,
176177
}

0 commit comments

Comments
 (0)