Skip to content

Commit ccd4a7a

Browse files
committed
Update auto-generated bindings with new NetworkGraph API
1 parent 3b6f7f1 commit ccd4a7a

File tree

4 files changed

+199
-14
lines changed

4 files changed

+199
-14
lines changed

lightning-c-bindings/include/lightning.h

Lines changed: 89 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,32 @@ typedef struct LDKC2TupleTempl_HTLCOutputInCommitment__Signature {
586586

587587
typedef LDKC2TupleTempl_HTLCOutputInCommitment__Signature LDKC2Tuple_HTLCOutputInCommitmentSignatureZ;
588588

589+
590+
591+
/**
592+
* An Err type for failure to process messages.
593+
*/
594+
typedef struct MUST_USE_STRUCT LDKLightningError {
595+
/**
596+
* Nearly everywhere, inner must be non-null, however in places where
597+
* the Rust equivalent takes an Option, it may be set to null to indicate None.
598+
*/
599+
LDKnativeLightningError *inner;
600+
bool is_owned;
601+
} LDKLightningError;
602+
603+
typedef union LDKCResultPtr_u8__LightningError {
604+
uint8_t *result;
605+
LDKLightningError *err;
606+
} LDKCResultPtr_u8__LightningError;
607+
608+
typedef struct LDKCResultTempl_u8__LightningError {
609+
LDKCResultPtr_u8__LightningError contents;
610+
bool result_ok;
611+
} LDKCResultTempl_u8__LightningError;
612+
613+
typedef LDKCResultTempl_u8__LightningError LDKCResult_NoneLightningErrorZ;
614+
589615
typedef struct LDKPublicKey {
590616
uint8_t compressed_form[33];
591617
} LDKPublicKey;
@@ -2641,20 +2667,6 @@ typedef struct MUST_USE_STRUCT LDKGossipTimestampFilter {
26412667
bool is_owned;
26422668
} LDKGossipTimestampFilter;
26432669

2644-
2645-
2646-
/**
2647-
* An Err type for failure to process messages.
2648-
*/
2649-
typedef struct MUST_USE_STRUCT LDKLightningError {
2650-
/**
2651-
* Nearly everywhere, inner must be non-null, however in places where
2652-
* the Rust equivalent takes an Option, it may be set to null to indicate None.
2653-
*/
2654-
LDKnativeLightningError *inner;
2655-
bool is_owned;
2656-
} LDKLightningError;
2657-
26582670
typedef struct LDKCVecTempl_UpdateAddHTLC {
26592671
LDKUpdateAddHTLC *data;
26602672
uintptr_t datalen;
@@ -3153,6 +3165,10 @@ extern const LDKCResult_NoneChannelMonitorUpdateErrZ (*CResult_NoneChannelMonito
31533165

31543166
extern const void (*CResult_NoneChannelMonitorUpdateErrZ_free)(LDKCResult_NoneChannelMonitorUpdateErrZ);
31553167

3168+
extern const LDKCResult_NoneLightningErrorZ (*CResult_NoneLightningErrorZ_err)(LDKLightningError);
3169+
3170+
extern const void (*CResult_NoneLightningErrorZ_free)(LDKCResult_NoneLightningErrorZ);
3171+
31563172
extern const LDKCResult_NoneMonitorUpdateErrorZ (*CResult_NoneMonitorUpdateErrorZ_err)(LDKMonitorUpdateError);
31573173

31583174
extern const void (*CResult_NoneMonitorUpdateErrorZ_free)(LDKCResult_NoneMonitorUpdateErrorZ);
@@ -3301,6 +3317,8 @@ LDKCResult_NonePeerHandleErrorZ CResult_NonePeerHandleErrorZ_ok(void);
33013317

33023318
LDKC2Tuple_HTLCOutputInCommitmentSignatureZ C2Tuple_HTLCOutputInCommitmentSignatureZ_new(LDKHTLCOutputInCommitment a, LDKSignature b);
33033319

3320+
LDKCResult_NoneLightningErrorZ CResult_NoneLightningErrorZ_ok(void);
3321+
33043322
void Event_free(LDKEvent this_ptr);
33053323

33063324
LDKEvent Event_clone(const LDKEvent *orig);
@@ -7262,6 +7280,46 @@ LDKNetworkGraph NetworkGraph_read(LDKu8slice ser);
72627280
*/
72637281
MUST_USE_RES LDKNetworkGraph NetworkGraph_new(void);
72647282

7283+
/**
7284+
* For an already known node (from channel announcements), update its stored properties from a
7285+
* given node announcement.
7286+
*
7287+
* You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
7288+
* RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
7289+
* routing messages from a source using a protocol other than the lightning P2P protocol.
7290+
*/
7291+
MUST_USE_RES LDKCResult_NoneLightningErrorZ NetworkGraph_update_node_from_announcement(LDKNetworkGraph *this_arg, const LDKNodeAnnouncement *msg);
7292+
7293+
/**
7294+
* For an already known node (from channel announcements), update its stored properties from a
7295+
* given node announcement without verifying the associated signatures. Because we aren't
7296+
* given the associated signatures here we cannot relay the node announcement to any of our
7297+
* peers.
7298+
*/
7299+
MUST_USE_RES LDKCResult_NoneLightningErrorZ NetworkGraph_update_node_from_unsigned_announcement(LDKNetworkGraph *this_arg, const LDKUnsignedNodeAnnouncement *msg);
7300+
7301+
/**
7302+
* Store or update channel info from a channel announcement.
7303+
*
7304+
* You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
7305+
* RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
7306+
* routing messages from a source using a protocol other than the lightning P2P protocol.
7307+
*
7308+
* If a `chain::Access` object is provided via `chain_access`, it will be called to verify
7309+
* the corresponding UTXO exists on chain and is correctly-formatted.
7310+
*/
7311+
MUST_USE_RES LDKCResult_NoneLightningErrorZ NetworkGraph_update_channel_from_announcement(LDKNetworkGraph *this_arg, const LDKChannelAnnouncement *msg, LDKAccess *chain_access);
7312+
7313+
/**
7314+
* Store or update channel info from a channel announcement without verifying the associated
7315+
* signatures. Because we aren't given the associated signatures here we cannot relay the
7316+
* channel announcement to any of our peers.
7317+
*
7318+
* If a `chain::Access` object is provided via `chain_access`, it will be called to verify
7319+
* the corresponding UTXO exists on chain and is correctly-formatted.
7320+
*/
7321+
MUST_USE_RES LDKCResult_NoneLightningErrorZ NetworkGraph_update_channel_from_unsigned_announcement(LDKNetworkGraph *this_arg, const LDKUnsignedChannelAnnouncement *msg, LDKAccess *chain_access);
7322+
72657323
/**
72667324
* Close a channel if a corresponding HTLC fail was sent.
72677325
* If permanent, removes a channel from the local storage.
@@ -7270,4 +7328,21 @@ MUST_USE_RES LDKNetworkGraph NetworkGraph_new(void);
72707328
*/
72717329
void NetworkGraph_close_channel_from_update(LDKNetworkGraph *this_arg, uint64_t short_channel_id, bool is_permanent);
72727330

7331+
/**
7332+
* For an already known (from announcement) channel, update info about one of the directions
7333+
* of the channel.
7334+
*
7335+
* You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
7336+
* RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
7337+
* routing messages from a source using a protocol other than the lightning P2P protocol.
7338+
*/
7339+
MUST_USE_RES LDKCResult_NoneLightningErrorZ NetworkGraph_update_channel(LDKNetworkGraph *this_arg, const LDKChannelUpdate *msg);
7340+
7341+
/**
7342+
* For an already known (from announcement) channel, update info about one of the directions
7343+
* of the channel without verifying the associated signatures. Because we aren't given the
7344+
* associated signatures here we cannot relay the channel update to any of our peers.
7345+
*/
7346+
MUST_USE_RES LDKCResult_NoneLightningErrorZ NetworkGraph_update_channel_unsigned(LDKNetworkGraph *this_arg, const LDKUnsignedChannelUpdate *msg);
7347+
72737348
/* Text to put at the end of the generated file */

lightning-c-bindings/include/lightningpp.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,6 +1830,20 @@ class CResult_RouteLightningErrorZ {
18301830
const LDKCResult_RouteLightningErrorZ* operator &() const { return &self; }
18311831
const LDKCResult_RouteLightningErrorZ* operator ->() const { return &self; }
18321832
};
1833+
class CResult_NoneLightningErrorZ {
1834+
private:
1835+
LDKCResult_NoneLightningErrorZ self;
1836+
public:
1837+
CResult_NoneLightningErrorZ(const CResult_NoneLightningErrorZ&) = delete;
1838+
~CResult_NoneLightningErrorZ() { CResult_NoneLightningErrorZ_free(self); }
1839+
CResult_NoneLightningErrorZ(CResult_NoneLightningErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_NoneLightningErrorZ)); }
1840+
CResult_NoneLightningErrorZ(LDKCResult_NoneLightningErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_NoneLightningErrorZ)); }
1841+
operator LDKCResult_NoneLightningErrorZ() { LDKCResult_NoneLightningErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_NoneLightningErrorZ)); return res; }
1842+
LDKCResult_NoneLightningErrorZ* operator &() { return &self; }
1843+
LDKCResult_NoneLightningErrorZ* operator ->() { return &self; }
1844+
const LDKCResult_NoneLightningErrorZ* operator &() const { return &self; }
1845+
const LDKCResult_NoneLightningErrorZ* operator ->() const { return &self; }
1846+
};
18331847
class CResult_CVec_SignatureZNoneZ {
18341848
private:
18351849
LDKCResult_CVec_SignatureZNoneZ self;

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,3 +400,16 @@ pub static CResult_RouteLightningErrorZ_ok: extern "C" fn (crate::routing::route
400400
pub static CResult_RouteLightningErrorZ_err: extern "C" fn (crate::ln::msgs::LightningError) -> CResult_RouteLightningErrorZ =
401401
crate::c_types::CResultTempl::<crate::routing::router::Route, crate::ln::msgs::LightningError>::err;
402402

403+
#[no_mangle]
404+
pub type CResult_NoneLightningErrorZ = crate::c_types::CResultTempl<u8, crate::ln::msgs::LightningError>;
405+
#[no_mangle]
406+
pub static CResult_NoneLightningErrorZ_free: extern "C" fn(CResult_NoneLightningErrorZ) = crate::c_types::CResultTempl_free::<u8, crate::ln::msgs::LightningError>;
407+
#[no_mangle]
408+
pub extern "C" fn CResult_NoneLightningErrorZ_ok() -> CResult_NoneLightningErrorZ {
409+
crate::c_types::CResultTempl::ok(0)
410+
}
411+
412+
#[no_mangle]
413+
pub static CResult_NoneLightningErrorZ_err: extern "C" fn (crate::ln::msgs::LightningError) -> CResult_NoneLightningErrorZ =
414+
crate::c_types::CResultTempl::<u8, crate::ln::msgs::LightningError>::err;
415+

lightning-c-bindings/src/routing/network_graph.rs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,64 @@ pub extern "C" fn NetworkGraph_new() -> crate::routing::network_graph::NetworkGr
826826
crate::routing::network_graph::NetworkGraph { inner: Box::into_raw(Box::new(ret)), is_owned: true }
827827
}
828828

829+
/// For an already known node (from channel announcements), update its stored properties from a
830+
/// given node announcement.
831+
///
832+
/// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
833+
/// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
834+
/// routing messages from a source using a protocol other than the lightning P2P protocol.
835+
#[must_use]
836+
#[no_mangle]
837+
pub extern "C" fn NetworkGraph_update_node_from_announcement(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
838+
let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_node_from_announcement(unsafe { &*msg.inner }, &bitcoin::secp256k1::Secp256k1::new());
839+
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) };
840+
local_ret
841+
}
842+
843+
/// For an already known node (from channel announcements), update its stored properties from a
844+
/// given node announcement without verifying the associated signatures. Because we aren't
845+
/// given the associated signatures here we cannot relay the node announcement to any of our
846+
/// peers.
847+
#[must_use]
848+
#[no_mangle]
849+
pub extern "C" fn NetworkGraph_update_node_from_unsigned_announcement(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::UnsignedNodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
850+
let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_node_from_unsigned_announcement(unsafe { &*msg.inner });
851+
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) };
852+
local_ret
853+
}
854+
855+
/// Store or update channel info from a channel announcement.
856+
///
857+
/// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
858+
/// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
859+
/// routing messages from a source using a protocol other than the lightning P2P protocol.
860+
///
861+
/// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
862+
/// the corresponding UTXO exists on chain and is correctly-formatted.
863+
#[must_use]
864+
#[no_mangle]
865+
pub extern "C" fn NetworkGraph_update_channel_from_announcement(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::ChannelAnnouncement, chain_access: *mut crate::chain::Access) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
866+
let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
867+
let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_from_announcement(unsafe { &*msg.inner }, &local_chain_access, &bitcoin::secp256k1::Secp256k1::new());
868+
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) };
869+
local_ret
870+
}
871+
872+
/// Store or update channel info from a channel announcement without verifying the associated
873+
/// signatures. Because we aren't given the associated signatures here we cannot relay the
874+
/// channel announcement to any of our peers.
875+
///
876+
/// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
877+
/// the corresponding UTXO exists on chain and is correctly-formatted.
878+
#[must_use]
879+
#[no_mangle]
880+
pub extern "C" fn NetworkGraph_update_channel_from_unsigned_announcement(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::UnsignedChannelAnnouncement, chain_access: *mut crate::chain::Access) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
881+
let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
882+
let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_from_unsigned_announcement(unsafe { &*msg.inner }, &local_chain_access);
883+
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) };
884+
local_ret
885+
}
886+
829887
/// Close a channel if a corresponding HTLC fail was sent.
830888
/// If permanent, removes a channel from the local storage.
831889
/// May cause the removal of nodes too, if this was their last channel.
@@ -835,3 +893,28 @@ pub extern "C" fn NetworkGraph_close_channel_from_update(this_arg: &mut NetworkG
835893
unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.close_channel_from_update(short_channel_id, is_permanent)
836894
}
837895

896+
/// For an already known (from announcement) channel, update info about one of the directions
897+
/// of the channel.
898+
///
899+
/// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
900+
/// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
901+
/// routing messages from a source using a protocol other than the lightning P2P protocol.
902+
#[must_use]
903+
#[no_mangle]
904+
pub extern "C" fn NetworkGraph_update_channel(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
905+
let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel(unsafe { &*msg.inner }, &bitcoin::secp256k1::Secp256k1::new());
906+
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) };
907+
local_ret
908+
}
909+
910+
/// For an already known (from announcement) channel, update info about one of the directions
911+
/// of the channel without verifying the associated signatures. Because we aren't given the
912+
/// associated signatures here we cannot relay the channel update to any of our peers.
913+
#[must_use]
914+
#[no_mangle]
915+
pub extern "C" fn NetworkGraph_update_channel_unsigned(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::UnsignedChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
916+
let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_unsigned(unsafe { &*msg.inner });
917+
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) };
918+
local_ret
919+
}
920+

0 commit comments

Comments
 (0)