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

Commit

Permalink
Merge pull request #133 from tnull/2024-05-lsps1-switch-u8-to-u16
Browse files Browse the repository at this point in the history
  • Loading branch information
tnull authored May 14, 2024
2 parents 1da2a14 + 90fafd4 commit 0d1a1f6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
23 changes: 23 additions & 0 deletions src/lsps0/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,3 +653,26 @@ pub(crate) mod string_amount_option {
}
}
}

#[cfg(lsps1)]
pub(crate) mod u32_fee_rate {
use bitcoin::FeeRate;
use serde::{Deserialize, Deserializer, Serializer};

pub(crate) fn serialize<S>(x: &FeeRate, s: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let fee_rate_sat_kwu = x.to_sat_per_kwu();
s.serialize_u32(fee_rate_sat_kwu as u32)
}

pub(crate) fn deserialize<'de, D>(deserializer: D) -> Result<FeeRate, D::Error>
where
D: Deserializer<'de>,
{
let fee_rate_sat_kwu = u32::deserialize(deserializer)?;

Ok(FeeRate::from_sat_per_kwu(fee_rate_sat_kwu as u64))
}
}
19 changes: 10 additions & 9 deletions src/lsps1/msgs.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! Message, request, and other primitive types used to implement LSPS1.
use crate::lsps0::ser::{
string_amount, string_amount_option, LSPSMessage, RequestId, ResponseError,
string_amount, string_amount_option, u32_fee_rate, LSPSMessage, RequestId, ResponseError,
};

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

use bitcoin::address::{Address, NetworkUnchecked};
use bitcoin::OutPoint;
use bitcoin::{FeeRate, OutPoint};

use lightning_invoice::Bolt11Invoice;

Expand Down Expand Up @@ -40,11 +40,11 @@ pub struct GetInfoRequest {}
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct OptionsSupported {
/// The smallest number of confirmations needed for the LSP to accept a channel as confirmed.
pub min_required_channel_confirmations: u8,
pub min_required_channel_confirmations: u16,
/// The smallest number of blocks in which the LSP can confirm the funding transaction.
pub min_funding_confirms_within_blocks: u8,
pub min_funding_confirms_within_blocks: u16,
/// The minimum number of block confirmations before the LSP accepts an on-chain payment as confirmed.
pub min_onchain_payment_confirmations: Option<u8>,
pub min_onchain_payment_confirmations: Option<u16>,
/// Indicates if the LSP supports zero reserve.
pub supports_zero_channel_reserve: bool,
/// Indicates the minimum amount of satoshi that is required for the LSP to accept a payment
Expand Down Expand Up @@ -104,9 +104,9 @@ pub struct OrderParams {
#[serde(with = "string_amount")]
pub client_balance_sat: u64,
/// The number of confirmations the funding tx must have before the LSP sends `channel_ready`.
pub required_channel_confirmations: u8,
pub required_channel_confirmations: u16,
/// The maximum number of blocks the client wants to wait until the funding transaction is confirmed.
pub funding_confirms_within_blocks: u8,
pub funding_confirms_within_blocks: u16,
/// Indicates how long the channel is leased for in block time.
pub channel_expiry_blocks: u32,
/// May contain arbitrary associated data like a coupon code or a authentication token.
Expand Down Expand Up @@ -167,10 +167,11 @@ pub struct PaymentInfo {
pub onchain_address: Address<NetworkUnchecked>,
/// The minimum number of block confirmations that are required for the on-chain payment to be
/// considered confirmed.
pub min_onchain_payment_confirmations: Option<u8>,
pub min_onchain_payment_confirmations: Option<u16>,
/// The minimum fee rate for the on-chain payment in case the client wants the payment to be
/// confirmed without a confirmation.
pub min_fee_for_0conf: u8,
#[serde(with = "u32_fee_rate")]
pub min_fee_for_0conf: FeeRate,
/// Details regarding a detected on-chain payment.
pub onchain_payment: Option<OnchainPayment>,
}
Expand Down

0 comments on commit 0d1a1f6

Please sign in to comment.