X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-c-bindings;a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning%2Fchain%2Fchaininterface.rs;h=9ba2256e9b915b7ee25ef6a385a34b73ba6cb346;hp=9b8e84b105e22e160ebe75a1bb5bec63aa82bbbc;hb=2f0c348c6fe505a736c3d015df6d6cd30032c912;hpb=d9866e870bbe080412dc70b1421e28a756e4407e diff --git a/lightning-c-bindings/src/lightning/chain/chaininterface.rs b/lightning-c-bindings/src/lightning/chain/chaininterface.rs index 9b8e84b..9ba2256 100644 --- a/lightning-c-bindings/src/lightning/chain/chaininterface.rs +++ b/lightning-c-bindings/src/lightning/chain/chaininterface.rs @@ -12,6 +12,7 @@ //! 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 bitcoin::hashes::Hash; use crate::c_types::*; @@ -28,14 +29,21 @@ pub struct BroadcasterInterface { /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. pub free: Option, } -unsafe impl Sync for BroadcasterInterface {} unsafe impl Send for BroadcasterInterface {} +unsafe impl Sync for BroadcasterInterface {} +#[no_mangle] +pub(crate) extern "C" fn BroadcasterInterface_clone_fields(orig: &BroadcasterInterface) -> BroadcasterInterface { + BroadcasterInterface { + this_arg: orig.this_arg, + broadcast_transaction: Clone::clone(&orig.broadcast_transaction), + free: Clone::clone(&orig.free), + } +} use lightning::chain::chaininterface::BroadcasterInterface as rustBroadcasterInterface; impl rustBroadcasterInterface for BroadcasterInterface { - fn broadcast_transaction(&self, tx: &bitcoin::blockdata::transaction::Transaction) { - let mut local_tx = ::bitcoin::consensus::encode::serialize(tx); - (self.broadcast_transaction)(self.this_arg, crate::c_types::Transaction::from_vec(local_tx)) + fn broadcast_transaction(&self, mut tx: &bitcoin::blockdata::transaction::Transaction) { + (self.broadcast_transaction)(self.this_arg, crate::c_types::Transaction::from_bitcoin(tx)) } } @@ -110,6 +118,18 @@ impl ConfirmationTarget { pub extern "C" fn ConfirmationTarget_clone(orig: &ConfirmationTarget) -> ConfirmationTarget { orig.clone() } +#[no_mangle] +/// Utility method to constructs a new Background-variant ConfirmationTarget +pub extern "C" fn ConfirmationTarget_background() -> ConfirmationTarget { + ConfirmationTarget::Background} +#[no_mangle] +/// Utility method to constructs a new Normal-variant ConfirmationTarget +pub extern "C" fn ConfirmationTarget_normal() -> ConfirmationTarget { + ConfirmationTarget::Normal} +#[no_mangle] +/// Utility method to constructs a new HighPriority-variant ConfirmationTarget +pub extern "C" fn ConfirmationTarget_high_priority() -> ConfirmationTarget { + ConfirmationTarget::HighPriority} /// A trait which should be implemented to provide feerate information on a number of time /// horizons. /// @@ -134,12 +154,20 @@ pub struct FeeEstimator { /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. pub free: Option, } -unsafe impl Sync for FeeEstimator {} unsafe impl Send for FeeEstimator {} +unsafe impl Sync for FeeEstimator {} +#[no_mangle] +pub(crate) extern "C" fn FeeEstimator_clone_fields(orig: &FeeEstimator) -> FeeEstimator { + FeeEstimator { + this_arg: orig.this_arg, + get_est_sat_per_1000_weight: Clone::clone(&orig.get_est_sat_per_1000_weight), + free: Clone::clone(&orig.free), + } +} use lightning::chain::chaininterface::FeeEstimator as rustFeeEstimator; impl rustFeeEstimator for FeeEstimator { - fn get_est_sat_per_1000_weight(&self, confirmation_target: lightning::chain::chaininterface::ConfirmationTarget) -> u32 { + fn get_est_sat_per_1000_weight(&self, mut confirmation_target: lightning::chain::chaininterface::ConfirmationTarget) -> u32 { let mut ret = (self.get_est_sat_per_1000_weight)(self.this_arg, crate::lightning::chain::chaininterface::ConfirmationTarget::native_into(confirmation_target)); ret }