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

Commit 0d1a1f6

Browse files
authored
Merge pull request #133 from tnull/2024-05-lsps1-switch-u8-to-u16
2 parents 1da2a14 + 90fafd4 commit 0d1a1f6

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

src/lsps0/ser.rs

+23
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

+10-9
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

@@ -40,11 +40,11 @@ pub struct GetInfoRequest {}
4040
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
4141
pub struct OptionsSupported {
4242
/// The smallest number of confirmations needed for the LSP to accept a channel as confirmed.
43-
pub min_required_channel_confirmations: u8,
43+
pub min_required_channel_confirmations: u16,
4444
/// The smallest number of blocks in which the LSP can confirm the funding transaction.
45-
pub min_funding_confirms_within_blocks: u8,
45+
pub min_funding_confirms_within_blocks: u16,
4646
/// The minimum number of block confirmations before the LSP accepts an on-chain payment as confirmed.
47-
pub min_onchain_payment_confirmations: Option<u8>,
47+
pub min_onchain_payment_confirmations: Option<u16>,
4848
/// Indicates if the LSP supports zero reserve.
4949
pub supports_zero_channel_reserve: bool,
5050
/// Indicates the minimum amount of satoshi that is required for the LSP to accept a payment
@@ -104,9 +104,9 @@ pub struct OrderParams {
104104
#[serde(with = "string_amount")]
105105
pub client_balance_sat: u64,
106106
/// The number of confirmations the funding tx must have before the LSP sends `channel_ready`.
107-
pub required_channel_confirmations: u8,
107+
pub required_channel_confirmations: u16,
108108
/// The maximum number of blocks the client wants to wait until the funding transaction is confirmed.
109-
pub funding_confirms_within_blocks: u8,
109+
pub funding_confirms_within_blocks: u16,
110110
/// Indicates how long the channel is leased for in block time.
111111
pub channel_expiry_blocks: u32,
112112
/// May contain arbitrary associated data like a coupon code or a authentication token.
@@ -167,10 +167,11 @@ pub struct PaymentInfo {
167167
pub onchain_address: Address<NetworkUnchecked>,
168168
/// The minimum number of block confirmations that are required for the on-chain payment to be
169169
/// considered confirmed.
170-
pub min_onchain_payment_confirmations: Option<u8>,
170+
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)