]> git.bitcoin.ninja Git - ldk-c-bindings/blobdiff - lightning-c-bindings/src/lightning/routing/utxo.rs
Add missing `rustc` `metadata` override for `lightning_types`
[ldk-c-bindings] / lightning-c-bindings / src / lightning / routing / utxo.rs
index 187badd8629479e12a50ead78002b053b00bb354..517d633b35d5302a3bba16912f96a073c0a02b7a 100644 (file)
@@ -50,7 +50,8 @@ impl UtxoLookupError {
                }
        }
        #[allow(unused)]
                }
        }
        #[allow(unused)]
-       pub(crate) fn from_native(native: &nativeUtxoLookupError) -> Self {
+       pub(crate) fn from_native(native: &UtxoLookupErrorImport) -> Self {
+               let native = unsafe { &*(native as *const _ as *const c_void as *const nativeUtxoLookupError) };
                match native {
                        nativeUtxoLookupError::UnknownChain => UtxoLookupError::UnknownChain,
                        nativeUtxoLookupError::UnknownTx => UtxoLookupError::UnknownTx,
                match native {
                        nativeUtxoLookupError::UnknownChain => UtxoLookupError::UnknownChain,
                        nativeUtxoLookupError::UnknownTx => UtxoLookupError::UnknownTx,
@@ -69,6 +70,16 @@ impl UtxoLookupError {
 pub extern "C" fn UtxoLookupError_clone(orig: &UtxoLookupError) -> UtxoLookupError {
        orig.clone()
 }
 pub extern "C" fn UtxoLookupError_clone(orig: &UtxoLookupError) -> UtxoLookupError {
        orig.clone()
 }
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn UtxoLookupError_clone_void(this_ptr: *const c_void) -> *mut c_void {
+       Box::into_raw(Box::new(unsafe { (*(this_ptr as *const UtxoLookupError)).clone() })) as *mut c_void
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn UtxoLookupError_free_void(this_ptr: *mut c_void) {
+       let _ = unsafe { Box::from_raw(this_ptr as *mut UtxoLookupError) };
+}
 #[no_mangle]
 /// Utility method to constructs a new UnknownChain-variant UtxoLookupError
 pub extern "C" fn UtxoLookupError_unknown_chain() -> UtxoLookupError {
 #[no_mangle]
 /// Utility method to constructs a new UnknownChain-variant UtxoLookupError
 pub extern "C" fn UtxoLookupError_unknown_chain() -> UtxoLookupError {
@@ -77,6 +88,9 @@ pub extern "C" fn UtxoLookupError_unknown_chain() -> UtxoLookupError {
 /// Utility method to constructs a new UnknownTx-variant UtxoLookupError
 pub extern "C" fn UtxoLookupError_unknown_tx() -> UtxoLookupError {
        UtxoLookupError::UnknownTx}
 /// Utility method to constructs a new UnknownTx-variant UtxoLookupError
 pub extern "C" fn UtxoLookupError_unknown_tx() -> UtxoLookupError {
        UtxoLookupError::UnknownTx}
+/// Get a string which allows debug introspection of a UtxoLookupError object
+pub extern "C" fn UtxoLookupError_debug_str_void(o: *const c_void) -> Str {
+       alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::utxo::UtxoLookupError }).into()}
 /// The result of a [`UtxoLookup::get_utxo`] call. A call may resolve either synchronously,
 /// returning the `Sync` variant, or asynchronously, returning an [`UtxoFuture`] in the `Async`
 /// variant.
 /// The result of a [`UtxoLookup::get_utxo`] call. A call may resolve either synchronously,
 /// returning the `Sync` variant, or asynchronously, returning an [`UtxoFuture`] in the `Async`
 /// variant.
@@ -137,7 +151,8 @@ impl UtxoResult {
                }
        }
        #[allow(unused)]
                }
        }
        #[allow(unused)]
-       pub(crate) fn from_native(native: &nativeUtxoResult) -> Self {
+       pub(crate) fn from_native(native: &UtxoResultImport) -> Self {
+               let native = unsafe { &*(native as *const _ as *const c_void as *const nativeUtxoResult) };
                match native {
                        nativeUtxoResult::Sync (ref a, ) => {
                                let mut a_nonref = Clone::clone(a);
                match native {
                        nativeUtxoResult::Sync (ref a, ) => {
                                let mut a_nonref = Clone::clone(a);
@@ -179,6 +194,16 @@ pub extern "C" fn UtxoResult_free(this_ptr: UtxoResult) { }
 pub extern "C" fn UtxoResult_clone(orig: &UtxoResult) -> UtxoResult {
        orig.clone()
 }
 pub extern "C" fn UtxoResult_clone(orig: &UtxoResult) -> UtxoResult {
        orig.clone()
 }
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn UtxoResult_clone_void(this_ptr: *const c_void) -> *mut c_void {
+       Box::into_raw(Box::new(unsafe { (*(this_ptr as *const UtxoResult)).clone() })) as *mut c_void
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn UtxoResult_free_void(this_ptr: *mut c_void) {
+       let _ = unsafe { Box::from_raw(this_ptr as *mut UtxoResult) };
+}
 #[no_mangle]
 /// Utility method to constructs a new Sync-variant UtxoResult
 pub extern "C" fn UtxoResult_sync(a: crate::c_types::derived::CResult_TxOutUtxoLookupErrorZ) -> UtxoResult {
 #[no_mangle]
 /// Utility method to constructs a new Sync-variant UtxoResult
 pub extern "C" fn UtxoResult_sync(a: crate::c_types::derived::CResult_TxOutUtxoLookupErrorZ) -> UtxoResult {
@@ -196,17 +221,18 @@ pub struct UtxoLookup {
        /// This has no meaning in the LDK, and can be NULL or any other value.
        pub this_arg: *mut c_void,
        /// Returns the transaction output of a funding transaction encoded by [`short_channel_id`].
        /// This has no meaning in the LDK, and can be NULL or any other value.
        pub this_arg: *mut c_void,
        /// Returns the transaction output of a funding transaction encoded by [`short_channel_id`].
-       /// Returns an error if `genesis_hash` is for a different chain or if such a transaction output
-       /// is unknown.
+       /// Returns an error if `chain_hash` is for a different chain or if such a transaction output is
+       /// unknown.
        ///
        /// [`short_channel_id`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#definition-of-short_channel_id
        ///
        /// [`short_channel_id`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#definition-of-short_channel_id
-       pub get_utxo: extern "C" fn (this_arg: *const c_void, genesis_hash: *const [u8; 32], short_channel_id: u64) -> crate::lightning::routing::utxo::UtxoResult,
+       pub get_utxo: extern "C" fn (this_arg: *const c_void, chain_hash: *const [u8; 32], short_channel_id: u64) -> crate::lightning::routing::utxo::UtxoResult,
        /// Frees any resources associated with this object given its this_arg pointer.
        /// 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<extern "C" fn(this_arg: *mut c_void)>,
 }
 unsafe impl Send for UtxoLookup {}
 unsafe impl Sync for UtxoLookup {}
        /// Frees any resources associated with this object given its this_arg pointer.
        /// 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<extern "C" fn(this_arg: *mut c_void)>,
 }
 unsafe impl Send for UtxoLookup {}
 unsafe impl Sync for UtxoLookup {}
+#[allow(unused)]
 pub(crate) fn UtxoLookup_clone_fields(orig: &UtxoLookup) -> UtxoLookup {
        UtxoLookup {
                this_arg: orig.this_arg,
 pub(crate) fn UtxoLookup_clone_fields(orig: &UtxoLookup) -> UtxoLookup {
        UtxoLookup {
                this_arg: orig.this_arg,
@@ -217,8 +243,16 @@ pub(crate) fn UtxoLookup_clone_fields(orig: &UtxoLookup) -> UtxoLookup {
 
 use lightning::routing::utxo::UtxoLookup as rustUtxoLookup;
 impl rustUtxoLookup for UtxoLookup {
 
 use lightning::routing::utxo::UtxoLookup as rustUtxoLookup;
 impl rustUtxoLookup for UtxoLookup {
-       fn get_utxo(&self, mut genesis_hash: &bitcoin::BlockHash, mut short_channel_id: u64) -> lightning::routing::utxo::UtxoResult {
-               let mut ret = (self.get_utxo)(self.this_arg, genesis_hash.as_inner(), short_channel_id);
+       fn get_utxo(&self, mut chain_hash: &bitcoin::constants::ChainHash, mut short_channel_id: u64) -> lightning::routing::utxo::UtxoResult {
+               let mut ret = (self.get_utxo)(self.this_arg, chain_hash.as_ref(), short_channel_id);
+               ret.into_native()
+       }
+}
+
+pub struct UtxoLookupRef(UtxoLookup);
+impl rustUtxoLookup for UtxoLookupRef {
+       fn get_utxo(&self, mut chain_hash: &bitcoin::constants::ChainHash, mut short_channel_id: u64) -> lightning::routing::utxo::UtxoResult {
+               let mut ret = (self.0.get_utxo)(self.0.this_arg, chain_hash.as_ref(), short_channel_id);
                ret.into_native()
        }
 }
                ret.into_native()
        }
 }
@@ -226,14 +260,14 @@ impl rustUtxoLookup for UtxoLookup {
 // 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 core::ops::Deref for UtxoLookup {
 // 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 core::ops::Deref for UtxoLookup {
-       type Target = Self;
-       fn deref(&self) -> &Self {
-               self
+       type Target = UtxoLookupRef;
+       fn deref(&self) -> &Self::Target {
+               unsafe { &*(self as *const _ as *const UtxoLookupRef) }
        }
 }
 impl core::ops::DerefMut for UtxoLookup {
        }
 }
 impl core::ops::DerefMut for UtxoLookup {
-       fn deref_mut(&mut self) -> &mut Self {
-               self
+       fn deref_mut(&mut self) -> &mut UtxoLookupRef {
+               unsafe { &mut *(self as *mut _ as *mut UtxoLookupRef) }
        }
 }
 /// Calls the free function if one is set
        }
 }
 /// Calls the free function if one is set
@@ -268,6 +302,12 @@ pub struct UtxoFuture {
        pub is_owned: bool,
 }
 
        pub is_owned: bool,
 }
 
+impl core::ops::Deref for UtxoFuture {
+       type Target = nativeUtxoFuture;
+       fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } }
+}
+unsafe impl core::marker::Send for UtxoFuture { }
+unsafe impl core::marker::Sync for UtxoFuture { }
 impl Drop for UtxoFuture {
        fn drop(&mut self) {
                if self.is_owned && !<*mut nativeUtxoFuture>::is_null(self.inner) {
 impl Drop for UtxoFuture {
        fn drop(&mut self) {
                if self.is_owned && !<*mut nativeUtxoFuture>::is_null(self.inner) {
@@ -298,6 +338,9 @@ impl UtxoFuture {
                self.inner = core::ptr::null_mut();
                ret
        }
                self.inner = core::ptr::null_mut();
                ret
        }
+       pub(crate) fn as_ref_to(&self) -> Self {
+               Self { inner: self.inner, is_owned: false }
+       }
 }
 impl Clone for UtxoFuture {
        fn clone(&self) -> Self {
 }
 impl Clone for UtxoFuture {
        fn clone(&self) -> Self {
@@ -311,7 +354,7 @@ impl Clone for UtxoFuture {
 #[allow(unused)]
 /// Used only if an object of this type is returned as a trait impl by a method
 pub(crate) extern "C" fn UtxoFuture_clone_void(this_ptr: *const c_void) -> *mut c_void {
 #[allow(unused)]
 /// Used only if an object of this type is returned as a trait impl by a method
 pub(crate) extern "C" fn UtxoFuture_clone_void(this_ptr: *const c_void) -> *mut c_void {
-       Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUtxoFuture)).clone() })) as *mut c_void
+       Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeUtxoFuture)).clone() })) as *mut c_void
 }
 #[no_mangle]
 /// Creates a copy of the UtxoFuture
 }
 #[no_mangle]
 /// Creates a copy of the UtxoFuture