Skip to content

Commit bfbc72d

Browse files
committed
EXPERIMENT: Try to use bitcoin::FeeRate
.. at the cost of `from_sat_per_vb`.
1 parent 5c3ea0f commit bfbc72d

File tree

3 files changed

+6
-72
lines changed

3 files changed

+6
-72
lines changed

bindings/ldk_node.udl

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,11 @@ interface OnchainPayment {
169169
interface FeeRate {
170170
[Name=from_sat_per_kwu]
171171
constructor(u64 sat_kwu);
172-
[Name=from_sat_per_vb, Throws=FeeRateError]
173-
constructor(u64 sat_vb);
174172
[Name=from_sat_per_vb_unchecked]
175173
constructor(u64 sat_vb);
176-
u64 as_sat_per_kwu();
177-
u64 as_sat_per_vb_floor();
178-
u64 as_sat_per_vb_ceil();
179-
};
180-
181-
[Error]
182-
enum FeeRateError {
183-
"ConversionError",
174+
u64 to_sat_per_kwu();
175+
u64 to_sat_per_vb_floor();
176+
u64 to_sat_per_vb_ceil();
184177
};
185178

186179
interface UnifiedQrPayment {

src/payment/onchain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::sync::{Arc, RwLock};
2020
#[cfg(not(feature = "uniffi"))]
2121
type FeeRate = bitcoin::FeeRate;
2222
#[cfg(feature = "uniffi")]
23-
type FeeRate = Arc<crate::uniffi_types::FeeRate>;
23+
type FeeRate = Arc<bitcoin::FeeRate>;
2424

2525
macro_rules! maybe_map_fee_rate_opt {
2626
($fee_rate_opt: expr) => {{
@@ -30,7 +30,7 @@ macro_rules! maybe_map_fee_rate_opt {
3030
}
3131
#[cfg(feature = "uniffi")]
3232
{
33-
$fee_rate_opt.map(|f| f.0)
33+
$fee_rate_opt.map(|f| *f)
3434
}
3535
}};
3636
}

src/uniffi_types.rs

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub use lightning_types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
3030

3131
pub use lightning_invoice::Bolt11Invoice;
3232

33-
pub use bitcoin::{Address, BlockHash, Network, OutPoint, Txid};
33+
pub use bitcoin::{Address, BlockHash, FeeRate, Network, OutPoint, Txid};
3434

3535
pub use bip39::Mnemonic;
3636

@@ -51,7 +51,6 @@ use lightning::util::ser::Writeable;
5151
use lightning_invoice::SignedRawBolt11Invoice;
5252

5353
use std::convert::TryInto;
54-
use std::fmt;
5554
use std::str::FromStr;
5655

5756
impl UniffiCustomTypeConverter for PublicKey {
@@ -346,61 +345,3 @@ impl UniffiCustomTypeConverter for NodeAlias {
346345
obj.to_string()
347346
}
348347
}
349-
350-
/// Represents fee rate.
351-
///
352-
/// This is a simple wrapper around [`bitcoin::FeeRate`], only used for UniFFI bindings.
353-
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
354-
pub struct FeeRate(pub(crate) bitcoin::FeeRate);
355-
356-
impl FeeRate {
357-
/// Constructs `FeeRate` from satoshis per 1000 weight units.
358-
pub const fn from_sat_per_kwu(sat_kwu: u64) -> Self {
359-
Self(bitcoin::FeeRate::from_sat_per_kwu(sat_kwu))
360-
}
361-
362-
/// Constructs `FeeRate` from satoshis per virtual bytes.
363-
///
364-
/// # Errors
365-
///
366-
/// Returns [`FeeRateError::ConversionError`] on arithmetic overflow.
367-
pub fn from_sat_per_vb(sat_vb: u64) -> Result<Self, FeeRateError> {
368-
Ok(Self(bitcoin::FeeRate::from_sat_per_vb(sat_vb).ok_or(FeeRateError::ConversionError)?))
369-
}
370-
371-
/// Constructs `FeeRate` from satoshis per virtual bytes without overflow check.
372-
pub const fn from_sat_per_vb_unchecked(sat_vb: u64) -> Self {
373-
Self(bitcoin::FeeRate::from_sat_per_vb_unchecked(sat_vb))
374-
}
375-
376-
/// Returns raw fee rate as satoshis per 1000 weight units.
377-
pub const fn as_sat_per_kwu(&self) -> u64 {
378-
self.0.to_sat_per_kwu()
379-
}
380-
381-
/// Converts to sat/vB rounding down.
382-
pub const fn as_sat_per_vb_floor(&self) -> u64 {
383-
self.0.to_sat_per_vb_floor()
384-
}
385-
386-
/// Converts to sat/vB rounding up.
387-
pub const fn as_sat_per_vb_ceil(self) -> u64 {
388-
self.0.to_sat_per_vb_ceil()
389-
}
390-
}
391-
392-
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
393-
/// A fee rate error that possibly needs to be handled by the user.
394-
pub enum FeeRateError {
395-
ConversionError,
396-
}
397-
398-
impl std::error::Error for FeeRateError {}
399-
400-
impl fmt::Display for FeeRateError {
401-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
402-
match self {
403-
Self::ConversionError => write!(f, "Fee-rate conversion failed."),
404-
}
405-
}
406-
}

0 commit comments

Comments
 (0)