From e419524cf19c36857bf1f3c79d4b9dd47c7544c8 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 11 Jun 2021 17:43:09 +0000 Subject: [PATCH] Update auto-generated bindings to upstream 0.0.98 --- lightning-c-bindings/include/ldk_rust_types.h | 6 +- lightning-c-bindings/include/lightning.h | 148 +++++++++++------- lightning-c-bindings/include/lightningpp.hpp | 123 ++++++++------- lightning-c-bindings/src/c_types/derived.rs | 104 ++++++------ .../src/lightning/chain/mod.rs | 2 +- .../src/lightning/routing/router.rs | 81 +++++++++- .../src/lightning_invoice/constants.rs | 2 +- .../src/lightning_invoice/mod.rs | 79 +++++----- 8 files changed, 342 insertions(+), 203 deletions(-) diff --git a/lightning-c-bindings/include/ldk_rust_types.h b/lightning-c-bindings/include/ldk_rust_types.h index 3138c9e..114f789 100644 --- a/lightning-c-bindings/include/ldk_rust_types.h +++ b/lightning-c-bindings/include/ldk_rust_types.h @@ -36,6 +36,8 @@ struct nativeRouteHopOpaque; typedef struct nativeRouteHopOpaque LDKnativeRouteHop; struct nativeRouteOpaque; typedef struct nativeRouteOpaque LDKnativeRoute; +struct nativeRouteHintOpaque; +typedef struct nativeRouteHintOpaque LDKnativeRouteHint; struct nativeRouteHintHopOpaque; typedef struct nativeRouteHintHopOpaque LDKnativeRouteHintHop; struct nativeWatchedOutputOpaque; @@ -102,8 +104,8 @@ struct nativeMinFinalCltvExpiryOpaque; typedef struct nativeMinFinalCltvExpiryOpaque LDKnativeMinFinalCltvExpiry; struct nativeInvoiceSignatureOpaque; typedef struct nativeInvoiceSignatureOpaque LDKnativeInvoiceSignature; -struct nativeRouteHintOpaque; -typedef struct nativeRouteHintOpaque LDKnativeRouteHint; +struct nativePrivateRouteOpaque; +typedef struct nativePrivateRouteOpaque LDKnativePrivateRoute; struct nativeChannelMonitorUpdateOpaque; typedef struct nativeChannelMonitorUpdateOpaque LDKnativeChannelMonitorUpdate; struct nativeMonitorUpdateErrorOpaque; diff --git a/lightning-c-bindings/include/lightning.h b/lightning-c-bindings/include/lightning.h index 8d27f34..8fe1048 100644 --- a/lightning-c-bindings/include/lightning.h +++ b/lightning-c-bindings/include/lightning.h @@ -1425,38 +1425,38 @@ typedef struct LDKCVec_ChannelDetailsZ { /** - * A channel descriptor which provides a last-hop route to get_route + * A list of hops along a payment path terminating with a channel to the recipient. */ -typedef struct MUST_USE_STRUCT LDKRouteHintHop { +typedef struct MUST_USE_STRUCT LDKRouteHint { /** * A pointer to the opaque Rust object. * Nearly everywhere, inner must be non-null, however in places where * the Rust equivalent takes an Option, it may be set to null to indicate None. */ - LDKnativeRouteHintHop *inner; + LDKnativeRouteHint *inner; /** * Indicates that this is the only struct which contains the same pointer. * Rust functions which take ownership of an object provided via an argument require * this to be true and invalidate the object pointed to by inner. */ bool is_owned; -} LDKRouteHintHop; +} LDKRouteHint; /** - * A dynamically-allocated array of crate::lightning::routing::router::RouteHintHops of arbitrary size. + * A dynamically-allocated array of crate::lightning::routing::router::RouteHints of arbitrary size. * This corresponds to std::vector in C++ */ -typedef struct LDKCVec_RouteHintHopZ { +typedef struct LDKCVec_RouteHintZ { /** * The elements in the array. * If datalen is non-0 this must be a valid, non-NULL pointer allocated by malloc(). */ - struct LDKRouteHintHop *data; + struct LDKRouteHint *data; /** * The number of elements pointed to by `data`. */ uintptr_t datalen; -} LDKCVec_RouteHintHopZ; +} LDKCVec_RouteHintZ; @@ -4805,36 +4805,36 @@ typedef struct LDKCResult_PayeePubKeyErrorZ { * The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops) * */ -typedef struct MUST_USE_STRUCT LDKRouteHint { +typedef struct MUST_USE_STRUCT LDKPrivateRoute { /** * A pointer to the opaque Rust object. * Nearly everywhere, inner must be non-null, however in places where * the Rust equivalent takes an Option, it may be set to null to indicate None. */ - LDKnativeRouteHint *inner; + LDKnativePrivateRoute *inner; /** * Indicates that this is the only struct which contains the same pointer. * Rust functions which take ownership of an object provided via an argument require * this to be true and invalidate the object pointed to by inner. */ bool is_owned; -} LDKRouteHint; +} LDKPrivateRoute; /** - * A dynamically-allocated array of crate::lightning_invoice::RouteHints of arbitrary size. + * A dynamically-allocated array of crate::lightning_invoice::PrivateRoutes of arbitrary size. * This corresponds to std::vector in C++ */ -typedef struct LDKCVec_RouteHintZ { +typedef struct LDKCVec_PrivateRouteZ { /** * The elements in the array. * If datalen is non-0 this must be a valid, non-NULL pointer allocated by malloc(). */ - struct LDKRouteHint *data; + struct LDKPrivateRoute *data; /** * The number of elements pointed to by `data`. */ uintptr_t datalen; -} LDKCVec_RouteHintZ; +} LDKCVec_PrivateRouteZ; @@ -5075,37 +5075,37 @@ typedef struct LDKCResult_ExpiryTimeCreationErrorZ { } LDKCResult_ExpiryTimeCreationErrorZ; /** - * The contents of CResult_RouteHintCreationErrorZ + * The contents of CResult_PrivateRouteCreationErrorZ */ -typedef union LDKCResult_RouteHintCreationErrorZPtr { +typedef union LDKCResult_PrivateRouteCreationErrorZPtr { /** * A pointer to the contents in the success state. * Reading from this pointer when `result_ok` is not set is undefined. */ - struct LDKRouteHint *result; + struct LDKPrivateRoute *result; /** * A pointer to the contents in the error state. * Reading from this pointer when `result_ok` is set is undefined. */ enum LDKCreationError *err; -} LDKCResult_RouteHintCreationErrorZPtr; +} LDKCResult_PrivateRouteCreationErrorZPtr; /** - * A CResult_RouteHintCreationErrorZ represents the result of a fallible operation, - * containing a crate::lightning_invoice::RouteHint on success and a crate::lightning_invoice::CreationError on failure. + * A CResult_PrivateRouteCreationErrorZ represents the result of a fallible operation, + * containing a crate::lightning_invoice::PrivateRoute on success and a crate::lightning_invoice::CreationError on failure. * `result_ok` indicates the overall state, and the contents are provided via `contents`. */ -typedef struct LDKCResult_RouteHintCreationErrorZ { +typedef struct LDKCResult_PrivateRouteCreationErrorZ { /** - * The contents of this CResult_RouteHintCreationErrorZ, accessible via either + * The contents of this CResult_PrivateRouteCreationErrorZ, accessible via either * `err` or `result` depending on the state of `result_ok`. */ - union LDKCResult_RouteHintCreationErrorZPtr contents; + union LDKCResult_PrivateRouteCreationErrorZPtr contents; /** - * Whether this CResult_RouteHintCreationErrorZ represents a success state. + * Whether this CResult_PrivateRouteCreationErrorZ represents a success state. */ bool result_ok; -} LDKCResult_RouteHintCreationErrorZ; +} LDKCResult_PrivateRouteCreationErrorZ; /** * The contents of CResult_StringErrorZ @@ -8745,6 +8745,26 @@ typedef struct MUST_USE_STRUCT LDKDirectedChannelTransactionParameters { +/** + * A channel descriptor for a hop along a payment path. + */ +typedef struct MUST_USE_STRUCT LDKRouteHintHop { + /** + * A pointer to the opaque Rust object. + * Nearly everywhere, inner must be non-null, however in places where + * the Rust equivalent takes an Option, it may be set to null to indicate None. + */ + LDKnativeRouteHintHop *inner; + /** + * Indicates that this is the only struct which contains the same pointer. + * Rust functions which take ownership of an object provided via an argument require + * this to be true and invalidate the object pointed to by inner. + */ + bool is_owned; +} LDKRouteHintHop; + + + /** * A simple newtype for RwLockReadGuard<'a, NetworkGraph>. * This exists only to make accessing a RwLock possible from @@ -9016,7 +9036,7 @@ extern const uint8_t TAG_MIN_FINAL_CLTV_EXPIRY; extern const uint8_t TAG_FALLBACK; -extern const uint8_t TAG_ROUTE; +extern const uint8_t TAG_PRIVATE_ROUTE; extern const uint8_t TAG_PAYMENT_SECRET; @@ -9435,7 +9455,7 @@ void CVec_ChannelDetailsZ_free(struct LDKCVec_ChannelDetailsZ _res); /** * Frees the buffer pointed to by `data` if `datalen` is non-0. */ -void CVec_RouteHintHopZ_free(struct LDKCVec_RouteHintHopZ _res); +void CVec_RouteHintZ_free(struct LDKCVec_RouteHintZ _res); /** * Creates a new CResult_RouteLightningErrorZ in the success state. @@ -10162,7 +10182,7 @@ struct LDKCResult_PayeePubKeyErrorZ CResult_PayeePubKeyErrorZ_clone(const struct /** * Frees the buffer pointed to by `data` if `datalen` is non-0. */ -void CVec_RouteHintZ_free(struct LDKCVec_RouteHintZ _res); +void CVec_PrivateRouteZ_free(struct LDKCVec_PrivateRouteZ _res); /** * Creates a new CResult_PositiveTimestampCreationErrorZ in the success state. @@ -10270,25 +10290,25 @@ void CResult_ExpiryTimeCreationErrorZ_free(struct LDKCResult_ExpiryTimeCreationE struct LDKCResult_ExpiryTimeCreationErrorZ CResult_ExpiryTimeCreationErrorZ_clone(const struct LDKCResult_ExpiryTimeCreationErrorZ *NONNULL_PTR orig); /** - * Creates a new CResult_RouteHintCreationErrorZ in the success state. + * Creates a new CResult_PrivateRouteCreationErrorZ in the success state. */ -struct LDKCResult_RouteHintCreationErrorZ CResult_RouteHintCreationErrorZ_ok(struct LDKRouteHint o); +struct LDKCResult_PrivateRouteCreationErrorZ CResult_PrivateRouteCreationErrorZ_ok(struct LDKPrivateRoute o); /** - * Creates a new CResult_RouteHintCreationErrorZ in the error state. + * Creates a new CResult_PrivateRouteCreationErrorZ in the error state. */ -struct LDKCResult_RouteHintCreationErrorZ CResult_RouteHintCreationErrorZ_err(enum LDKCreationError e); +struct LDKCResult_PrivateRouteCreationErrorZ CResult_PrivateRouteCreationErrorZ_err(enum LDKCreationError e); /** - * Frees any resources used by the CResult_RouteHintCreationErrorZ. + * Frees any resources used by the CResult_PrivateRouteCreationErrorZ. */ -void CResult_RouteHintCreationErrorZ_free(struct LDKCResult_RouteHintCreationErrorZ _res); +void CResult_PrivateRouteCreationErrorZ_free(struct LDKCResult_PrivateRouteCreationErrorZ _res); /** - * Creates a new CResult_RouteHintCreationErrorZ which has the same data as `orig` + * Creates a new CResult_PrivateRouteCreationErrorZ which has the same data as `orig` * but with all dynamically-allocated buffers duplicated in new buffers. */ -struct LDKCResult_RouteHintCreationErrorZ CResult_RouteHintCreationErrorZ_clone(const struct LDKCResult_RouteHintCreationErrorZ *NONNULL_PTR orig); +struct LDKCResult_PrivateRouteCreationErrorZ CResult_PrivateRouteCreationErrorZ_clone(const struct LDKCResult_PrivateRouteCreationErrorZ *NONNULL_PTR orig); /** * Creates a new CResult_StringErrorZ in the success state. @@ -17088,6 +17108,23 @@ struct LDKCVec_u8Z Route_write(const struct LDKRoute *NONNULL_PTR obj); */ struct LDKCResult_RouteDecodeErrorZ Route_read(struct LDKu8slice ser); +/** + * Frees any resources used by the RouteHint, if is_owned is set and inner is non-NULL. + */ +void RouteHint_free(struct LDKRouteHint this_obj); + +/** + * Checks if two RouteHints contain equal inner contents. + * This ignores pointers and is_owned flags and looks at the values in fields. + * Two objects with NULL inner values will be considered "equal" here. + */ +bool RouteHint_eq(const struct LDKRouteHint *NONNULL_PTR a, const struct LDKRouteHint *NONNULL_PTR b); + +/** + * Creates a copy of the RouteHint + */ +struct LDKRouteHint RouteHint_clone(const struct LDKRouteHint *NONNULL_PTR orig); + /** * Frees any resources used by the RouteHintHop, if is_owned is set and inner is non-NULL. */ @@ -17176,8 +17213,8 @@ struct LDKRouteHintHop RouteHintHop_clone(const struct LDKRouteHintHop *NONNULL_ * If the payee provided features in their invoice, they should be provided via payee_features. * Without this, MPP will only be used if the payee's features are available in the network graph. * - * Extra routing hops between known nodes and the target will be used if they are included in - * last_hops. + * Private routing paths between a public node and the target may be included in `last_hops`. + * Currently, only the last hop in each path is considered. * * If some channels aren't announced, it may be useful to fill in a first_hops with the * results from a local ChannelManager::list_usable_channels() call. If it is filled in, our @@ -17191,7 +17228,7 @@ struct LDKRouteHintHop RouteHintHop_clone(const struct LDKRouteHintHop *NONNULL_ * equal), however the enabled/disabled bit on such channels as well as the * htlc_minimum_msat/htlc_maximum_msat *are* checked as they may change based on the receiving node. */ -struct LDKCResult_RouteLightningErrorZ get_route(struct LDKPublicKey our_node_id, const struct LDKNetworkGraph *NONNULL_PTR network, struct LDKPublicKey payee, struct LDKInvoiceFeatures payee_features, struct LDKCVec_ChannelDetailsZ *first_hops, struct LDKCVec_RouteHintHopZ last_hops, uint64_t final_value_msat, uint32_t final_cltv, struct LDKLogger logger); +struct LDKCResult_RouteLightningErrorZ get_route(struct LDKPublicKey our_node_id, const struct LDKNetworkGraph *NONNULL_PTR network, struct LDKPublicKey payee, struct LDKInvoiceFeatures payee_features, struct LDKCVec_ChannelDetailsZ *first_hops, struct LDKCVec_RouteHintZ last_hops, uint64_t final_value_msat, uint32_t final_cltv, struct LDKLogger logger); /** * Frees any resources used by the NetworkGraph, if is_owned is set and inner is non-NULL. @@ -18087,21 +18124,21 @@ bool InvoiceSignature_eq(const struct LDKInvoiceSignature *NONNULL_PTR a, const struct LDKInvoiceSignature InvoiceSignature_clone(const struct LDKInvoiceSignature *NONNULL_PTR orig); /** - * Frees any resources used by the RouteHint, if is_owned is set and inner is non-NULL. + * Frees any resources used by the PrivateRoute, if is_owned is set and inner is non-NULL. */ -void RouteHint_free(struct LDKRouteHint this_obj); +void PrivateRoute_free(struct LDKPrivateRoute this_obj); /** - * Checks if two RouteHints contain equal inner contents. + * Checks if two PrivateRoutes contain equal inner contents. * This ignores pointers and is_owned flags and looks at the values in fields. * Two objects with NULL inner values will be considered "equal" here. */ -bool RouteHint_eq(const struct LDKRouteHint *NONNULL_PTR a, const struct LDKRouteHint *NONNULL_PTR b); +bool PrivateRoute_eq(const struct LDKPrivateRoute *NONNULL_PTR a, const struct LDKPrivateRoute *NONNULL_PTR b); /** - * Creates a copy of the RouteHint + * Creates a copy of the PrivateRoute */ -struct LDKRouteHint RouteHint_clone(const struct LDKRouteHint *NONNULL_PTR orig); +struct LDKPrivateRoute PrivateRoute_clone(const struct LDKPrivateRoute *NONNULL_PTR orig); /** * Disassembles the `SignedRawInvoice` into its three parts: @@ -18158,7 +18195,7 @@ MUST_USE_RES struct LDKThirtyTwoBytes RawInvoice_payment_secret(const struct LDK MUST_USE_RES struct LDKInvoiceFeatures RawInvoice_features(const struct LDKRawInvoice *NONNULL_PTR this_arg); -MUST_USE_RES struct LDKCVec_RouteHintZ RawInvoice_routes(const struct LDKRawInvoice *NONNULL_PTR this_arg); +MUST_USE_RES struct LDKCVec_PrivateRouteZ RawInvoice_private_routes(const struct LDKRawInvoice *NONNULL_PTR this_arg); MUST_USE_RES struct LDKCOption_u64Z RawInvoice_amount_pico_btc(const struct LDKRawInvoice *NONNULL_PTR this_arg); @@ -18199,7 +18236,7 @@ MUST_USE_RES struct LDKSignedRawInvoice Invoice_into_signed_raw(struct LDKInvoic MUST_USE_RES struct LDKCResult_NoneSemanticErrorZ Invoice_check_signature(const struct LDKInvoice *NONNULL_PTR this_arg); /** - * Constructs an `Invoice` from a `SignedInvoice` by checking all its invariants. + * Constructs an `Invoice` from a `SignedRawInvoice` by checking all its invariants. * ``` * use lightning_invoice::*; * @@ -18259,7 +18296,12 @@ MUST_USE_RES uint64_t Invoice_min_final_cltv_expiry(const struct LDKInvoice *NON /** * Returns a list of all routes included in the invoice */ -MUST_USE_RES struct LDKCVec_RouteHintZ Invoice_routes(const struct LDKInvoice *NONNULL_PTR this_arg); +MUST_USE_RES struct LDKCVec_PrivateRouteZ Invoice_private_routes(const struct LDKInvoice *NONNULL_PTR this_arg); + +/** + * Returns a list of all routes included in the invoice as the underlying hints + */ +MUST_USE_RES struct LDKCVec_RouteHintZ Invoice_route_hints(const struct LDKInvoice *NONNULL_PTR this_arg); /** * Returns the currency for which the invoice was issued @@ -18309,14 +18351,14 @@ MUST_USE_RES uint64_t ExpiryTime_as_seconds(const struct LDKExpiryTime *NONNULL_ MUST_USE_RES uint64_t ExpiryTime_as_duration(const struct LDKExpiryTime *NONNULL_PTR this_arg); /** - * Create a new (partial) route from a list of hops + * Creates a new (partial) route from a list of hops */ -MUST_USE_RES struct LDKCResult_RouteHintCreationErrorZ RouteHint_new(struct LDKCVec_RouteHintHopZ hops); +MUST_USE_RES struct LDKCResult_PrivateRouteCreationErrorZ PrivateRoute_new(struct LDKRouteHint hops); /** - * Returrn the underlying vector of hops + * Returns the underlying list of hops */ -MUST_USE_RES struct LDKCVec_RouteHintHopZ RouteHint_into_inner(struct LDKRouteHint this_arg); +MUST_USE_RES struct LDKRouteHint PrivateRoute_into_inner(struct LDKPrivateRoute this_arg); /** * Creates a copy of the CreationError diff --git a/lightning-c-bindings/include/lightningpp.hpp b/lightning-c-bindings/include/lightningpp.hpp index 0cd1dc4..0b0a417 100644 --- a/lightning-c-bindings/include/lightningpp.hpp +++ b/lightning-c-bindings/include/lightningpp.hpp @@ -210,6 +210,21 @@ public: const LDKRoute* operator &() const { return &self; } const LDKRoute* operator ->() const { return &self; } }; +class RouteHint { +private: + LDKRouteHint self; +public: + RouteHint(const RouteHint&) = delete; + RouteHint(RouteHint&& o) : self(o.self) { memset(&o, 0, sizeof(RouteHint)); } + RouteHint(LDKRouteHint&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKRouteHint)); } + operator LDKRouteHint() && { LDKRouteHint res = self; memset(&self, 0, sizeof(LDKRouteHint)); return res; } + ~RouteHint() { RouteHint_free(self); } + RouteHint& operator=(RouteHint&& o) { RouteHint_free(self); self = o.self; memset(&o, 0, sizeof(RouteHint)); return *this; } + LDKRouteHint* operator &() { return &self; } + LDKRouteHint* operator ->() { return &self; } + const LDKRouteHint* operator &() const { return &self; } + const LDKRouteHint* operator ->() const { return &self; } +}; class RouteHintHop { private: LDKRouteHintHop self; @@ -1031,20 +1046,20 @@ public: const LDKInvoiceSignature* operator &() const { return &self; } const LDKInvoiceSignature* operator ->() const { return &self; } }; -class RouteHint { +class PrivateRoute { private: - LDKRouteHint self; + LDKPrivateRoute self; public: - RouteHint(const RouteHint&) = delete; - RouteHint(RouteHint&& o) : self(o.self) { memset(&o, 0, sizeof(RouteHint)); } - RouteHint(LDKRouteHint&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKRouteHint)); } - operator LDKRouteHint() && { LDKRouteHint res = self; memset(&self, 0, sizeof(LDKRouteHint)); return res; } - ~RouteHint() { RouteHint_free(self); } - RouteHint& operator=(RouteHint&& o) { RouteHint_free(self); self = o.self; memset(&o, 0, sizeof(RouteHint)); return *this; } - LDKRouteHint* operator &() { return &self; } - LDKRouteHint* operator ->() { return &self; } - const LDKRouteHint* operator &() const { return &self; } - const LDKRouteHint* operator ->() const { return &self; } + PrivateRoute(const PrivateRoute&) = delete; + PrivateRoute(PrivateRoute&& o) : self(o.self) { memset(&o, 0, sizeof(PrivateRoute)); } + PrivateRoute(LDKPrivateRoute&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKPrivateRoute)); } + operator LDKPrivateRoute() && { LDKPrivateRoute res = self; memset(&self, 0, sizeof(LDKPrivateRoute)); return res; } + ~PrivateRoute() { PrivateRoute_free(self); } + PrivateRoute& operator=(PrivateRoute&& o) { PrivateRoute_free(self); self = o.self; memset(&o, 0, sizeof(PrivateRoute)); return *this; } + LDKPrivateRoute* operator &() { return &self; } + LDKPrivateRoute* operator ->() { return &self; } + const LDKPrivateRoute* operator &() const { return &self; } + const LDKPrivateRoute* operator ->() const { return &self; } }; class CreationError { private: @@ -2932,21 +2947,6 @@ public: const LDKCVec_RouteHopZ* operator &() const { return &self; } const LDKCVec_RouteHopZ* operator ->() const { return &self; } }; -class CResult_RouteHintCreationErrorZ { -private: - LDKCResult_RouteHintCreationErrorZ self; -public: - CResult_RouteHintCreationErrorZ(const CResult_RouteHintCreationErrorZ&) = delete; - CResult_RouteHintCreationErrorZ(CResult_RouteHintCreationErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_RouteHintCreationErrorZ)); } - CResult_RouteHintCreationErrorZ(LDKCResult_RouteHintCreationErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_RouteHintCreationErrorZ)); } - operator LDKCResult_RouteHintCreationErrorZ() && { LDKCResult_RouteHintCreationErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_RouteHintCreationErrorZ)); return res; } - ~CResult_RouteHintCreationErrorZ() { CResult_RouteHintCreationErrorZ_free(self); } - CResult_RouteHintCreationErrorZ& operator=(CResult_RouteHintCreationErrorZ&& o) { CResult_RouteHintCreationErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_RouteHintCreationErrorZ)); return *this; } - LDKCResult_RouteHintCreationErrorZ* operator &() { return &self; } - LDKCResult_RouteHintCreationErrorZ* operator ->() { return &self; } - const LDKCResult_RouteHintCreationErrorZ* operator &() const { return &self; } - const LDKCResult_RouteHintCreationErrorZ* operator ->() const { return &self; } -}; class CVec_C2Tuple_BlockHashChannelMonitorZZ { private: LDKCVec_C2Tuple_BlockHashChannelMonitorZZ self; @@ -3097,21 +3097,6 @@ public: const LDKCResult_SignatureNoneZ* operator &() const { return &self; } const LDKCResult_SignatureNoneZ* operator ->() const { return &self; } }; -class CVec_RouteHintHopZ { -private: - LDKCVec_RouteHintHopZ self; -public: - CVec_RouteHintHopZ(const CVec_RouteHintHopZ&) = delete; - CVec_RouteHintHopZ(CVec_RouteHintHopZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_RouteHintHopZ)); } - CVec_RouteHintHopZ(LDKCVec_RouteHintHopZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_RouteHintHopZ)); } - operator LDKCVec_RouteHintHopZ() && { LDKCVec_RouteHintHopZ res = self; memset(&self, 0, sizeof(LDKCVec_RouteHintHopZ)); return res; } - ~CVec_RouteHintHopZ() { CVec_RouteHintHopZ_free(self); } - CVec_RouteHintHopZ& operator=(CVec_RouteHintHopZ&& o) { CVec_RouteHintHopZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_RouteHintHopZ)); return *this; } - LDKCVec_RouteHintHopZ* operator &() { return &self; } - LDKCVec_RouteHintHopZ* operator ->() { return &self; } - const LDKCVec_RouteHintHopZ* operator &() const { return &self; } - const LDKCVec_RouteHintHopZ* operator ->() const { return &self; } -}; class C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ { private: LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ self; @@ -3832,20 +3817,20 @@ public: const LDKCResult_ChannelConfigDecodeErrorZ* operator &() const { return &self; } const LDKCResult_ChannelConfigDecodeErrorZ* operator ->() const { return &self; } }; -class CResult_RevokeAndACKDecodeErrorZ { +class CVec_PrivateRouteZ { private: - LDKCResult_RevokeAndACKDecodeErrorZ self; + LDKCVec_PrivateRouteZ self; public: - CResult_RevokeAndACKDecodeErrorZ(const CResult_RevokeAndACKDecodeErrorZ&) = delete; - CResult_RevokeAndACKDecodeErrorZ(CResult_RevokeAndACKDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_RevokeAndACKDecodeErrorZ)); } - CResult_RevokeAndACKDecodeErrorZ(LDKCResult_RevokeAndACKDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_RevokeAndACKDecodeErrorZ)); } - operator LDKCResult_RevokeAndACKDecodeErrorZ() && { LDKCResult_RevokeAndACKDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_RevokeAndACKDecodeErrorZ)); return res; } - ~CResult_RevokeAndACKDecodeErrorZ() { CResult_RevokeAndACKDecodeErrorZ_free(self); } - CResult_RevokeAndACKDecodeErrorZ& operator=(CResult_RevokeAndACKDecodeErrorZ&& o) { CResult_RevokeAndACKDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_RevokeAndACKDecodeErrorZ)); return *this; } - LDKCResult_RevokeAndACKDecodeErrorZ* operator &() { return &self; } - LDKCResult_RevokeAndACKDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_RevokeAndACKDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_RevokeAndACKDecodeErrorZ* operator ->() const { return &self; } + CVec_PrivateRouteZ(const CVec_PrivateRouteZ&) = delete; + CVec_PrivateRouteZ(CVec_PrivateRouteZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_PrivateRouteZ)); } + CVec_PrivateRouteZ(LDKCVec_PrivateRouteZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_PrivateRouteZ)); } + operator LDKCVec_PrivateRouteZ() && { LDKCVec_PrivateRouteZ res = self; memset(&self, 0, sizeof(LDKCVec_PrivateRouteZ)); return res; } + ~CVec_PrivateRouteZ() { CVec_PrivateRouteZ_free(self); } + CVec_PrivateRouteZ& operator=(CVec_PrivateRouteZ&& o) { CVec_PrivateRouteZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_PrivateRouteZ)); return *this; } + LDKCVec_PrivateRouteZ* operator &() { return &self; } + LDKCVec_PrivateRouteZ* operator ->() { return &self; } + const LDKCVec_PrivateRouteZ* operator &() const { return &self; } + const LDKCVec_PrivateRouteZ* operator ->() const { return &self; } }; class CResult_SpendableOutputDescriptorDecodeErrorZ { private: @@ -3862,6 +3847,21 @@ public: const LDKCResult_SpendableOutputDescriptorDecodeErrorZ* operator &() const { return &self; } const LDKCResult_SpendableOutputDescriptorDecodeErrorZ* operator ->() const { return &self; } }; +class CResult_RevokeAndACKDecodeErrorZ { +private: + LDKCResult_RevokeAndACKDecodeErrorZ self; +public: + CResult_RevokeAndACKDecodeErrorZ(const CResult_RevokeAndACKDecodeErrorZ&) = delete; + CResult_RevokeAndACKDecodeErrorZ(CResult_RevokeAndACKDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_RevokeAndACKDecodeErrorZ)); } + CResult_RevokeAndACKDecodeErrorZ(LDKCResult_RevokeAndACKDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_RevokeAndACKDecodeErrorZ)); } + operator LDKCResult_RevokeAndACKDecodeErrorZ() && { LDKCResult_RevokeAndACKDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_RevokeAndACKDecodeErrorZ)); return res; } + ~CResult_RevokeAndACKDecodeErrorZ() { CResult_RevokeAndACKDecodeErrorZ_free(self); } + CResult_RevokeAndACKDecodeErrorZ& operator=(CResult_RevokeAndACKDecodeErrorZ&& o) { CResult_RevokeAndACKDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_RevokeAndACKDecodeErrorZ)); return *this; } + LDKCResult_RevokeAndACKDecodeErrorZ* operator &() { return &self; } + LDKCResult_RevokeAndACKDecodeErrorZ* operator ->() { return &self; } + const LDKCResult_RevokeAndACKDecodeErrorZ* operator &() const { return &self; } + const LDKCResult_RevokeAndACKDecodeErrorZ* operator ->() const { return &self; } +}; class CResult_UnsignedChannelUpdateDecodeErrorZ { private: LDKCResult_UnsignedChannelUpdateDecodeErrorZ self; @@ -4012,6 +4012,21 @@ public: const LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* operator &() const { return &self; } const LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* operator ->() const { return &self; } }; +class CResult_PrivateRouteCreationErrorZ { +private: + LDKCResult_PrivateRouteCreationErrorZ self; +public: + CResult_PrivateRouteCreationErrorZ(const CResult_PrivateRouteCreationErrorZ&) = delete; + CResult_PrivateRouteCreationErrorZ(CResult_PrivateRouteCreationErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_PrivateRouteCreationErrorZ)); } + CResult_PrivateRouteCreationErrorZ(LDKCResult_PrivateRouteCreationErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_PrivateRouteCreationErrorZ)); } + operator LDKCResult_PrivateRouteCreationErrorZ() && { LDKCResult_PrivateRouteCreationErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_PrivateRouteCreationErrorZ)); return res; } + ~CResult_PrivateRouteCreationErrorZ() { CResult_PrivateRouteCreationErrorZ_free(self); } + CResult_PrivateRouteCreationErrorZ& operator=(CResult_PrivateRouteCreationErrorZ&& o) { CResult_PrivateRouteCreationErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_PrivateRouteCreationErrorZ)); return *this; } + LDKCResult_PrivateRouteCreationErrorZ* operator &() { return &self; } + LDKCResult_PrivateRouteCreationErrorZ* operator ->() { return &self; } + const LDKCResult_PrivateRouteCreationErrorZ* operator &() const { return &self; } + const LDKCResult_PrivateRouteCreationErrorZ* operator ->() const { return &self; } +}; class CResult_boolPeerHandleErrorZ { private: LDKCResult_boolPeerHandleErrorZ self; diff --git a/lightning-c-bindings/src/c_types/derived.rs b/lightning-c-bindings/src/c_types/derived.rs index 0e48f5d..33325e2 100644 --- a/lightning-c-bindings/src/c_types/derived.rs +++ b/lightning-c-bindings/src/c_types/derived.rs @@ -1661,29 +1661,29 @@ impl Clone for CVec_ChannelDetailsZ { } } #[repr(C)] -/// A dynamically-allocated array of crate::lightning::routing::router::RouteHintHops of arbitrary size. +/// A dynamically-allocated array of crate::lightning::routing::router::RouteHints of arbitrary size. /// This corresponds to std::vector in C++ -pub struct CVec_RouteHintHopZ { +pub struct CVec_RouteHintZ { /// The elements in the array. /// If datalen is non-0 this must be a valid, non-NULL pointer allocated by malloc(). - pub data: *mut crate::lightning::routing::router::RouteHintHop, + pub data: *mut crate::lightning::routing::router::RouteHint, /// The number of elements pointed to by `data`. pub datalen: usize } -impl CVec_RouteHintHopZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { +impl CVec_RouteHintZ { + #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { if self.datalen == 0 { return Vec::new(); } let ret = unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }.into(); self.data = std::ptr::null_mut(); self.datalen = 0; ret } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::lightning::routing::router::RouteHintHop] { + #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::lightning::routing::router::RouteHint] { unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } } } -impl From> for CVec_RouteHintHopZ { - fn from(v: Vec) -> Self { +impl From> for CVec_RouteHintZ { + fn from(v: Vec) -> Self { let datalen = v.len(); let data = Box::into_raw(v.into_boxed_slice()); Self { datalen, data: unsafe { (*data).as_mut_ptr() } } @@ -1691,14 +1691,14 @@ impl From> for CVec_RouteHi } #[no_mangle] /// Frees the buffer pointed to by `data` if `datalen` is non-0. -pub extern "C" fn CVec_RouteHintHopZ_free(_res: CVec_RouteHintHopZ) { } -impl Drop for CVec_RouteHintHopZ { +pub extern "C" fn CVec_RouteHintZ_free(_res: CVec_RouteHintZ) { } +impl Drop for CVec_RouteHintZ { fn drop(&mut self) { if self.datalen == 0 { return; } unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; } } -impl Clone for CVec_RouteHintHopZ { +impl Clone for CVec_RouteHintZ { fn clone(&self) -> Self { let mut res = Vec::new(); if self.datalen == 0 { return Self::from(res); } @@ -4957,29 +4957,29 @@ impl Clone for CResult_PayeePubKeyErrorZ { /// but with all dynamically-allocated buffers duplicated in new buffers. pub extern "C" fn CResult_PayeePubKeyErrorZ_clone(orig: &CResult_PayeePubKeyErrorZ) -> CResult_PayeePubKeyErrorZ { orig.clone() } #[repr(C)] -/// A dynamically-allocated array of crate::lightning_invoice::RouteHints of arbitrary size. +/// A dynamically-allocated array of crate::lightning_invoice::PrivateRoutes of arbitrary size. /// This corresponds to std::vector in C++ -pub struct CVec_RouteHintZ { +pub struct CVec_PrivateRouteZ { /// The elements in the array. /// If datalen is non-0 this must be a valid, non-NULL pointer allocated by malloc(). - pub data: *mut crate::lightning_invoice::RouteHint, + pub data: *mut crate::lightning_invoice::PrivateRoute, /// The number of elements pointed to by `data`. pub datalen: usize } -impl CVec_RouteHintZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { +impl CVec_PrivateRouteZ { + #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { if self.datalen == 0 { return Vec::new(); } let ret = unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }.into(); self.data = std::ptr::null_mut(); self.datalen = 0; ret } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::lightning_invoice::RouteHint] { + #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::lightning_invoice::PrivateRoute] { unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } } } -impl From> for CVec_RouteHintZ { - fn from(v: Vec) -> Self { +impl From> for CVec_PrivateRouteZ { + fn from(v: Vec) -> Self { let datalen = v.len(); let data = Box::into_raw(v.into_boxed_slice()); Self { datalen, data: unsafe { (*data).as_mut_ptr() } } @@ -4987,14 +4987,14 @@ impl From> for CVec_RouteHintZ { } #[no_mangle] /// Frees the buffer pointed to by `data` if `datalen` is non-0. -pub extern "C" fn CVec_RouteHintZ_free(_res: CVec_RouteHintZ) { } -impl Drop for CVec_RouteHintZ { +pub extern "C" fn CVec_PrivateRouteZ_free(_res: CVec_PrivateRouteZ) { } +impl Drop for CVec_PrivateRouteZ { fn drop(&mut self) { if self.datalen == 0 { return; } unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; } } -impl Clone for CVec_RouteHintZ { +impl Clone for CVec_PrivateRouteZ { fn clone(&self) -> Self { let mut res = Vec::new(); if self.datalen == 0 { return Self::from(res); } @@ -5454,50 +5454,50 @@ impl Clone for CResult_ExpiryTimeCreationErrorZ { /// but with all dynamically-allocated buffers duplicated in new buffers. pub extern "C" fn CResult_ExpiryTimeCreationErrorZ_clone(orig: &CResult_ExpiryTimeCreationErrorZ) -> CResult_ExpiryTimeCreationErrorZ { orig.clone() } #[repr(C)] -/// The contents of CResult_RouteHintCreationErrorZ -pub union CResult_RouteHintCreationErrorZPtr { +/// The contents of CResult_PrivateRouteCreationErrorZ +pub union CResult_PrivateRouteCreationErrorZPtr { /// A pointer to the contents in the success state. /// Reading from this pointer when `result_ok` is not set is undefined. - pub result: *mut crate::lightning_invoice::RouteHint, + pub result: *mut crate::lightning_invoice::PrivateRoute, /// A pointer to the contents in the error state. /// Reading from this pointer when `result_ok` is set is undefined. pub err: *mut crate::lightning_invoice::CreationError, } #[repr(C)] -/// A CResult_RouteHintCreationErrorZ represents the result of a fallible operation, -/// containing a crate::lightning_invoice::RouteHint on success and a crate::lightning_invoice::CreationError on failure. +/// A CResult_PrivateRouteCreationErrorZ represents the result of a fallible operation, +/// containing a crate::lightning_invoice::PrivateRoute on success and a crate::lightning_invoice::CreationError on failure. /// `result_ok` indicates the overall state, and the contents are provided via `contents`. -pub struct CResult_RouteHintCreationErrorZ { - /// The contents of this CResult_RouteHintCreationErrorZ, accessible via either +pub struct CResult_PrivateRouteCreationErrorZ { + /// The contents of this CResult_PrivateRouteCreationErrorZ, accessible via either /// `err` or `result` depending on the state of `result_ok`. - pub contents: CResult_RouteHintCreationErrorZPtr, - /// Whether this CResult_RouteHintCreationErrorZ represents a success state. + pub contents: CResult_PrivateRouteCreationErrorZPtr, + /// Whether this CResult_PrivateRouteCreationErrorZ represents a success state. pub result_ok: bool, } #[no_mangle] -/// Creates a new CResult_RouteHintCreationErrorZ in the success state. -pub extern "C" fn CResult_RouteHintCreationErrorZ_ok(o: crate::lightning_invoice::RouteHint) -> CResult_RouteHintCreationErrorZ { - CResult_RouteHintCreationErrorZ { - contents: CResult_RouteHintCreationErrorZPtr { +/// Creates a new CResult_PrivateRouteCreationErrorZ in the success state. +pub extern "C" fn CResult_PrivateRouteCreationErrorZ_ok(o: crate::lightning_invoice::PrivateRoute) -> CResult_PrivateRouteCreationErrorZ { + CResult_PrivateRouteCreationErrorZ { + contents: CResult_PrivateRouteCreationErrorZPtr { result: Box::into_raw(Box::new(o)), }, result_ok: true, } } #[no_mangle] -/// Creates a new CResult_RouteHintCreationErrorZ in the error state. -pub extern "C" fn CResult_RouteHintCreationErrorZ_err(e: crate::lightning_invoice::CreationError) -> CResult_RouteHintCreationErrorZ { - CResult_RouteHintCreationErrorZ { - contents: CResult_RouteHintCreationErrorZPtr { +/// Creates a new CResult_PrivateRouteCreationErrorZ in the error state. +pub extern "C" fn CResult_PrivateRouteCreationErrorZ_err(e: crate::lightning_invoice::CreationError) -> CResult_PrivateRouteCreationErrorZ { + CResult_PrivateRouteCreationErrorZ { + contents: CResult_PrivateRouteCreationErrorZPtr { err: Box::into_raw(Box::new(e)), }, result_ok: false, } } #[no_mangle] -/// Frees any resources used by the CResult_RouteHintCreationErrorZ. -pub extern "C" fn CResult_RouteHintCreationErrorZ_free(_res: CResult_RouteHintCreationErrorZ) { } -impl Drop for CResult_RouteHintCreationErrorZ { +/// Frees any resources used by the CResult_PrivateRouteCreationErrorZ. +pub extern "C" fn CResult_PrivateRouteCreationErrorZ_free(_res: CResult_PrivateRouteCreationErrorZ) { } +impl Drop for CResult_PrivateRouteCreationErrorZ { fn drop(&mut self) { if self.result_ok { if unsafe { !(self.contents.result as *mut ()).is_null() } { @@ -5510,16 +5510,16 @@ impl Drop for CResult_RouteHintCreationErrorZ { } } } -impl From> for CResult_RouteHintCreationErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { +impl From> for CResult_PrivateRouteCreationErrorZ { + fn from(mut o: crate::c_types::CResultTempl) -> Self { let contents = if o.result_ok { let result = unsafe { o.contents.result }; unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_RouteHintCreationErrorZPtr { result } + CResult_PrivateRouteCreationErrorZPtr { result } } else { let err = unsafe { o.contents.err }; unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_RouteHintCreationErrorZPtr { err } + CResult_PrivateRouteCreationErrorZPtr { err } }; Self { contents, @@ -5527,23 +5527,23 @@ impl From Self { if self.result_ok { - Self { result_ok: true, contents: CResult_RouteHintCreationErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) + Self { result_ok: true, contents: CResult_PrivateRouteCreationErrorZPtr { + result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) } } } else { - Self { result_ok: false, contents: CResult_RouteHintCreationErrorZPtr { + Self { result_ok: false, contents: CResult_PrivateRouteCreationErrorZPtr { err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) } } } } } #[no_mangle] -/// Creates a new CResult_RouteHintCreationErrorZ which has the same data as `orig` +/// Creates a new CResult_PrivateRouteCreationErrorZ which has the same data as `orig` /// but with all dynamically-allocated buffers duplicated in new buffers. -pub extern "C" fn CResult_RouteHintCreationErrorZ_clone(orig: &CResult_RouteHintCreationErrorZ) -> CResult_RouteHintCreationErrorZ { orig.clone() } +pub extern "C" fn CResult_PrivateRouteCreationErrorZ_clone(orig: &CResult_PrivateRouteCreationErrorZ) -> CResult_PrivateRouteCreationErrorZ { orig.clone() } #[repr(C)] /// The contents of CResult_StringErrorZ pub union CResult_StringErrorZPtr { diff --git a/lightning-c-bindings/src/lightning/chain/mod.rs b/lightning-c-bindings/src/lightning/chain/mod.rs index d2704fa..4879e7f 100644 --- a/lightning-c-bindings/src/lightning/chain/mod.rs +++ b/lightning-c-bindings/src/lightning/chain/mod.rs @@ -272,7 +272,7 @@ use lightning::chain::Confirm as rustConfirm; impl rustConfirm for Confirm { fn transactions_confirmed(&self, mut header: &bitcoin::blockdata::block::BlockHeader, mut txdata: &lightning::chain::transaction::TransactionData, mut height: u32) { let mut local_header = { let mut s = [0u8; 80]; s[..].copy_from_slice(&::bitcoin::consensus::encode::serialize(header)); s }; - let mut local_txdata = Vec::new(); for item in txdata.iter() { local_txdata.push( { let (mut orig_txdata_0_0, mut orig_txdata_0_1) = *item; let mut local_txdata_0 = (orig_txdata_0_0, crate::c_types::Transaction::from_bitcoin(&orig_txdata_0_1)).into(); local_txdata_0 }); }; + let mut local_txdata = Vec::new(); for item in txdata.iter() { local_txdata.push( { let (mut orig_txdata_0_0, mut orig_txdata_0_1) = item; let mut local_txdata_0 = (orig_txdata_0_0, crate::c_types::Transaction::from_bitcoin(&orig_txdata_0_1)).into(); local_txdata_0 }); }; (self.transactions_confirmed)(self.this_arg, &local_header, local_txdata.into(), height) } fn transaction_unconfirmed(&self, mut txid: &bitcoin::hash_types::Txid) { diff --git a/lightning-c-bindings/src/lightning/routing/router.rs b/lightning-c-bindings/src/lightning/routing/router.rs index 5ee9614..7022f50 100644 --- a/lightning-c-bindings/src/lightning/routing/router.rs +++ b/lightning-c-bindings/src/lightning/routing/router.rs @@ -287,10 +287,83 @@ pub extern "C" fn Route_read(ser: crate::c_types::u8slice) -> crate::c_types::de local_res } +use lightning::routing::router::RouteHint as nativeRouteHintImport; +type nativeRouteHint = nativeRouteHintImport; + +/// A list of hops along a payment path terminating with a channel to the recipient. +#[must_use] +#[repr(C)] +pub struct RouteHint { + /// A pointer to the opaque Rust object. + + /// Nearly everywhere, inner must be non-null, however in places where + /// the Rust equivalent takes an Option, it may be set to null to indicate None. + pub inner: *mut nativeRouteHint, + /// Indicates that this is the only struct which contains the same pointer. + + /// Rust functions which take ownership of an object provided via an argument require + /// this to be true and invalidate the object pointed to by inner. + pub is_owned: bool, +} + +impl Drop for RouteHint { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeRouteHint>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(self.inner) }; + } + } +} +/// Frees any resources used by the RouteHint, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn RouteHint_free(this_obj: RouteHint) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +extern "C" fn RouteHint_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRouteHint); } +} +#[allow(unused)] +/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy +impl RouteHint { + pub(crate) fn take_inner(mut self) -> *mut nativeRouteHint { + assert!(self.is_owned); + let ret = self.inner; + self.inner = std::ptr::null_mut(); + ret + } +} +/// Checks if two RouteHints contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn RouteHint_eq(a: &RouteHint, b: &RouteHint) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false } +} +impl Clone for RouteHint { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeRouteHint>::is_null(self.inner) { std::ptr::null_mut() } else { + Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, + is_owned: true, + } + } +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn RouteHint_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHint)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the RouteHint +pub extern "C" fn RouteHint_clone(orig: &RouteHint) -> RouteHint { + orig.clone() +} + use lightning::routing::router::RouteHintHop as nativeRouteHintHopImport; type nativeRouteHintHop = nativeRouteHintHopImport; -/// A channel descriptor which provides a last-hop route to get_route +/// A channel descriptor for a hop along a payment path. #[must_use] #[repr(C)] pub struct RouteHintHop { @@ -449,8 +522,8 @@ pub extern "C" fn RouteHintHop_clone(orig: &RouteHintHop) -> RouteHintHop { /// If the payee provided features in their invoice, they should be provided via payee_features. /// Without this, MPP will only be used if the payee's features are available in the network graph. /// -/// Extra routing hops between known nodes and the target will be used if they are included in -/// last_hops. +/// Private routing paths between a public node and the target may be included in `last_hops`. +/// Currently, only the last hop in each path is considered. /// /// If some channels aren't announced, it may be useful to fill in a first_hops with the /// results from a local ChannelManager::list_usable_channels() call. If it is filled in, our @@ -464,7 +537,7 @@ pub extern "C" fn RouteHintHop_clone(orig: &RouteHintHop) -> RouteHintHop { /// equal), however the enabled/disabled bit on such channels as well as the /// htlc_minimum_msat/htlc_maximum_msat *are* checked as they may change based on the receiving node. #[no_mangle] -pub extern "C" fn get_route(mut our_node_id: crate::c_types::PublicKey, network: &crate::lightning::routing::network_graph::NetworkGraph, mut payee: crate::c_types::PublicKey, mut payee_features: crate::lightning::ln::features::InvoiceFeatures, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut last_hops: crate::c_types::derived::CVec_RouteHintHopZ, mut final_value_msat: u64, mut final_cltv: u32, mut logger: crate::lightning::util::logger::Logger) -> crate::c_types::derived::CResult_RouteLightningErrorZ { +pub extern "C" fn get_route(mut our_node_id: crate::c_types::PublicKey, network: &crate::lightning::routing::network_graph::NetworkGraph, mut payee: crate::c_types::PublicKey, mut payee_features: crate::lightning::ln::features::InvoiceFeatures, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut last_hops: crate::c_types::derived::CVec_RouteHintZ, mut final_value_msat: u64, mut final_cltv: u32, mut logger: crate::lightning::util::logger::Logger) -> crate::c_types::derived::CResult_RouteLightningErrorZ { let mut local_payee_features = if payee_features.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(payee_features.take_inner()) } }) }; let mut local_first_hops_base = if first_hops == std::ptr::null_mut() { None } else { Some( { let mut local_first_hops_0 = Vec::new(); for mut item in unsafe { &mut *first_hops }.as_slice().iter() { local_first_hops_0.push( { unsafe { &*item.inner } }); }; local_first_hops_0 }) }; let mut local_first_hops = local_first_hops_base.as_ref().map(|a| &a[..]); let mut local_last_hops = Vec::new(); for mut item in last_hops.as_slice().iter() { local_last_hops.push( { unsafe { &*item.inner } }); }; diff --git a/lightning-c-bindings/src/lightning_invoice/constants.rs b/lightning-c-bindings/src/lightning_invoice/constants.rs index d4e2e85..a821291 100644 --- a/lightning-c-bindings/src/lightning_invoice/constants.rs +++ b/lightning-c-bindings/src/lightning_invoice/constants.rs @@ -36,7 +36,7 @@ pub static TAG_MIN_FINAL_CLTV_EXPIRY: u8 = lightning_invoice::constants::TAG_MIN pub static TAG_FALLBACK: u8 = lightning_invoice::constants::TAG_FALLBACK; #[no_mangle] -pub static TAG_ROUTE: u8 = lightning_invoice::constants::TAG_ROUTE; +pub static TAG_PRIVATE_ROUTE: u8 = lightning_invoice::constants::TAG_PRIVATE_ROUTE; #[no_mangle] pub static TAG_PAYMENT_SECRET: u8 = lightning_invoice::constants::TAG_PAYMENT_SECRET; diff --git a/lightning-c-bindings/src/lightning_invoice/mod.rs b/lightning-c-bindings/src/lightning_invoice/mod.rs index ef1bb7b..eaa9aab 100644 --- a/lightning-c-bindings/src/lightning_invoice/mod.rs +++ b/lightning-c-bindings/src/lightning_invoice/mod.rs @@ -1249,8 +1249,8 @@ pub extern "C" fn InvoiceSignature_clone(orig: &InvoiceSignature) -> InvoiceSign orig.clone() } -use lightning_invoice::RouteHint as nativeRouteHintImport; -type nativeRouteHint = nativeRouteHintImport; +use lightning_invoice::PrivateRoute as nativePrivateRouteImport; +type nativePrivateRoute = nativePrivateRouteImport; /// Private routing information /// @@ -1259,12 +1259,12 @@ type nativeRouteHint = nativeRouteHintImport; /// #[must_use] #[repr(C)] -pub struct RouteHint { +pub struct PrivateRoute { /// A pointer to the opaque Rust object. /// Nearly everywhere, inner must be non-null, however in places where /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeRouteHint, + pub inner: *mut nativePrivateRoute, /// Indicates that this is the only struct which contains the same pointer. /// Rust functions which take ownership of an object provided via an argument require @@ -1272,44 +1272,44 @@ pub struct RouteHint { pub is_owned: bool, } -impl Drop for RouteHint { +impl Drop for PrivateRoute { fn drop(&mut self) { - if self.is_owned && !<*mut nativeRouteHint>::is_null(self.inner) { + if self.is_owned && !<*mut nativePrivateRoute>::is_null(self.inner) { let _ = unsafe { Box::from_raw(self.inner) }; } } } -/// Frees any resources used by the RouteHint, if is_owned is set and inner is non-NULL. +/// Frees any resources used by the PrivateRoute, if is_owned is set and inner is non-NULL. #[no_mangle] -pub extern "C" fn RouteHint_free(this_obj: RouteHint) { } +pub extern "C" fn PrivateRoute_free(this_obj: PrivateRoute) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn RouteHint_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRouteHint); } +extern "C" fn PrivateRoute_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativePrivateRoute); } } #[allow(unused)] /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl RouteHint { - pub(crate) fn take_inner(mut self) -> *mut nativeRouteHint { +impl PrivateRoute { + pub(crate) fn take_inner(mut self) -> *mut nativePrivateRoute { assert!(self.is_owned); let ret = self.inner; self.inner = std::ptr::null_mut(); ret } } -/// Checks if two RouteHints contain equal inner contents. +/// Checks if two PrivateRoutes contain equal inner contents. /// This ignores pointers and is_owned flags and looks at the values in fields. /// Two objects with NULL inner values will be considered "equal" here. #[no_mangle] -pub extern "C" fn RouteHint_eq(a: &RouteHint, b: &RouteHint) -> bool { +pub extern "C" fn PrivateRoute_eq(a: &PrivateRoute, b: &PrivateRoute) -> bool { if a.inner == b.inner { return true; } if a.inner.is_null() || b.inner.is_null() { return false; } if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false } } -impl Clone for RouteHint { +impl Clone for PrivateRoute { fn clone(&self) -> Self { Self { - inner: if <*mut nativeRouteHint>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativePrivateRoute>::is_null(self.inner) { std::ptr::null_mut() } else { Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, is_owned: true, } @@ -1317,12 +1317,12 @@ impl Clone for RouteHint { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn RouteHint_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHint)).clone() })) as *mut c_void +pub(crate) extern "C" fn PrivateRoute_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePrivateRoute)).clone() })) as *mut c_void } #[no_mangle] -/// Creates a copy of the RouteHint -pub extern "C" fn RouteHint_clone(orig: &RouteHint) -> RouteHint { +/// Creates a copy of the PrivateRoute +pub extern "C" fn PrivateRoute_clone(orig: &PrivateRoute) -> PrivateRoute { orig.clone() } /// Disassembles the `SignedRawInvoice` into its three parts: @@ -1453,9 +1453,9 @@ pub extern "C" fn RawInvoice_features(this_arg: &RawInvoice) -> crate::lightning #[must_use] #[no_mangle] -pub extern "C" fn RawInvoice_routes(this_arg: &RawInvoice) -> crate::c_types::derived::CVec_RouteHintZ { - let mut ret = unsafe { &*this_arg.inner }.routes(); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::RouteHint { inner: unsafe { ( (&(**item) as *const _) as *mut _) }, is_owned: false } }); }; +pub extern "C" fn RawInvoice_private_routes(this_arg: &RawInvoice) -> crate::c_types::derived::CVec_PrivateRouteZ { + let mut ret = unsafe { &*this_arg.inner }.private_routes(); + let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::PrivateRoute { inner: unsafe { ( (&(*item) as *const _) as *mut _) }, is_owned: false } }); }; local_ret.into() } @@ -1529,7 +1529,7 @@ pub extern "C" fn Invoice_check_signature(this_arg: &Invoice) -> crate::c_types: local_ret } -/// Constructs an `Invoice` from a `SignedInvoice` by checking all its invariants. +/// Constructs an `Invoice` from a `SignedRawInvoice` by checking all its invariants. /// ``` /// use lightning_invoice::*; /// @@ -1621,9 +1621,18 @@ pub extern "C" fn Invoice_min_final_cltv_expiry(this_arg: &Invoice) -> u64 { /// Returns a list of all routes included in the invoice #[must_use] #[no_mangle] -pub extern "C" fn Invoice_routes(this_arg: &Invoice) -> crate::c_types::derived::CVec_RouteHintZ { - let mut ret = unsafe { &*this_arg.inner }.routes(); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::RouteHint { inner: unsafe { ( (&(**item) as *const _) as *mut _) }, is_owned: false } }); }; +pub extern "C" fn Invoice_private_routes(this_arg: &Invoice) -> crate::c_types::derived::CVec_PrivateRouteZ { + let mut ret = unsafe { &*this_arg.inner }.private_routes(); + let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::PrivateRoute { inner: unsafe { ( (&(*item) as *const _) as *mut _) }, is_owned: false } }); }; + local_ret.into() +} + +/// Returns a list of all routes included in the invoice as the underlying hints +#[must_use] +#[no_mangle] +pub extern "C" fn Invoice_route_hints(this_arg: &Invoice) -> crate::c_types::derived::CVec_RouteHintZ { + let mut ret = unsafe { &*this_arg.inner }.route_hints(); + let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::routing::router::RouteHint { inner: unsafe { ( (&(*item) as *const _) as *mut _) }, is_owned: false } }); }; local_ret.into() } @@ -1702,23 +1711,21 @@ pub extern "C" fn ExpiryTime_as_duration(this_arg: &ExpiryTime) -> u64 { ret.as_secs() } -/// Create a new (partial) route from a list of hops +/// Creates a new (partial) route from a list of hops #[must_use] #[no_mangle] -pub extern "C" fn RouteHint_new(mut hops: crate::c_types::derived::CVec_RouteHintHopZ) -> crate::c_types::derived::CResult_RouteHintCreationErrorZ { - let mut local_hops = Vec::new(); for mut item in hops.into_rust().drain(..) { local_hops.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; - let mut ret = lightning_invoice::RouteHint::new(local_hops); - let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::RouteHint { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() }; +pub extern "C" fn PrivateRoute_new(mut hops: crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CResult_PrivateRouteCreationErrorZ { + let mut ret = lightning_invoice::PrivateRoute::new(*unsafe { Box::from_raw(hops.take_inner()) }); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PrivateRoute { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() }; local_ret } -/// Returrn the underlying vector of hops +/// Returns the underlying list of hops #[must_use] #[no_mangle] -pub extern "C" fn RouteHint_into_inner(mut this_arg: RouteHint) -> crate::c_types::derived::CVec_RouteHintHopZ { +pub extern "C" fn PrivateRoute_into_inner(mut this_arg: PrivateRoute) -> crate::lightning::routing::router::RouteHint { let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner(); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::routing::router::RouteHintHop { inner: Box::into_raw(Box::new(item)), is_owned: true } }); }; - local_ret.into() + crate::lightning::routing::router::RouteHint { inner: Box::into_raw(Box::new(ret)), is_owned: true } } /// Errors that may occur when constructing a new `RawInvoice` or `Invoice` -- 2.30.2