X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning%2Fchain%2Fchaininterface.rs;h=4c22d5653de2c256247e7b7c04d1d8c2d9e1e1d4;hb=2f70a371708dbfde3fa6abfcc0315736d2795a01;hp=9ba2256e9b915b7ee25ef6a385a34b73ba6cb346;hpb=a82e075188fc15a103234832686915c196bfe240;p=ldk-c-bindings diff --git a/lightning-c-bindings/src/lightning/chain/chaininterface.rs b/lightning-c-bindings/src/lightning/chain/chaininterface.rs index 9ba2256..4c22d56 100644 --- a/lightning-c-bindings/src/lightning/chain/chaininterface.rs +++ b/lightning-c-bindings/src/lightning/chain/chaininterface.rs @@ -12,10 +12,13 @@ //! Includes traits for monitoring and receiving notifications of new blocks and block //! disconnections, transaction broadcasting, and feerate information requests. -use std::str::FromStr; -use std::ffi::c_void; +use alloc::str::FromStr; +use core::ffi::c_void; +use core::convert::Infallible; use bitcoin::hashes::Hash; use crate::c_types::*; +#[cfg(feature="no-std")] +use alloc::{vec::Vec, boxed::Box}; /// An interface to send a transaction to the Bitcoin network. #[repr(C)] @@ -49,7 +52,7 @@ impl rustBroadcasterInterface for BroadcasterInterface { // We're essentially a pointer already, or at least a set of pointers, so allow us to be used // directly as a Deref trait in higher-level structs: -impl std::ops::Deref for BroadcasterInterface { +impl core::ops::Deref for BroadcasterInterface { type Target = Self; fn deref(&self) -> &Self { self @@ -67,8 +70,8 @@ impl Drop for BroadcasterInterface { } /// An enum that represents the speed at which we want a transaction to confirm used for feerate /// estimation. -#[must_use] #[derive(Clone)] +#[must_use] #[repr(C)] pub enum ConfirmationTarget { /// We are happy with this transaction confirming slowly when feerate drops some. @@ -78,7 +81,9 @@ pub enum ConfirmationTarget { /// We'd like this transaction to confirm in the next few blocks. HighPriority, } -use lightning::chain::chaininterface::ConfirmationTarget as nativeConfirmationTarget; +use lightning::chain::chaininterface::ConfirmationTarget as ConfirmationTargetImport; +pub(crate) type nativeConfirmationTarget = ConfirmationTargetImport; + impl ConfirmationTarget { #[allow(unused)] pub(crate) fn to_native(&self) -> nativeConfirmationTarget { @@ -130,6 +135,21 @@ pub extern "C" fn ConfirmationTarget_normal() -> ConfirmationTarget { /// Utility method to constructs a new HighPriority-variant ConfirmationTarget pub extern "C" fn ConfirmationTarget_high_priority() -> ConfirmationTarget { ConfirmationTarget::HighPriority} +/// Checks if two ConfirmationTargets contain equal inner contents. +#[no_mangle] +pub extern "C" fn ConfirmationTarget_hash(o: &ConfirmationTarget) -> u64 { + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(&o.to_native(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} +/// Checks if two ConfirmationTargets contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +#[no_mangle] +pub extern "C" fn ConfirmationTarget_eq(a: &ConfirmationTarget, b: &ConfirmationTarget) -> bool { + if &a.to_native() == &b.to_native() { true } else { false } +} /// A trait which should be implemented to provide feerate information on a number of time /// horizons. /// @@ -142,12 +162,12 @@ pub struct FeeEstimator { pub this_arg: *mut c_void, /// Gets estimated satoshis of fee required per 1000 Weight-Units. /// - /// Must be no smaller than 253 (ie 1 satoshi-per-byte rounded up to ensure later round-downs - /// don't put us below 1 satoshi-per-byte). + /// LDK will wrap this method and ensure that the value returned is no smaller than 253 + /// (ie 1 satoshi-per-byte rounded up to ensure later round-downs don't put us below 1 satoshi-per-byte). /// - /// This translates to: + /// The following unit conversions can be used to convert to sats/KW: /// * satoshis-per-byte * 250 - /// * ceil(satoshis-per-kbyte / 4) + /// * satoshis-per-kbyte / 4 #[must_use] pub get_est_sat_per_1000_weight: extern "C" fn (this_arg: *const c_void, confirmation_target: crate::lightning::chain::chaininterface::ConfirmationTarget) -> u32, /// Frees any resources associated with this object given its this_arg pointer. @@ -175,7 +195,7 @@ impl rustFeeEstimator for FeeEstimator { // We're essentially a pointer already, or at least a set of pointers, so allow us to be used // directly as a Deref trait in higher-level structs: -impl std::ops::Deref for FeeEstimator { +impl core::ops::Deref for FeeEstimator { type Target = Self; fn deref(&self) -> &Self { self @@ -195,3 +215,9 @@ impl Drop for FeeEstimator { #[no_mangle] pub static MIN_RELAY_FEE_SAT_PER_1000_WEIGHT: u64 = lightning::chain::chaininterface::MIN_RELAY_FEE_SAT_PER_1000_WEIGHT; +/// Minimum feerate that takes a sane approach to bitcoind weight-to-vbytes rounding. +/// See the following Core Lightning commit for an explanation: +/// + +#[no_mangle] +pub static FEERATE_FLOOR_SATS_PER_KW: u32 = lightning::chain::chaininterface::FEERATE_FLOOR_SATS_PER_KW;