Skip to content

Commit 671222d

Browse files
committed
Update auto-generated bindings to include ln-transaction-sync
1 parent 9847090 commit 671222d

File tree

8 files changed

+1173
-152
lines changed

8 files changed

+1173
-152
lines changed

lightning-c-bindings/include/ldk_rust_types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,10 @@ struct nativePacketOpaque;
383383
typedef struct nativePacketOpaque LDKnativePacket;
384384
struct nativeClaimedHTLCOpaque;
385385
typedef struct nativeClaimedHTLCOpaque LDKnativeClaimedHTLC;
386+
struct nativeElectrumSyncClientOpaque;
387+
typedef struct nativeElectrumSyncClientOpaque LDKnativeElectrumSyncClient;
388+
struct nativeEsploraSyncClientOpaque;
389+
typedef struct nativeEsploraSyncClientOpaque LDKnativeEsploraSyncClient;
386390
struct nativeBolt11InvoiceOpaque;
387391
typedef struct nativeBolt11InvoiceOpaque LDKnativeBolt11Invoice;
388392
struct nativeSignedRawBolt11InvoiceOpaque;

lightning-c-bindings/include/lightning.h

Lines changed: 388 additions & 110 deletions
Large diffs are not rendered by default.

lightning-c-bindings/include/lightningpp.hpp

Lines changed: 137 additions & 42 deletions
Large diffs are not rendered by default.

lightning-c-bindings/src/c_types/derived.rs

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24030,6 +24030,198 @@ impl Clone for CResult_COption_EventZDecodeErrorZ {
2403024030
/// but with all dynamically-allocated buffers duplicated in new buffers.
2403124031
pub extern "C" fn CResult_COption_EventZDecodeErrorZ_clone(orig: &CResult_COption_EventZDecodeErrorZ) -> CResult_COption_EventZDecodeErrorZ { Clone::clone(&orig) }
2403224032
#[repr(C)]
24033+
/// The contents of CResult_ElectrumSyncClientTxSyncErrorZ
24034+
pub union CResult_ElectrumSyncClientTxSyncErrorZPtr {
24035+
/// A pointer to the contents in the success state.
24036+
/// Reading from this pointer when `result_ok` is not set is undefined.
24037+
pub result: *mut crate::lightning_transaction_sync::electrum::ElectrumSyncClient,
24038+
/// A pointer to the contents in the error state.
24039+
/// Reading from this pointer when `result_ok` is set is undefined.
24040+
pub err: *mut crate::lightning_transaction_sync::error::TxSyncError,
24041+
}
24042+
#[repr(C)]
24043+
/// A CResult_ElectrumSyncClientTxSyncErrorZ represents the result of a fallible operation,
24044+
/// containing a crate::lightning_transaction_sync::electrum::ElectrumSyncClient on success and a crate::lightning_transaction_sync::error::TxSyncError on failure.
24045+
/// `result_ok` indicates the overall state, and the contents are provided via `contents`.
24046+
pub struct CResult_ElectrumSyncClientTxSyncErrorZ {
24047+
/// The contents of this CResult_ElectrumSyncClientTxSyncErrorZ, accessible via either
24048+
/// `err` or `result` depending on the state of `result_ok`.
24049+
pub contents: CResult_ElectrumSyncClientTxSyncErrorZPtr,
24050+
/// Whether this CResult_ElectrumSyncClientTxSyncErrorZ represents a success state.
24051+
pub result_ok: bool,
24052+
}
24053+
#[no_mangle]
24054+
/// Creates a new CResult_ElectrumSyncClientTxSyncErrorZ in the success state.
24055+
pub extern "C" fn CResult_ElectrumSyncClientTxSyncErrorZ_ok(o: crate::lightning_transaction_sync::electrum::ElectrumSyncClient) -> CResult_ElectrumSyncClientTxSyncErrorZ {
24056+
CResult_ElectrumSyncClientTxSyncErrorZ {
24057+
contents: CResult_ElectrumSyncClientTxSyncErrorZPtr {
24058+
result: Box::into_raw(Box::new(o)),
24059+
},
24060+
result_ok: true,
24061+
}
24062+
}
24063+
#[no_mangle]
24064+
/// Creates a new CResult_ElectrumSyncClientTxSyncErrorZ in the error state.
24065+
pub extern "C" fn CResult_ElectrumSyncClientTxSyncErrorZ_err(e: crate::lightning_transaction_sync::error::TxSyncError) -> CResult_ElectrumSyncClientTxSyncErrorZ {
24066+
CResult_ElectrumSyncClientTxSyncErrorZ {
24067+
contents: CResult_ElectrumSyncClientTxSyncErrorZPtr {
24068+
err: Box::into_raw(Box::new(e)),
24069+
},
24070+
result_ok: false,
24071+
}
24072+
}
24073+
/// Checks if the given object is currently in the success state
24074+
#[no_mangle]
24075+
pub extern "C" fn CResult_ElectrumSyncClientTxSyncErrorZ_is_ok(o: &CResult_ElectrumSyncClientTxSyncErrorZ) -> bool {
24076+
o.result_ok
24077+
}
24078+
#[no_mangle]
24079+
/// Frees any resources used by the CResult_ElectrumSyncClientTxSyncErrorZ.
24080+
pub extern "C" fn CResult_ElectrumSyncClientTxSyncErrorZ_free(_res: CResult_ElectrumSyncClientTxSyncErrorZ) { }
24081+
impl Drop for CResult_ElectrumSyncClientTxSyncErrorZ {
24082+
fn drop(&mut self) {
24083+
if self.result_ok {
24084+
if unsafe { !(self.contents.result as *mut ()).is_null() } {
24085+
let _ = unsafe { Box::from_raw(self.contents.result) };
24086+
}
24087+
} else {
24088+
if unsafe { !(self.contents.err as *mut ()).is_null() } {
24089+
let _ = unsafe { Box::from_raw(self.contents.err) };
24090+
}
24091+
}
24092+
}
24093+
}
24094+
impl From<crate::c_types::CResultTempl<crate::lightning_transaction_sync::electrum::ElectrumSyncClient, crate::lightning_transaction_sync::error::TxSyncError>> for CResult_ElectrumSyncClientTxSyncErrorZ {
24095+
fn from(mut o: crate::c_types::CResultTempl<crate::lightning_transaction_sync::electrum::ElectrumSyncClient, crate::lightning_transaction_sync::error::TxSyncError>) -> Self {
24096+
let contents = if o.result_ok {
24097+
let result = unsafe { o.contents.result };
24098+
unsafe { o.contents.result = core::ptr::null_mut() };
24099+
CResult_ElectrumSyncClientTxSyncErrorZPtr { result }
24100+
} else {
24101+
let err = unsafe { o.contents.err };
24102+
unsafe { o.contents.err = core::ptr::null_mut(); }
24103+
CResult_ElectrumSyncClientTxSyncErrorZPtr { err }
24104+
};
24105+
Self {
24106+
contents,
24107+
result_ok: o.result_ok,
24108+
}
24109+
}
24110+
}
24111+
#[repr(C)]
24112+
/// A dynamically-allocated array of crate::lightning::chain::Confirms of arbitrary size.
24113+
/// This corresponds to std::vector in C++
24114+
pub struct CVec_ConfirmZ {
24115+
/// The elements in the array.
24116+
/// If datalen is non-0 this must be a valid, non-NULL pointer allocated by malloc().
24117+
pub data: *mut crate::lightning::chain::Confirm,
24118+
/// The number of elements pointed to by `data`.
24119+
pub datalen: usize
24120+
}
24121+
impl CVec_ConfirmZ {
24122+
#[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec<crate::lightning::chain::Confirm> {
24123+
if self.datalen == 0 { return Vec::new(); }
24124+
let ret = unsafe { Box::from_raw(core::slice::from_raw_parts_mut(self.data, self.datalen)) }.into();
24125+
self.data = core::ptr::null_mut();
24126+
self.datalen = 0;
24127+
ret
24128+
}
24129+
#[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::lightning::chain::Confirm] {
24130+
unsafe { core::slice::from_raw_parts_mut(self.data, self.datalen) }
24131+
}
24132+
}
24133+
impl From<Vec<crate::lightning::chain::Confirm>> for CVec_ConfirmZ {
24134+
fn from(v: Vec<crate::lightning::chain::Confirm>) -> Self {
24135+
let datalen = v.len();
24136+
let data = Box::into_raw(v.into_boxed_slice());
24137+
Self { datalen, data: unsafe { (*data).as_mut_ptr() } }
24138+
}
24139+
}
24140+
#[no_mangle]
24141+
/// Frees the buffer pointed to by `data` if `datalen` is non-0.
24142+
pub extern "C" fn CVec_ConfirmZ_free(_res: CVec_ConfirmZ) { }
24143+
impl Drop for CVec_ConfirmZ {
24144+
fn drop(&mut self) {
24145+
if self.datalen == 0 { return; }
24146+
let _ = unsafe { Box::from_raw(core::slice::from_raw_parts_mut(self.data, self.datalen)) };
24147+
}
24148+
}
24149+
#[repr(C)]
24150+
/// The contents of CResult_NoneTxSyncErrorZ
24151+
pub union CResult_NoneTxSyncErrorZPtr {
24152+
/// Note that this value is always NULL, as there are no contents in the OK variant
24153+
pub result: *mut core::ffi::c_void,
24154+
/// A pointer to the contents in the error state.
24155+
/// Reading from this pointer when `result_ok` is set is undefined.
24156+
pub err: *mut crate::lightning_transaction_sync::error::TxSyncError,
24157+
}
24158+
#[repr(C)]
24159+
/// A CResult_NoneTxSyncErrorZ represents the result of a fallible operation,
24160+
/// containing a () on success and a crate::lightning_transaction_sync::error::TxSyncError on failure.
24161+
/// `result_ok` indicates the overall state, and the contents are provided via `contents`.
24162+
pub struct CResult_NoneTxSyncErrorZ {
24163+
/// The contents of this CResult_NoneTxSyncErrorZ, accessible via either
24164+
/// `err` or `result` depending on the state of `result_ok`.
24165+
pub contents: CResult_NoneTxSyncErrorZPtr,
24166+
/// Whether this CResult_NoneTxSyncErrorZ represents a success state.
24167+
pub result_ok: bool,
24168+
}
24169+
#[no_mangle]
24170+
/// Creates a new CResult_NoneTxSyncErrorZ in the success state.
24171+
pub extern "C" fn CResult_NoneTxSyncErrorZ_ok() -> CResult_NoneTxSyncErrorZ {
24172+
CResult_NoneTxSyncErrorZ {
24173+
contents: CResult_NoneTxSyncErrorZPtr {
24174+
result: core::ptr::null_mut(),
24175+
},
24176+
result_ok: true,
24177+
}
24178+
}
24179+
#[no_mangle]
24180+
/// Creates a new CResult_NoneTxSyncErrorZ in the error state.
24181+
pub extern "C" fn CResult_NoneTxSyncErrorZ_err(e: crate::lightning_transaction_sync::error::TxSyncError) -> CResult_NoneTxSyncErrorZ {
24182+
CResult_NoneTxSyncErrorZ {
24183+
contents: CResult_NoneTxSyncErrorZPtr {
24184+
err: Box::into_raw(Box::new(e)),
24185+
},
24186+
result_ok: false,
24187+
}
24188+
}
24189+
/// Checks if the given object is currently in the success state
24190+
#[no_mangle]
24191+
pub extern "C" fn CResult_NoneTxSyncErrorZ_is_ok(o: &CResult_NoneTxSyncErrorZ) -> bool {
24192+
o.result_ok
24193+
}
24194+
#[no_mangle]
24195+
/// Frees any resources used by the CResult_NoneTxSyncErrorZ.
24196+
pub extern "C" fn CResult_NoneTxSyncErrorZ_free(_res: CResult_NoneTxSyncErrorZ) { }
24197+
impl Drop for CResult_NoneTxSyncErrorZ {
24198+
fn drop(&mut self) {
24199+
if self.result_ok {
24200+
} else {
24201+
if unsafe { !(self.contents.err as *mut ()).is_null() } {
24202+
let _ = unsafe { Box::from_raw(self.contents.err) };
24203+
}
24204+
}
24205+
}
24206+
}
24207+
impl From<crate::c_types::CResultTempl<(), crate::lightning_transaction_sync::error::TxSyncError>> for CResult_NoneTxSyncErrorZ {
24208+
fn from(mut o: crate::c_types::CResultTempl<(), crate::lightning_transaction_sync::error::TxSyncError>) -> Self {
24209+
let contents = if o.result_ok {
24210+
let _ = unsafe { Box::from_raw(o.contents.result) };
24211+
o.contents.result = core::ptr::null_mut();
24212+
CResult_NoneTxSyncErrorZPtr { result: core::ptr::null_mut() }
24213+
} else {
24214+
let err = unsafe { o.contents.err };
24215+
unsafe { o.contents.err = core::ptr::null_mut(); }
24216+
CResult_NoneTxSyncErrorZPtr { err }
24217+
};
24218+
Self {
24219+
contents,
24220+
result_ok: o.result_ok,
24221+
}
24222+
}
24223+
}
24224+
#[repr(C)]
2403324225
/// The contents of CResult_SiPrefixBolt11ParseErrorZ
2403424226
pub union CResult_SiPrefixBolt11ParseErrorZPtr {
2403524227
/// A pointer to the contents in the success state.
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
// This file is Copyright its original authors, visible in version control
2+
// history and in the source files from which this was generated.
3+
//
4+
// This file is licensed under the license available in the LICENSE or LICENSE.md
5+
// file in the root of this repository or, if no such file exists, the same
6+
// license as that which applies to the original source files from which this
7+
// source was automatically generated.
8+
9+
//! Chain sync using the electrum protocol
10+
11+
use alloc::str::FromStr;
12+
use alloc::string::String;
13+
use core::ffi::c_void;
14+
use core::convert::Infallible;
15+
use bitcoin::hashes::Hash;
16+
use crate::c_types::*;
17+
#[cfg(feature="no-std")]
18+
use alloc::{vec::Vec, boxed::Box};
19+
20+
21+
use lightning_transaction_sync::electrum::ElectrumSyncClient as nativeElectrumSyncClientImport;
22+
pub(crate) type nativeElectrumSyncClient = nativeElectrumSyncClientImport<crate::lightning::util::logger::Logger, >;
23+
24+
/// Synchronizes LDK with a given Electrum server.
25+
///
26+
/// Needs to be registered with a [`ChainMonitor`] via the [`Filter`] interface to be informed of
27+
/// transactions and outputs to monitor for on-chain confirmation, unconfirmation, and
28+
/// reconfirmation.
29+
///
30+
/// Note that registration via [`Filter`] needs to happen before any calls to
31+
/// [`Watch::watch_channel`] to ensure we get notified of the items to monitor.
32+
///
33+
/// [`ChainMonitor`]: lightning::chain::chainmonitor::ChainMonitor
34+
/// [`Watch::watch_channel`]: lightning::chain::Watch::watch_channel
35+
/// [`Filter`]: lightning::chain::Filter
36+
#[must_use]
37+
#[repr(C)]
38+
pub struct ElectrumSyncClient {
39+
/// A pointer to the opaque Rust object.
40+
41+
/// Nearly everywhere, inner must be non-null, however in places where
42+
/// the Rust equivalent takes an Option, it may be set to null to indicate None.
43+
pub inner: *mut nativeElectrumSyncClient,
44+
/// Indicates that this is the only struct which contains the same pointer.
45+
46+
/// Rust functions which take ownership of an object provided via an argument require
47+
/// this to be true and invalidate the object pointed to by inner.
48+
pub is_owned: bool,
49+
}
50+
51+
impl Drop for ElectrumSyncClient {
52+
fn drop(&mut self) {
53+
if self.is_owned && !<*mut nativeElectrumSyncClient>::is_null(self.inner) {
54+
let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
55+
}
56+
}
57+
}
58+
/// Frees any resources used by the ElectrumSyncClient, if is_owned is set and inner is non-NULL.
59+
#[no_mangle]
60+
pub extern "C" fn ElectrumSyncClient_free(this_obj: ElectrumSyncClient) { }
61+
#[allow(unused)]
62+
/// Used only if an object of this type is returned as a trait impl by a method
63+
pub(crate) extern "C" fn ElectrumSyncClient_free_void(this_ptr: *mut c_void) {
64+
let _ = unsafe { Box::from_raw(this_ptr as *mut nativeElectrumSyncClient) };
65+
}
66+
#[allow(unused)]
67+
impl ElectrumSyncClient {
68+
pub(crate) fn get_native_ref(&self) -> &'static nativeElectrumSyncClient {
69+
unsafe { &*ObjOps::untweak_ptr(self.inner) }
70+
}
71+
pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeElectrumSyncClient {
72+
unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
73+
}
74+
/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
75+
pub(crate) fn take_inner(mut self) -> *mut nativeElectrumSyncClient {
76+
assert!(self.is_owned);
77+
let ret = ObjOps::untweak_ptr(self.inner);
78+
self.inner = core::ptr::null_mut();
79+
ret
80+
}
81+
}
82+
/// Returns a new [`ElectrumSyncClient`] object.
83+
#[must_use]
84+
#[no_mangle]
85+
pub extern "C" fn ElectrumSyncClient_new(mut server_url: crate::c_types::Str, mut logger: crate::lightning::util::logger::Logger) -> crate::c_types::derived::CResult_ElectrumSyncClientTxSyncErrorZ {
86+
let mut ret = lightning_transaction_sync::electrum::ElectrumSyncClient::new(server_url.into_string(), logger);
87+
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_transaction_sync::electrum::ElectrumSyncClient { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_transaction_sync::error::TxSyncError::native_into(e) }).into() };
88+
local_ret
89+
}
90+
91+
/// Synchronizes the given `confirmables` via their [`Confirm`] interface implementations. This
92+
/// method should be called regularly to keep LDK up-to-date with current chain data.
93+
///
94+
/// For example, instances of [`ChannelManager`] and [`ChainMonitor`] can be informed about the
95+
/// newest on-chain activity related to the items previously registered via the [`Filter`]
96+
/// interface.
97+
///
98+
/// [`Confirm`]: lightning::chain::Confirm
99+
/// [`ChainMonitor`]: lightning::chain::chainmonitor::ChainMonitor
100+
/// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager
101+
/// [`Filter`]: lightning::chain::Filter
102+
#[must_use]
103+
#[no_mangle]
104+
pub extern "C" fn ElectrumSyncClient_sync(this_arg: &crate::lightning_transaction_sync::electrum::ElectrumSyncClient, mut confirmables: crate::c_types::derived::CVec_ConfirmZ) -> crate::c_types::derived::CResult_NoneTxSyncErrorZ {
105+
let mut local_confirmables = Vec::new(); for mut item in confirmables.into_rust().drain(..) { local_confirmables.push( { item }); };
106+
let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.sync(local_confirmables);
107+
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_transaction_sync::error::TxSyncError::native_into(e) }).into() };
108+
local_ret
109+
}
110+
111+
impl From<nativeElectrumSyncClient> for crate::lightning::chain::Filter {
112+
fn from(obj: nativeElectrumSyncClient) -> Self {
113+
let rust_obj = crate::lightning_transaction_sync::electrum::ElectrumSyncClient { inner: ObjOps::heap_alloc(obj), is_owned: true };
114+
let mut ret = ElectrumSyncClient_as_Filter(&rust_obj);
115+
// We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
116+
core::mem::forget(rust_obj);
117+
ret.free = Some(ElectrumSyncClient_free_void);
118+
ret
119+
}
120+
}
121+
/// Constructs a new Filter which calls the relevant methods on this_arg.
122+
/// This copies the `inner` pointer in this_arg and thus the returned Filter must be freed before this_arg is
123+
#[no_mangle]
124+
pub extern "C" fn ElectrumSyncClient_as_Filter(this_arg: &ElectrumSyncClient) -> crate::lightning::chain::Filter {
125+
crate::lightning::chain::Filter {
126+
this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
127+
free: None,
128+
register_tx: ElectrumSyncClient_Filter_register_tx,
129+
register_output: ElectrumSyncClient_Filter_register_output,
130+
}
131+
}
132+
133+
extern "C" fn ElectrumSyncClient_Filter_register_tx(this_arg: *const c_void, txid: *const [u8; 32], mut script_pubkey: crate::c_types::u8slice) {
134+
<nativeElectrumSyncClient as lightning::chain::Filter>::register_tx(unsafe { &mut *(this_arg as *mut nativeElectrumSyncClient) }, &::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap(), ::bitcoin::blockdata::script::Script::from_bytes(script_pubkey.to_slice()))
135+
}
136+
extern "C" fn ElectrumSyncClient_Filter_register_output(this_arg: *const c_void, mut output: crate::lightning::chain::WatchedOutput) {
137+
<nativeElectrumSyncClient as lightning::chain::Filter>::register_output(unsafe { &mut *(this_arg as *mut nativeElectrumSyncClient) }, *unsafe { Box::from_raw(output.take_inner()) })
138+
}
139+

0 commit comments

Comments
 (0)