From c0d6da5234279514641ccbd4355e8d6238562761 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 25 Nov 2020 13:26:53 -0500 Subject: [PATCH] - bindings diff --- lightning-c-bindings/include/lightningpp.hpp | 234 +++-- lightning-c-bindings/include/rust_types.h | 14 +- lightning-c-bindings/src/c_types/derived.rs | 58 +- .../src/chain/chainmonitor.rs | 20 + .../src/chain/channelmonitor.rs | 14 + .../src/chain/keysinterface.rs | 179 +++- lightning-c-bindings/src/chain/mod.rs | 2 +- lightning-c-bindings/src/chain/transaction.rs | 4 + lightning-c-bindings/src/ln/chan_utils.rs | 902 ++++++++++++++---- lightning-c-bindings/src/ln/channelmanager.rs | 36 +- lightning-c-bindings/src/ln/msgs.rs | 185 +++- .../src/routing/network_graph.rs | 125 ++- lightning-c-bindings/src/routing/router.rs | 4 + lightning-c-bindings/src/util/config.rs | 4 + lightning-c-bindings/src/util/events.rs | 67 ++ lightning-c-bindings/src/util/ser.rs | 3 + 16 files changed, 1505 insertions(+), 346 deletions(-) diff --git a/lightning-c-bindings/include/lightningpp.hpp b/lightning-c-bindings/include/lightningpp.hpp index 5f8b77f3f..b313d1fd3 100644 --- a/lightning-c-bindings/include/lightningpp.hpp +++ b/lightning-c-bindings/include/lightningpp.hpp @@ -1130,20 +1130,6 @@ public: const LDKTxCreationKeys* operator &() const { return &self; } const LDKTxCreationKeys* operator ->() const { return &self; } }; -class PreCalculatedTxCreationKeys { -private: - LDKPreCalculatedTxCreationKeys self; -public: - PreCalculatedTxCreationKeys(const PreCalculatedTxCreationKeys&) = delete; - ~PreCalculatedTxCreationKeys() { PreCalculatedTxCreationKeys_free(self); } - PreCalculatedTxCreationKeys(PreCalculatedTxCreationKeys&& o) : self(o.self) { memset(&o, 0, sizeof(PreCalculatedTxCreationKeys)); } - PreCalculatedTxCreationKeys(LDKPreCalculatedTxCreationKeys&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKPreCalculatedTxCreationKeys)); } - operator LDKPreCalculatedTxCreationKeys() { LDKPreCalculatedTxCreationKeys res = self; memset(&self, 0, sizeof(LDKPreCalculatedTxCreationKeys)); return res; } - LDKPreCalculatedTxCreationKeys* operator &() { return &self; } - LDKPreCalculatedTxCreationKeys* operator ->() { return &self; } - const LDKPreCalculatedTxCreationKeys* operator &() const { return &self; } - const LDKPreCalculatedTxCreationKeys* operator ->() const { return &self; } -}; class ChannelPublicKeys { private: LDKChannelPublicKeys self; @@ -1172,6 +1158,48 @@ public: const LDKHTLCOutputInCommitment* operator &() const { return &self; } const LDKHTLCOutputInCommitment* operator ->() const { return &self; } }; +class ChannelTransactionParameters { +private: + LDKChannelTransactionParameters self; +public: + ChannelTransactionParameters(const ChannelTransactionParameters&) = delete; + ~ChannelTransactionParameters() { ChannelTransactionParameters_free(self); } + ChannelTransactionParameters(ChannelTransactionParameters&& o) : self(o.self) { memset(&o, 0, sizeof(ChannelTransactionParameters)); } + ChannelTransactionParameters(LDKChannelTransactionParameters&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKChannelTransactionParameters)); } + operator LDKChannelTransactionParameters() { LDKChannelTransactionParameters res = self; memset(&self, 0, sizeof(LDKChannelTransactionParameters)); return res; } + LDKChannelTransactionParameters* operator &() { return &self; } + LDKChannelTransactionParameters* operator ->() { return &self; } + const LDKChannelTransactionParameters* operator &() const { return &self; } + const LDKChannelTransactionParameters* operator ->() const { return &self; } +}; +class CounterpartyChannelTransactionParameters { +private: + LDKCounterpartyChannelTransactionParameters self; +public: + CounterpartyChannelTransactionParameters(const CounterpartyChannelTransactionParameters&) = delete; + ~CounterpartyChannelTransactionParameters() { CounterpartyChannelTransactionParameters_free(self); } + CounterpartyChannelTransactionParameters(CounterpartyChannelTransactionParameters&& o) : self(o.self) { memset(&o, 0, sizeof(CounterpartyChannelTransactionParameters)); } + CounterpartyChannelTransactionParameters(LDKCounterpartyChannelTransactionParameters&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCounterpartyChannelTransactionParameters)); } + operator LDKCounterpartyChannelTransactionParameters() { LDKCounterpartyChannelTransactionParameters res = self; memset(&self, 0, sizeof(LDKCounterpartyChannelTransactionParameters)); return res; } + LDKCounterpartyChannelTransactionParameters* operator &() { return &self; } + LDKCounterpartyChannelTransactionParameters* operator ->() { return &self; } + const LDKCounterpartyChannelTransactionParameters* operator &() const { return &self; } + const LDKCounterpartyChannelTransactionParameters* operator ->() const { return &self; } +}; +class DirectedChannelTransactionParameters { +private: + LDKDirectedChannelTransactionParameters self; +public: + DirectedChannelTransactionParameters(const DirectedChannelTransactionParameters&) = delete; + ~DirectedChannelTransactionParameters() { DirectedChannelTransactionParameters_free(self); } + DirectedChannelTransactionParameters(DirectedChannelTransactionParameters&& o) : self(o.self) { memset(&o, 0, sizeof(DirectedChannelTransactionParameters)); } + DirectedChannelTransactionParameters(LDKDirectedChannelTransactionParameters&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKDirectedChannelTransactionParameters)); } + operator LDKDirectedChannelTransactionParameters() { LDKDirectedChannelTransactionParameters res = self; memset(&self, 0, sizeof(LDKDirectedChannelTransactionParameters)); return res; } + LDKDirectedChannelTransactionParameters* operator &() { return &self; } + LDKDirectedChannelTransactionParameters* operator ->() { return &self; } + const LDKDirectedChannelTransactionParameters* operator &() const { return &self; } + const LDKDirectedChannelTransactionParameters* operator ->() const { return &self; } +}; class HolderCommitmentTransaction { private: LDKHolderCommitmentTransaction self; @@ -1186,6 +1214,48 @@ public: const LDKHolderCommitmentTransaction* operator &() const { return &self; } const LDKHolderCommitmentTransaction* operator ->() const { return &self; } }; +class BuiltCommitmentTransaction { +private: + LDKBuiltCommitmentTransaction self; +public: + BuiltCommitmentTransaction(const BuiltCommitmentTransaction&) = delete; + ~BuiltCommitmentTransaction() { BuiltCommitmentTransaction_free(self); } + BuiltCommitmentTransaction(BuiltCommitmentTransaction&& o) : self(o.self) { memset(&o, 0, sizeof(BuiltCommitmentTransaction)); } + BuiltCommitmentTransaction(LDKBuiltCommitmentTransaction&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKBuiltCommitmentTransaction)); } + operator LDKBuiltCommitmentTransaction() { LDKBuiltCommitmentTransaction res = self; memset(&self, 0, sizeof(LDKBuiltCommitmentTransaction)); return res; } + LDKBuiltCommitmentTransaction* operator &() { return &self; } + LDKBuiltCommitmentTransaction* operator ->() { return &self; } + const LDKBuiltCommitmentTransaction* operator &() const { return &self; } + const LDKBuiltCommitmentTransaction* operator ->() const { return &self; } +}; +class CommitmentTransaction { +private: + LDKCommitmentTransaction self; +public: + CommitmentTransaction(const CommitmentTransaction&) = delete; + ~CommitmentTransaction() { CommitmentTransaction_free(self); } + CommitmentTransaction(CommitmentTransaction&& o) : self(o.self) { memset(&o, 0, sizeof(CommitmentTransaction)); } + CommitmentTransaction(LDKCommitmentTransaction&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCommitmentTransaction)); } + operator LDKCommitmentTransaction() { LDKCommitmentTransaction res = self; memset(&self, 0, sizeof(LDKCommitmentTransaction)); return res; } + LDKCommitmentTransaction* operator &() { return &self; } + LDKCommitmentTransaction* operator ->() { return &self; } + const LDKCommitmentTransaction* operator &() const { return &self; } + const LDKCommitmentTransaction* operator ->() const { return &self; } +}; +class TrustedCommitmentTransaction { +private: + LDKTrustedCommitmentTransaction self; +public: + TrustedCommitmentTransaction(const TrustedCommitmentTransaction&) = delete; + ~TrustedCommitmentTransaction() { TrustedCommitmentTransaction_free(self); } + TrustedCommitmentTransaction(TrustedCommitmentTransaction&& o) : self(o.self) { memset(&o, 0, sizeof(TrustedCommitmentTransaction)); } + TrustedCommitmentTransaction(LDKTrustedCommitmentTransaction&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKTrustedCommitmentTransaction)); } + operator LDKTrustedCommitmentTransaction() { LDKTrustedCommitmentTransaction res = self; memset(&self, 0, sizeof(LDKTrustedCommitmentTransaction)); return res; } + LDKTrustedCommitmentTransaction* operator &() { return &self; } + LDKTrustedCommitmentTransaction* operator ->() { return &self; } + const LDKTrustedCommitmentTransaction* operator &() const { return &self; } + const LDKTrustedCommitmentTransaction* operator ->() const { return &self; } +}; class InitFeatures { private: LDKInitFeatures self; @@ -1424,20 +1494,6 @@ public: const LDKC2Tuple_u32TxOutZ* operator &() const { return &self; } const LDKC2Tuple_u32TxOutZ* operator ->() const { return &self; } }; -class CResult_NoneMonitorUpdateErrorZ { -private: - LDKCResult_NoneMonitorUpdateErrorZ self; -public: - CResult_NoneMonitorUpdateErrorZ(const CResult_NoneMonitorUpdateErrorZ&) = delete; - ~CResult_NoneMonitorUpdateErrorZ() { CResult_NoneMonitorUpdateErrorZ_free(self); } - CResult_NoneMonitorUpdateErrorZ(CResult_NoneMonitorUpdateErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_NoneMonitorUpdateErrorZ)); } - CResult_NoneMonitorUpdateErrorZ(LDKCResult_NoneMonitorUpdateErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_NoneMonitorUpdateErrorZ)); } - operator LDKCResult_NoneMonitorUpdateErrorZ() { LDKCResult_NoneMonitorUpdateErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_NoneMonitorUpdateErrorZ)); return res; } - LDKCResult_NoneMonitorUpdateErrorZ* operator &() { return &self; } - LDKCResult_NoneMonitorUpdateErrorZ* operator ->() { return &self; } - const LDKCResult_NoneMonitorUpdateErrorZ* operator &() const { return &self; } - const LDKCResult_NoneMonitorUpdateErrorZ* operator ->() const { return &self; } -}; class CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ { private: LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ self; @@ -1564,20 +1620,6 @@ public: const LDKCResult_SecretKeySecpErrorZ* operator &() const { return &self; } const LDKCResult_SecretKeySecpErrorZ* operator ->() const { return &self; } }; -class C2Tuple_HTLCOutputInCommitmentSignatureZ { -private: - LDKC2Tuple_HTLCOutputInCommitmentSignatureZ self; -public: - C2Tuple_HTLCOutputInCommitmentSignatureZ(const C2Tuple_HTLCOutputInCommitmentSignatureZ&) = delete; - ~C2Tuple_HTLCOutputInCommitmentSignatureZ() { C2Tuple_HTLCOutputInCommitmentSignatureZ_free(self); } - C2Tuple_HTLCOutputInCommitmentSignatureZ(C2Tuple_HTLCOutputInCommitmentSignatureZ&& o) : self(o.self) { memset(&o, 0, sizeof(C2Tuple_HTLCOutputInCommitmentSignatureZ)); } - C2Tuple_HTLCOutputInCommitmentSignatureZ(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ)); } - operator LDKC2Tuple_HTLCOutputInCommitmentSignatureZ() { LDKC2Tuple_HTLCOutputInCommitmentSignatureZ res = self; memset(&self, 0, sizeof(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ)); return res; } - LDKC2Tuple_HTLCOutputInCommitmentSignatureZ* operator &() { return &self; } - LDKC2Tuple_HTLCOutputInCommitmentSignatureZ* operator ->() { return &self; } - const LDKC2Tuple_HTLCOutputInCommitmentSignatureZ* operator &() const { return &self; } - const LDKC2Tuple_HTLCOutputInCommitmentSignatureZ* operator ->() const { return &self; } -}; class CVec_EventZ { private: LDKCVec_EventZ self; @@ -1620,6 +1662,20 @@ public: const LDKCVec_MonitorEventZ* operator &() const { return &self; } const LDKCVec_MonitorEventZ* operator ->() const { return &self; } }; +class CResult_ChanKeySignerDecodeErrorZ { +private: + LDKCResult_ChanKeySignerDecodeErrorZ self; +public: + CResult_ChanKeySignerDecodeErrorZ(const CResult_ChanKeySignerDecodeErrorZ&) = delete; + ~CResult_ChanKeySignerDecodeErrorZ() { CResult_ChanKeySignerDecodeErrorZ_free(self); } + CResult_ChanKeySignerDecodeErrorZ(CResult_ChanKeySignerDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_ChanKeySignerDecodeErrorZ)); } + CResult_ChanKeySignerDecodeErrorZ(LDKCResult_ChanKeySignerDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_ChanKeySignerDecodeErrorZ)); } + operator LDKCResult_ChanKeySignerDecodeErrorZ() { LDKCResult_ChanKeySignerDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_ChanKeySignerDecodeErrorZ)); return res; } + LDKCResult_ChanKeySignerDecodeErrorZ* operator &() { return &self; } + LDKCResult_ChanKeySignerDecodeErrorZ* operator ->() { return &self; } + const LDKCResult_ChanKeySignerDecodeErrorZ* operator &() const { return &self; } + const LDKCResult_ChanKeySignerDecodeErrorZ* operator ->() const { return &self; } +}; class CVec_RouteHopZ { private: LDKCVec_RouteHopZ self; @@ -1718,19 +1774,19 @@ public: const LDKCResult_PublicKeySecpErrorZ* operator &() const { return &self; } const LDKCResult_PublicKeySecpErrorZ* operator ->() const { return &self; } }; -class CVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ { +class CVec_RouteHintZ { private: - LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ self; + LDKCVec_RouteHintZ self; public: - CVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ(const CVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ&) = delete; - ~CVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ() { CVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ_free(self); } - CVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ(CVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ)); } - CVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ(LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ)); } - operator LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ() { LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ res = self; memset(&self, 0, sizeof(LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ)); return res; } - LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ* operator &() { return &self; } - LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ* operator ->() { return &self; } - const LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ* operator &() const { return &self; } - const LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ* operator ->() const { return &self; } + CVec_RouteHintZ(const CVec_RouteHintZ&) = delete; + ~CVec_RouteHintZ() { CVec_RouteHintZ_free(self); } + CVec_RouteHintZ(CVec_RouteHintZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_RouteHintZ)); } + CVec_RouteHintZ(LDKCVec_RouteHintZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_RouteHintZ)); } + operator LDKCVec_RouteHintZ() { LDKCVec_RouteHintZ res = self; memset(&self, 0, sizeof(LDKCVec_RouteHintZ)); return res; } + LDKCVec_RouteHintZ* operator &() { return &self; } + LDKCVec_RouteHintZ* operator ->() { return &self; } + const LDKCVec_RouteHintZ* operator &() const { return &self; } + const LDKCVec_RouteHintZ* operator ->() const { return &self; } }; class C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ { private: @@ -1774,6 +1830,20 @@ public: const LDKCVec_UpdateAddHTLCZ* operator &() const { return &self; } const LDKCVec_UpdateAddHTLCZ* operator ->() const { return &self; } }; +class CResult_NoneLightningErrorZ { +private: + LDKCResult_NoneLightningErrorZ self; +public: + CResult_NoneLightningErrorZ(const CResult_NoneLightningErrorZ&) = delete; + ~CResult_NoneLightningErrorZ() { CResult_NoneLightningErrorZ_free(self); } + CResult_NoneLightningErrorZ(CResult_NoneLightningErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_NoneLightningErrorZ)); } + CResult_NoneLightningErrorZ(LDKCResult_NoneLightningErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_NoneLightningErrorZ)); } + operator LDKCResult_NoneLightningErrorZ() { LDKCResult_NoneLightningErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_NoneLightningErrorZ)); return res; } + LDKCResult_NoneLightningErrorZ* operator &() { return &self; } + LDKCResult_NoneLightningErrorZ* operator ->() { return &self; } + const LDKCResult_NoneLightningErrorZ* operator &() const { return &self; } + const LDKCResult_NoneLightningErrorZ* operator ->() const { return &self; } +}; class CResult_NonePeerHandleErrorZ { private: LDKCResult_NonePeerHandleErrorZ self; @@ -1802,19 +1872,19 @@ public: const LDKCResult_boolPeerHandleErrorZ* operator &() const { return &self; } const LDKCResult_boolPeerHandleErrorZ* operator ->() const { return &self; } }; -class CVec_RouteHintZ { +class CResult_TrustedCommitmentTransactionNoneZ { private: - LDKCVec_RouteHintZ self; + LDKCResult_TrustedCommitmentTransactionNoneZ self; public: - CVec_RouteHintZ(const CVec_RouteHintZ&) = delete; - ~CVec_RouteHintZ() { CVec_RouteHintZ_free(self); } - CVec_RouteHintZ(CVec_RouteHintZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_RouteHintZ)); } - CVec_RouteHintZ(LDKCVec_RouteHintZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_RouteHintZ)); } - operator LDKCVec_RouteHintZ() { LDKCVec_RouteHintZ res = self; memset(&self, 0, sizeof(LDKCVec_RouteHintZ)); return res; } - LDKCVec_RouteHintZ* operator &() { return &self; } - LDKCVec_RouteHintZ* operator ->() { return &self; } - const LDKCVec_RouteHintZ* operator &() const { return &self; } - const LDKCVec_RouteHintZ* operator ->() const { return &self; } + CResult_TrustedCommitmentTransactionNoneZ(const CResult_TrustedCommitmentTransactionNoneZ&) = delete; + ~CResult_TrustedCommitmentTransactionNoneZ() { CResult_TrustedCommitmentTransactionNoneZ_free(self); } + CResult_TrustedCommitmentTransactionNoneZ(CResult_TrustedCommitmentTransactionNoneZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_TrustedCommitmentTransactionNoneZ)); } + CResult_TrustedCommitmentTransactionNoneZ(LDKCResult_TrustedCommitmentTransactionNoneZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_TrustedCommitmentTransactionNoneZ)); } + operator LDKCResult_TrustedCommitmentTransactionNoneZ() { LDKCResult_TrustedCommitmentTransactionNoneZ res = self; memset(&self, 0, sizeof(LDKCResult_TrustedCommitmentTransactionNoneZ)); return res; } + LDKCResult_TrustedCommitmentTransactionNoneZ* operator &() { return &self; } + LDKCResult_TrustedCommitmentTransactionNoneZ* operator ->() { return &self; } + const LDKCResult_TrustedCommitmentTransactionNoneZ* operator &() const { return &self; } + const LDKCResult_TrustedCommitmentTransactionNoneZ* operator ->() const { return &self; } }; class CResult_RouteLightningErrorZ { private: @@ -1830,20 +1900,6 @@ public: const LDKCResult_RouteLightningErrorZ* operator &() const { return &self; } const LDKCResult_RouteLightningErrorZ* operator ->() const { return &self; } }; -class CResult_NoneLightningErrorZ { -private: - LDKCResult_NoneLightningErrorZ self; -public: - CResult_NoneLightningErrorZ(const CResult_NoneLightningErrorZ&) = delete; - ~CResult_NoneLightningErrorZ() { CResult_NoneLightningErrorZ_free(self); } - CResult_NoneLightningErrorZ(CResult_NoneLightningErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_NoneLightningErrorZ)); } - CResult_NoneLightningErrorZ(LDKCResult_NoneLightningErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_NoneLightningErrorZ)); } - operator LDKCResult_NoneLightningErrorZ() { LDKCResult_NoneLightningErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_NoneLightningErrorZ)); return res; } - LDKCResult_NoneLightningErrorZ* operator &() { return &self; } - LDKCResult_NoneLightningErrorZ* operator ->() { return &self; } - const LDKCResult_NoneLightningErrorZ* operator &() const { return &self; } - const LDKCResult_NoneLightningErrorZ* operator ->() const { return &self; } -}; class CResult_CVec_SignatureZNoneZ { private: LDKCResult_CVec_SignatureZNoneZ self; @@ -2082,18 +2138,18 @@ public: const LDKC2Tuple_u64u64Z* operator &() const { return &self; } const LDKC2Tuple_u64u64Z* operator ->() const { return &self; } }; -class CVec_HTLCOutputInCommitmentZ { +class CResult_NoneMonitorUpdateErrorZ { private: - LDKCVec_HTLCOutputInCommitmentZ self; + LDKCResult_NoneMonitorUpdateErrorZ self; public: - CVec_HTLCOutputInCommitmentZ(const CVec_HTLCOutputInCommitmentZ&) = delete; - ~CVec_HTLCOutputInCommitmentZ() { CVec_HTLCOutputInCommitmentZ_free(self); } - CVec_HTLCOutputInCommitmentZ(CVec_HTLCOutputInCommitmentZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_HTLCOutputInCommitmentZ)); } - CVec_HTLCOutputInCommitmentZ(LDKCVec_HTLCOutputInCommitmentZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_HTLCOutputInCommitmentZ)); } - operator LDKCVec_HTLCOutputInCommitmentZ() { LDKCVec_HTLCOutputInCommitmentZ res = self; memset(&self, 0, sizeof(LDKCVec_HTLCOutputInCommitmentZ)); return res; } - LDKCVec_HTLCOutputInCommitmentZ* operator &() { return &self; } - LDKCVec_HTLCOutputInCommitmentZ* operator ->() { return &self; } - const LDKCVec_HTLCOutputInCommitmentZ* operator &() const { return &self; } - const LDKCVec_HTLCOutputInCommitmentZ* operator ->() const { return &self; } + CResult_NoneMonitorUpdateErrorZ(const CResult_NoneMonitorUpdateErrorZ&) = delete; + ~CResult_NoneMonitorUpdateErrorZ() { CResult_NoneMonitorUpdateErrorZ_free(self); } + CResult_NoneMonitorUpdateErrorZ(CResult_NoneMonitorUpdateErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_NoneMonitorUpdateErrorZ)); } + CResult_NoneMonitorUpdateErrorZ(LDKCResult_NoneMonitorUpdateErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_NoneMonitorUpdateErrorZ)); } + operator LDKCResult_NoneMonitorUpdateErrorZ() { LDKCResult_NoneMonitorUpdateErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_NoneMonitorUpdateErrorZ)); return res; } + LDKCResult_NoneMonitorUpdateErrorZ* operator &() { return &self; } + LDKCResult_NoneMonitorUpdateErrorZ* operator ->() { return &self; } + const LDKCResult_NoneMonitorUpdateErrorZ* operator &() const { return &self; } + const LDKCResult_NoneMonitorUpdateErrorZ* operator ->() const { return &self; } }; } diff --git a/lightning-c-bindings/include/rust_types.h b/lightning-c-bindings/include/rust_types.h index 2e15b2a2b..2514c93e4 100644 --- a/lightning-c-bindings/include/rust_types.h +++ b/lightning-c-bindings/include/rust_types.h @@ -123,14 +123,24 @@ struct nativePeerManagerOpaque; typedef struct nativePeerManagerOpaque LDKnativePeerManager; struct nativeTxCreationKeysOpaque; typedef struct nativeTxCreationKeysOpaque LDKnativeTxCreationKeys; -struct nativePreCalculatedTxCreationKeysOpaque; -typedef struct nativePreCalculatedTxCreationKeysOpaque LDKnativePreCalculatedTxCreationKeys; struct nativeChannelPublicKeysOpaque; typedef struct nativeChannelPublicKeysOpaque LDKnativeChannelPublicKeys; struct nativeHTLCOutputInCommitmentOpaque; typedef struct nativeHTLCOutputInCommitmentOpaque LDKnativeHTLCOutputInCommitment; +struct nativeChannelTransactionParametersOpaque; +typedef struct nativeChannelTransactionParametersOpaque LDKnativeChannelTransactionParameters; +struct nativeCounterpartyChannelTransactionParametersOpaque; +typedef struct nativeCounterpartyChannelTransactionParametersOpaque LDKnativeCounterpartyChannelTransactionParameters; +struct nativeDirectedChannelTransactionParametersOpaque; +typedef struct nativeDirectedChannelTransactionParametersOpaque LDKnativeDirectedChannelTransactionParameters; struct nativeHolderCommitmentTransactionOpaque; typedef struct nativeHolderCommitmentTransactionOpaque LDKnativeHolderCommitmentTransaction; +struct nativeBuiltCommitmentTransactionOpaque; +typedef struct nativeBuiltCommitmentTransactionOpaque LDKnativeBuiltCommitmentTransaction; +struct nativeCommitmentTransactionOpaque; +typedef struct nativeCommitmentTransactionOpaque LDKnativeCommitmentTransaction; +struct nativeTrustedCommitmentTransactionOpaque; +typedef struct nativeTrustedCommitmentTransactionOpaque LDKnativeTrustedCommitmentTransaction; struct nativeInitFeaturesOpaque; typedef struct nativeInitFeaturesOpaque LDKnativeInitFeatures; struct nativeNodeFeaturesOpaque; diff --git a/lightning-c-bindings/src/c_types/derived.rs b/lightning-c-bindings/src/c_types/derived.rs index 38139e0e0..3cf2a7ed5 100644 --- a/lightning-c-bindings/src/c_types/derived.rs +++ b/lightning-c-bindings/src/c_types/derived.rs @@ -109,11 +109,6 @@ pub extern "C" fn C2Tuple_u64u64Z_new(a: u64, b: u64) -> C2Tuple_u64u64Z { C2Tuple_u64u64Z { a, b, } } -#[no_mangle] -pub type CVec_HTLCOutputInCommitmentZ = crate::c_types::CVecTempl; -#[no_mangle] -pub static CVec_HTLCOutputInCommitmentZ_free: extern "C" fn(CVec_HTLCOutputInCommitmentZ) = crate::c_types::CVecTempl_free::; - #[no_mangle] pub type CVec_SignatureZ = crate::c_types::CVecTempl; #[no_mangle] @@ -167,6 +162,18 @@ pub extern "C" fn CResult_CVec_SignatureZNoneZ_err() -> CResult_CVec_SignatureZN crate::c_types::CResultTempl::err(0) } +#[no_mangle] +pub type CResult_ChanKeySignerDecodeErrorZ = crate::c_types::CResultTempl; +#[no_mangle] +pub static CResult_ChanKeySignerDecodeErrorZ_free: extern "C" fn(CResult_ChanKeySignerDecodeErrorZ) = crate::c_types::CResultTempl_free::; +#[no_mangle] +pub static CResult_ChanKeySignerDecodeErrorZ_ok: extern "C" fn (crate::chain::keysinterface::ChannelKeys) -> CResult_ChanKeySignerDecodeErrorZ = + crate::c_types::CResultTempl::::ok; + +#[no_mangle] +pub static CResult_ChanKeySignerDecodeErrorZ_err: extern "C" fn (crate::ln::msgs::DecodeError) -> CResult_ChanKeySignerDecodeErrorZ = + crate::c_types::CResultTempl::::err; + #[no_mangle] pub type CResult_TxOutAccessErrorZ = crate::c_types::CResultTempl; #[no_mangle] @@ -276,6 +283,19 @@ pub type CVec_NodeAnnouncementZ = crate::c_types::CVecTempl; +#[no_mangle] +pub type CResult_NoneLightningErrorZ = crate::c_types::CResultTempl; +#[no_mangle] +pub static CResult_NoneLightningErrorZ_free: extern "C" fn(CResult_NoneLightningErrorZ) = crate::c_types::CResultTempl_free::; +#[no_mangle] +pub extern "C" fn CResult_NoneLightningErrorZ_ok() -> CResult_NoneLightningErrorZ { + crate::c_types::CResultTempl::ok(0) +} + +#[no_mangle] +pub static CResult_NoneLightningErrorZ_err: extern "C" fn (crate::ln::msgs::LightningError) -> CResult_NoneLightningErrorZ = + crate::c_types::CResultTempl::::err; + #[no_mangle] pub type CVec_PublicKeyZ = crate::c_types::CVecTempl; #[no_mangle] @@ -360,18 +380,17 @@ pub static CResult_TxCreationKeysSecpErrorZ_err: extern "C" fn (crate::c_types:: crate::c_types::CResultTempl::::err; #[no_mangle] -pub type C2Tuple_HTLCOutputInCommitmentSignatureZ = crate::c_types::C2TupleTempl; +pub type CResult_TrustedCommitmentTransactionNoneZ = crate::c_types::CResultTempl; #[no_mangle] -pub static C2Tuple_HTLCOutputInCommitmentSignatureZ_free: extern "C" fn(C2Tuple_HTLCOutputInCommitmentSignatureZ) = crate::c_types::C2TupleTempl_free::; +pub static CResult_TrustedCommitmentTransactionNoneZ_free: extern "C" fn(CResult_TrustedCommitmentTransactionNoneZ) = crate::c_types::CResultTempl_free::; #[no_mangle] -pub extern "C" fn C2Tuple_HTLCOutputInCommitmentSignatureZ_new(a: crate::ln::chan_utils::HTLCOutputInCommitment, b: crate::c_types::Signature) -> C2Tuple_HTLCOutputInCommitmentSignatureZ { - C2Tuple_HTLCOutputInCommitmentSignatureZ { a, b, } -} +pub static CResult_TrustedCommitmentTransactionNoneZ_ok: extern "C" fn (crate::ln::chan_utils::TrustedCommitmentTransaction) -> CResult_TrustedCommitmentTransactionNoneZ = + crate::c_types::CResultTempl::::ok; #[no_mangle] -pub type CVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ = crate::c_types::CVecTempl>; -#[no_mangle] -pub static CVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ_free: extern "C" fn(CVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ) = crate::c_types::CVecTempl_free::>; +pub extern "C" fn CResult_TrustedCommitmentTransactionNoneZ_err() -> CResult_TrustedCommitmentTransactionNoneZ { + crate::c_types::CResultTempl::err(0) +} #[no_mangle] pub type CVec_RouteHopZ = crate::c_types::CVecTempl; @@ -400,16 +419,3 @@ pub static CResult_RouteLightningErrorZ_ok: extern "C" fn (crate::routing::route pub static CResult_RouteLightningErrorZ_err: extern "C" fn (crate::ln::msgs::LightningError) -> CResult_RouteLightningErrorZ = crate::c_types::CResultTempl::::err; -#[no_mangle] -pub type CResult_NoneLightningErrorZ = crate::c_types::CResultTempl; -#[no_mangle] -pub static CResult_NoneLightningErrorZ_free: extern "C" fn(CResult_NoneLightningErrorZ) = crate::c_types::CResultTempl_free::; -#[no_mangle] -pub extern "C" fn CResult_NoneLightningErrorZ_ok() -> CResult_NoneLightningErrorZ { - crate::c_types::CResultTempl::ok(0) -} - -#[no_mangle] -pub static CResult_NoneLightningErrorZ_err: extern "C" fn (crate::ln::msgs::LightningError) -> CResult_NoneLightningErrorZ = - crate::c_types::CResultTempl::::err; - diff --git a/lightning-c-bindings/src/chain/chainmonitor.rs b/lightning-c-bindings/src/chain/chainmonitor.rs index 35eb1bed2..99961ffe6 100644 --- a/lightning-c-bindings/src/chain/chainmonitor.rs +++ b/lightning-c-bindings/src/chain/chainmonitor.rs @@ -117,6 +117,16 @@ pub extern "C" fn ChainMonitor_new(chain_source: *mut crate::chain::Filter, mut ChainMonitor { inner: Box::into_raw(Box::new(ret)), is_owned: true } } +impl From for crate::chain::Watch { + fn from(obj: nativeChainMonitor) -> Self { + let mut rust_obj = ChainMonitor { inner: Box::into_raw(Box::new(obj)), is_owned: true }; + let mut ret = ChainMonitor_as_Watch(&rust_obj); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn + rust_obj.inner = std::ptr::null_mut(); + ret.free = Some(ChainMonitor_free_void); + ret + } +} #[no_mangle] pub extern "C" fn ChainMonitor_as_Watch(this_arg: *const ChainMonitor) -> crate::chain::Watch { crate::chain::Watch { @@ -147,6 +157,16 @@ extern "C" fn ChainMonitor_Watch_release_pending_monitor_events(this_arg: *const local_ret.into() } +impl From for crate::util::events::EventsProvider { + fn from(obj: nativeChainMonitor) -> Self { + let mut rust_obj = ChainMonitor { inner: Box::into_raw(Box::new(obj)), is_owned: true }; + let mut ret = ChainMonitor_as_EventsProvider(&rust_obj); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn + rust_obj.inner = std::ptr::null_mut(); + ret.free = Some(ChainMonitor_free_void); + ret + } +} #[no_mangle] pub extern "C" fn ChainMonitor_as_EventsProvider(this_arg: *const ChainMonitor) -> crate::util::events::EventsProvider { crate::util::events::EventsProvider { diff --git a/lightning-c-bindings/src/chain/channelmonitor.rs b/lightning-c-bindings/src/chain/channelmonitor.rs index c64467025..a9bd48b89 100644 --- a/lightning-c-bindings/src/chain/channelmonitor.rs +++ b/lightning-c-bindings/src/chain/channelmonitor.rs @@ -116,6 +116,10 @@ pub extern "C" fn ChannelMonitorUpdate_write(obj: *const ChannelMonitorUpdate) - crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn ChannelMonitorUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelMonitorUpdate) }) +} +#[no_mangle] pub extern "C" fn ChannelMonitorUpdate_read(ser: crate::c_types::u8slice) -> ChannelMonitorUpdate { if let Ok(res) = crate::c_types::deserialize_obj(ser) { ChannelMonitorUpdate { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -381,6 +385,10 @@ pub extern "C" fn HTLCUpdate_write(obj: *const HTLCUpdate) -> crate::c_types::de crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn HTLCUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCUpdate) }) +} +#[no_mangle] pub extern "C" fn HTLCUpdate_read(ser: crate::c_types::u8slice) -> HTLCUpdate { if let Ok(res) = crate::c_types::deserialize_obj(ser) { HTLCUpdate { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -402,6 +410,12 @@ type nativeChannelMonitor = nativeChannelMonitorImport crate::c_types::derived::CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ, + pub sign_counterparty_commitment: extern "C" fn (this_arg: *const c_void, commitment_tx: &crate::ln::chan_utils::CommitmentTransaction) -> crate::c_types::derived::CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ, /// Create a signature for a holder's commitment transaction. This will only ever be called with - /// the same holder_commitment_tx (or a copy thereof), though there are currently no guarantees + /// the same commitment_tx (or a copy thereof), though there are currently no guarantees /// that it will not be called multiple times. /// An external signer implementation should check that the commitment has not been revoked. #[must_use] - pub sign_holder_commitment: extern "C" fn (this_arg: *const c_void, holder_commitment_tx: &crate::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_SignatureNoneZ, + pub sign_holder_commitment: extern "C" fn (this_arg: *const c_void, commitment_tx: &crate::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_SignatureNoneZ, /// Create a signature for each HTLC transaction spending a holder's commitment transaction. /// /// Unlike sign_holder_commitment, this may be called multiple times with *different* - /// holder_commitment_tx values. While this will never be called with a revoked - /// holder_commitment_tx, it is possible that it is called with the second-latest - /// holder_commitment_tx (only if we haven't yet revoked it) if some watchtower/secondary + /// commitment_tx values. While this will never be called with a revoked + /// commitment_tx, it is possible that it is called with the second-latest + /// commitment_tx (only if we haven't yet revoked it) if some watchtower/secondary /// ChannelMonitor decided to broadcast before it had been updated to the latest. /// /// Either an Err should be returned, or a Vec with one entry for each HTLC which exists in - /// holder_commitment_tx. For those HTLCs which have transaction_output_index set to None - /// (implying they were considered dust at the time the commitment transaction was negotiated), - /// a corresponding None should be included in the return value. All other positions in the - /// return value must contain a signature. + /// commitment_tx. #[must_use] - pub sign_holder_commitment_htlc_transactions: extern "C" fn (this_arg: *const c_void, holder_commitment_tx: &crate::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_CVec_SignatureZNoneZ, + pub sign_holder_commitment_htlc_transactions: extern "C" fn (this_arg: *const c_void, commitment_tx: &crate::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_CVec_SignatureZNoneZ, /// Create a signature for the given input in a transaction spending an HTLC or commitment /// transaction output when our counterparty broadcasts an old state. /// @@ -355,14 +352,19 @@ pub struct ChannelKeys { /// protocol. #[must_use] pub sign_channel_announcement: extern "C" fn (this_arg: *const c_void, msg: &crate::ln::msgs::UnsignedChannelAnnouncement) -> crate::c_types::derived::CResult_SignatureNoneZ, - /// Set the counterparty channel basepoints and counterparty_selected/holder_selected_contest_delay. - /// This is done immediately on incoming channels and as soon as the channel is accepted on outgoing channels. + /// Set the counterparty static channel data, including basepoints, + /// counterparty_selected/holder_selected_contest_delay and funding outpoint. + /// This is done as soon as the funding outpoint is known. Since these are static channel data, + /// they MUST NOT be allowed to change to different values once set. + /// + /// channel_parameters.is_populated() MUST be true. /// /// We bind holder_selected_contest_delay late here for API convenience. /// /// Will be called before any signatures are applied. - pub on_accept: extern "C" fn (this_arg: *mut c_void, channel_points: &crate::ln::chan_utils::ChannelPublicKeys, counterparty_selected_contest_delay: u16, holder_selected_contest_delay: u16), + pub ready_channel: extern "C" fn (this_arg: *mut c_void, channel_parameters: &crate::ln::chan_utils::ChannelTransactionParameters), pub clone: Option *mut c_void>, + pub write: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z, pub free: Option, } unsafe impl Send for ChannelKeys {} @@ -382,8 +384,9 @@ pub extern "C" fn ChannelKeys_clone(orig: &ChannelKeys) -> ChannelKeys { sign_counterparty_htlc_transaction: orig.sign_counterparty_htlc_transaction.clone(), sign_closing_transaction: orig.sign_closing_transaction.clone(), sign_channel_announcement: orig.sign_channel_announcement.clone(), - on_accept: orig.on_accept.clone(), + ready_channel: orig.ready_channel.clone(), clone: orig.clone.clone(), + write: orig.write.clone(), free: orig.free.clone(), } } @@ -392,6 +395,12 @@ impl Clone for ChannelKeys { ChannelKeys_clone(self) } } +impl lightning::util::ser::Writeable for ChannelKeys { + fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> { + let vec = (self.write)(self.this_arg); + w.write_all(vec.as_slice()) + } +} use lightning::chain::keysinterface::ChannelKeys as rustChannelKeys; impl rustChannelKeys for ChannelKeys { @@ -414,21 +423,19 @@ impl rustChannelKeys for ChannelKeys { let (mut orig_ret_0, mut orig_ret_1) = ret.to_rust(); let mut local_ret = (orig_ret_0, orig_ret_1); local_ret } - fn sign_counterparty_commitment(&self, feerate_per_kw: u32, commitment_tx: &bitcoin::blockdata::transaction::Transaction, keys: &lightning::ln::chan_utils::PreCalculatedTxCreationKeys, htlcs: &[&lightning::ln::chan_utils::HTLCOutputInCommitment], _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result<(bitcoin::secp256k1::Signature, Vec), ()> { - let mut local_commitment_tx = ::bitcoin::consensus::encode::serialize(commitment_tx); - let mut local_htlcs = Vec::new(); for item in htlcs.iter() { local_htlcs.push( { crate::ln::chan_utils::HTLCOutputInCommitment { inner: unsafe { ( (&(**item) as *const _) as *mut _) }, is_owned: false } }); }; - let mut ret = (self.sign_counterparty_commitment)(self.this_arg, feerate_per_kw, crate::c_types::Transaction::from_vec(local_commitment_tx), &crate::ln::chan_utils::PreCalculatedTxCreationKeys { inner: unsafe { (keys as *const _) as *mut _ }, is_owned: false }, local_htlcs.into()); + fn sign_counterparty_commitment(&self, commitment_tx: &lightning::ln::chan_utils::CommitmentTransaction, _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result<(bitcoin::secp256k1::Signature, Vec), ()> { + let mut ret = (self.sign_counterparty_commitment)(self.this_arg, &crate::ln::chan_utils::CommitmentTransaction { inner: unsafe { (commitment_tx as *const _) as *mut _ }, is_owned: false }); let mut local_ret = match ret.result_ok { true => Ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = (*unsafe { Box::from_raw(ret.contents.result.take_ptr()) }).to_rust(); let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.into_rust().drain(..) { local_orig_ret_0_1.push( { item.into_rust() }); }; let mut local_ret_0 = (orig_ret_0_0.into_rust(), local_orig_ret_0_1); local_ret_0 }), false => Err( { () /*(*unsafe { Box::from_raw(ret.contents.err.take_ptr()) })*/ })}; local_ret } - fn sign_holder_commitment(&self, holder_commitment_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result { - let mut ret = (self.sign_holder_commitment)(self.this_arg, &crate::ln::chan_utils::HolderCommitmentTransaction { inner: unsafe { (holder_commitment_tx as *const _) as *mut _ }, is_owned: false }); + fn sign_holder_commitment(&self, commitment_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result { + let mut ret = (self.sign_holder_commitment)(self.this_arg, &crate::ln::chan_utils::HolderCommitmentTransaction { inner: unsafe { (commitment_tx as *const _) as *mut _ }, is_owned: false }); let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(ret.contents.result.take_ptr()) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(ret.contents.err.take_ptr()) })*/ })}; local_ret } - fn sign_holder_commitment_htlc_transactions(&self, holder_commitment_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result>, ()> { - let mut ret = (self.sign_holder_commitment_htlc_transactions)(self.this_arg, &crate::ln::chan_utils::HolderCommitmentTransaction { inner: unsafe { (holder_commitment_tx as *const _) as *mut _ }, is_owned: false }); - let mut local_ret = match ret.result_ok { true => Ok( { let mut local_ret_0 = Vec::new(); for mut item in (*unsafe { Box::from_raw(ret.contents.result.take_ptr()) }).into_rust().drain(..) { local_ret_0.push( { let mut local_ret_0_0 = if item.is_null() { None } else { Some( { item.into_rust() }) }; local_ret_0_0 }); }; local_ret_0 }), false => Err( { () /*(*unsafe { Box::from_raw(ret.contents.err.take_ptr()) })*/ })}; + fn sign_holder_commitment_htlc_transactions(&self, commitment_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result, ()> { + let mut ret = (self.sign_holder_commitment_htlc_transactions)(self.this_arg, &crate::ln::chan_utils::HolderCommitmentTransaction { inner: unsafe { (commitment_tx as *const _) as *mut _ }, is_owned: false }); + let mut local_ret = match ret.result_ok { true => Ok( { let mut local_ret_0 = Vec::new(); for mut item in (*unsafe { Box::from_raw(ret.contents.result.take_ptr()) }).into_rust().drain(..) { local_ret_0.push( { item.into_rust() }); }; local_ret_0 }), false => Err( { () /*(*unsafe { Box::from_raw(ret.contents.err.take_ptr()) })*/ })}; local_ret } fn sign_justice_transaction(&self, justice_tx: &bitcoin::blockdata::transaction::Transaction, input: usize, amount: u64, per_commitment_key: &bitcoin::secp256k1::key::SecretKey, htlc: &Option, _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result { @@ -455,8 +462,8 @@ impl rustChannelKeys for ChannelKeys { let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(ret.contents.result.take_ptr()) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(ret.contents.err.take_ptr()) })*/ })}; local_ret } - fn on_accept(&mut self, channel_points: &lightning::ln::chan_utils::ChannelPublicKeys, counterparty_selected_contest_delay: u16, holder_selected_contest_delay: u16) { - (self.on_accept)(self.this_arg, &crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { (channel_points as *const _) as *mut _ }, is_owned: false }, counterparty_selected_contest_delay, holder_selected_contest_delay) + fn ready_channel(&mut self, channel_parameters: &lightning::ln::chan_utils::ChannelTransactionParameters) { + (self.ready_channel)(self.this_arg, &crate::ln::chan_utils::ChannelTransactionParameters { inner: unsafe { (channel_parameters as *const _) as *mut _ }, is_owned: false }) } } @@ -500,6 +507,14 @@ pub struct KeysInterface { /// persisted anywhere, though they must be unique across restarts. #[must_use] pub get_secure_random_bytes: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes, + /// Reads a `ChanKeySigner` for this `KeysInterface` from the given input stream. + /// This is only called during deserialization of other objects which contain + /// `ChannelKeys`-implementing objects (ie `ChannelMonitor`s and `ChannelManager`s). + /// The bytes are exactly those which `::write()` writes, and + /// contain no versioning scheme. You may wish to include your own version prefix and ensure + /// you've read all of the provided bytes to ensure no corruption occurred. + #[must_use] + pub read_chan_signer: extern "C" fn (this_arg: *const c_void, reader: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChanKeySignerDecodeErrorZ, pub free: Option, } unsafe impl Send for KeysInterface {} @@ -520,7 +535,7 @@ impl rustKeysInterface for KeysInterface { let mut ret = (self.get_shutdown_pubkey)(self.this_arg); ret.into_rust() } - fn get_channel_keys(&self, inbound: bool, channel_value_satoshis: u64) -> Self::ChanKeySigner { + fn get_channel_keys(&self, inbound: bool, channel_value_satoshis: u64) -> crate::chain::keysinterface::ChannelKeys { let mut ret = (self.get_channel_keys)(self.this_arg, inbound, channel_value_satoshis); ret } @@ -528,6 +543,12 @@ impl rustKeysInterface for KeysInterface { let mut ret = (self.get_secure_random_bytes)(self.this_arg); ret.data } + fn read_chan_signer(&self, reader: &[u8]) -> Result { + let mut local_reader = crate::c_types::u8slice::from_slice(reader); + let mut ret = (self.read_chan_signer)(self.this_arg, local_reader); + let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(ret.contents.result.take_ptr()) }) }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(ret.contents.err.take_ptr()) }).take_ptr()) } })}; + local_ret + } } // We're essentially a pointer already, or at least a set of pointers, so allow us to be used @@ -553,6 +574,9 @@ use lightning::chain::keysinterface::InMemoryChannelKeys as nativeInMemoryChanne type nativeInMemoryChannelKeys = nativeInMemoryChannelKeysImport; /// A simple implementation of ChannelKeys that just keeps the private keys in memory. +/// +/// This implementation performs no policy checks and is insufficient by itself as +/// a secure external signer. #[must_use] #[repr(C)] pub struct InMemoryChannelKeys { @@ -679,7 +703,7 @@ pub extern "C" fn InMemoryChannelKeys_new(mut funding_key: crate::c_types::Secre } /// Counterparty pubkeys. -/// Will panic if on_accept wasn't called. +/// Will panic if ready_channel wasn't called. #[must_use] #[no_mangle] pub extern "C" fn InMemoryChannelKeys_counterparty_pubkeys(this_arg: &InMemoryChannelKeys) -> crate::ln::chan_utils::ChannelPublicKeys { @@ -689,9 +713,8 @@ pub extern "C" fn InMemoryChannelKeys_counterparty_pubkeys(this_arg: &InMemoryCh /// The contest_delay value specified by our counterparty and applied on holder-broadcastable /// transactions, ie the amount of time that we have to wait to recover our funds if we -/// broadcast a transaction. You'll likely want to pass this to the -/// ln::chan_utils::build*_transaction functions when signing holder's transactions. -/// Will panic if on_accept wasn't called. +/// broadcast a transaction. +/// Will panic if ready_channel wasn't called. #[must_use] #[no_mangle] pub extern "C" fn InMemoryChannelKeys_counterparty_selected_contest_delay(this_arg: &InMemoryChannelKeys) -> u16 { @@ -702,7 +725,7 @@ pub extern "C" fn InMemoryChannelKeys_counterparty_selected_contest_delay(this_a /// The contest_delay value specified by us and applied on transactions broadcastable /// by our counterparty, ie the amount of time that they have to wait to recover their funds /// if they broadcast a transaction. -/// Will panic if on_accept wasn't called. +/// Will panic if ready_channel wasn't called. #[must_use] #[no_mangle] pub extern "C" fn InMemoryChannelKeys_holder_selected_contest_delay(this_arg: &InMemoryChannelKeys) -> u16 { @@ -710,6 +733,45 @@ pub extern "C" fn InMemoryChannelKeys_holder_selected_contest_delay(this_arg: &I ret } +/// Whether the holder is the initiator +/// Will panic if ready_channel wasn't called. +#[must_use] +#[no_mangle] +pub extern "C" fn InMemoryChannelKeys_is_outbound(this_arg: &InMemoryChannelKeys) -> bool { + let mut ret = unsafe { &*this_arg.inner }.is_outbound(); + ret +} + +/// Funding outpoint +/// Will panic if ready_channel wasn't called. +#[must_use] +#[no_mangle] +pub extern "C" fn InMemoryChannelKeys_funding_outpoint(this_arg: &InMemoryChannelKeys) -> crate::chain::transaction::OutPoint { + let mut ret = unsafe { &*this_arg.inner }.funding_outpoint(); + crate::chain::transaction::OutPoint { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false } +} + +/// Obtain a ChannelTransactionParameters for this channel, to be used when verifying or +/// building transactions. +/// +/// Will panic if ready_channel wasn't called. +#[must_use] +#[no_mangle] +pub extern "C" fn InMemoryChannelKeys_get_channel_parameters(this_arg: &InMemoryChannelKeys) -> crate::ln::chan_utils::ChannelTransactionParameters { + let mut ret = unsafe { &*this_arg.inner }.get_channel_parameters(); + crate::ln::chan_utils::ChannelTransactionParameters { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false } +} + +impl From for crate::chain::keysinterface::ChannelKeys { + fn from(obj: nativeInMemoryChannelKeys) -> Self { + let mut rust_obj = InMemoryChannelKeys { inner: Box::into_raw(Box::new(obj)), is_owned: true }; + let mut ret = InMemoryChannelKeys_as_ChannelKeys(&rust_obj); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn + rust_obj.inner = std::ptr::null_mut(); + ret.free = Some(InMemoryChannelKeys_free_void); + ret + } +} #[no_mangle] pub extern "C" fn InMemoryChannelKeys_as_ChannelKeys(this_arg: *const InMemoryChannelKeys) -> crate::chain::keysinterface::ChannelKeys { crate::chain::keysinterface::ChannelKeys { @@ -728,8 +790,9 @@ pub extern "C" fn InMemoryChannelKeys_as_ChannelKeys(this_arg: *const InMemoryCh sign_counterparty_htlc_transaction: InMemoryChannelKeys_ChannelKeys_sign_counterparty_htlc_transaction, sign_closing_transaction: InMemoryChannelKeys_ChannelKeys_sign_closing_transaction, sign_channel_announcement: InMemoryChannelKeys_ChannelKeys_sign_channel_announcement, - on_accept: InMemoryChannelKeys_ChannelKeys_on_accept, + ready_channel: InMemoryChannelKeys_ChannelKeys_ready_channel, clone: Some(InMemoryChannelKeys_clone_void), + write: InMemoryChannelKeys_write_void, } } use lightning::chain::keysinterface::ChannelKeys as ChannelKeysTraitImport; @@ -762,22 +825,21 @@ extern "C" fn InMemoryChannelKeys_ChannelKeys_key_derivation_params(this_arg: *c local_ret } #[must_use] -extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_counterparty_commitment(this_arg: *const c_void, mut feerate_per_kw: u32, mut commitment_tx: crate::c_types::Transaction, pre_keys: &crate::ln::chan_utils::PreCalculatedTxCreationKeys, mut htlcs: crate::c_types::derived::CVec_HTLCOutputInCommitmentZ) -> crate::c_types::derived::CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ { - let mut local_htlcs = Vec::new(); for mut item in htlcs.as_slice().iter() { local_htlcs.push( { unsafe { &*item.inner } }); }; - let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_counterparty_commitment(feerate_per_kw, &commitment_tx.into_bitcoin(), unsafe { &*pre_keys.inner }, &local_htlcs[..], &bitcoin::secp256k1::Secp256k1::new()); +extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_counterparty_commitment(this_arg: *const c_void, commitment_tx: &crate::ln::chan_utils::CommitmentTransaction) -> crate::c_types::derived::CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ { + let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_counterparty_commitment(unsafe { &*commitment_tx.inner }, &bitcoin::secp256k1::Secp256k1::new()); let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = o; let mut local_orig_ret_0_1 = Vec::new(); for item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { crate::c_types::Signature::from_rust(&item) }); }; let mut local_ret_0 = (crate::c_types::Signature::from_rust(&orig_ret_0_0), local_orig_ret_0_1.into()).into(); local_ret_0 }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) }; local_ret } #[must_use] -extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_holder_commitment(this_arg: *const c_void, holder_commitment_tx: &crate::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_SignatureNoneZ { - let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_holder_commitment(unsafe { &*holder_commitment_tx.inner }, &bitcoin::secp256k1::Secp256k1::new()); +extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_holder_commitment(this_arg: *const c_void, commitment_tx: &crate::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_SignatureNoneZ { + let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_holder_commitment(unsafe { &*commitment_tx.inner }, &bitcoin::secp256k1::Secp256k1::new()); let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) }; local_ret } #[must_use] -extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_holder_commitment_htlc_transactions(this_arg: *const c_void, holder_commitment_tx: &crate::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_CVec_SignatureZNoneZ { - let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_holder_commitment_htlc_transactions(unsafe { &*holder_commitment_tx.inner }, &bitcoin::secp256k1::Secp256k1::new()); - let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = Vec::new(); for item in o.drain(..) { local_ret_0.push( { let mut local_ret_0_0 = if item.is_none() { crate::c_types::Signature::null() } else { { crate::c_types::Signature::from_rust(&(item.unwrap())) } }; local_ret_0_0 }); }; local_ret_0.into() }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) }; +extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_holder_commitment_htlc_transactions(this_arg: *const c_void, commitment_tx: &crate::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_CVec_SignatureZNoneZ { + let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_holder_commitment_htlc_transactions(unsafe { &*commitment_tx.inner }, &bitcoin::secp256k1::Secp256k1::new()); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = Vec::new(); for item in o.drain(..) { local_ret_0.push( { crate::c_types::Signature::from_rust(&item) }); }; local_ret_0.into() }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) }; local_ret } #[must_use] @@ -805,8 +867,8 @@ extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_channel_announcement(this_arg let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) }; local_ret } -extern "C" fn InMemoryChannelKeys_ChannelKeys_on_accept(this_arg: *mut c_void, channel_pubkeys: &crate::ln::chan_utils::ChannelPublicKeys, mut counterparty_selected_contest_delay: u16, mut holder_selected_contest_delay: u16) { - unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.on_accept(unsafe { &*channel_pubkeys.inner }, counterparty_selected_contest_delay, holder_selected_contest_delay) +extern "C" fn InMemoryChannelKeys_ChannelKeys_ready_channel(this_arg: *mut c_void, channel_parameters: &crate::ln::chan_utils::ChannelTransactionParameters) { + unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.ready_channel(unsafe { &*channel_parameters.inner }) } #[no_mangle] @@ -814,6 +876,10 @@ pub extern "C" fn InMemoryChannelKeys_write(obj: *const InMemoryChannelKeys) -> crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn InMemoryChannelKeys_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInMemoryChannelKeys) }) +} +#[no_mangle] pub extern "C" fn InMemoryChannelKeys_read(ser: crate::c_types::u8slice) -> InMemoryChannelKeys { if let Ok(res) = crate::c_types::deserialize_obj(ser) { InMemoryChannelKeys { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -903,6 +969,16 @@ pub extern "C" fn KeysManager_derive_channel_keys(this_arg: &KeysManager, mut ch crate::chain::keysinterface::InMemoryChannelKeys { inner: Box::into_raw(Box::new(ret)), is_owned: true } } +impl From for crate::chain::keysinterface::KeysInterface { + fn from(obj: nativeKeysManager) -> Self { + let mut rust_obj = KeysManager { inner: Box::into_raw(Box::new(obj)), is_owned: true }; + let mut ret = KeysManager_as_KeysInterface(&rust_obj); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn + rust_obj.inner = std::ptr::null_mut(); + ret.free = Some(KeysManager_free_void); + ret + } +} #[no_mangle] pub extern "C" fn KeysManager_as_KeysInterface(this_arg: *const KeysManager) -> crate::chain::keysinterface::KeysInterface { crate::chain::keysinterface::KeysInterface { @@ -913,6 +989,7 @@ pub extern "C" fn KeysManager_as_KeysInterface(this_arg: *const KeysManager) -> get_shutdown_pubkey: KeysManager_KeysInterface_get_shutdown_pubkey, get_channel_keys: KeysManager_KeysInterface_get_channel_keys, get_secure_random_bytes: KeysManager_KeysInterface_get_secure_random_bytes, + read_chan_signer: KeysManager_KeysInterface_read_chan_signer, } } use lightning::chain::keysinterface::KeysInterface as KeysInterfaceTraitImport; @@ -934,17 +1011,17 @@ extern "C" fn KeysManager_KeysInterface_get_shutdown_pubkey(this_arg: *const c_v #[must_use] extern "C" fn KeysManager_KeysInterface_get_channel_keys(this_arg: *const c_void, mut _inbound: bool, mut channel_value_satoshis: u64) -> crate::chain::keysinterface::ChannelKeys { let mut ret = unsafe { &mut *(this_arg as *mut nativeKeysManager) }.get_channel_keys(_inbound, channel_value_satoshis); - let mut rust_obj = InMemoryChannelKeys { inner: Box::into_raw(Box::new(ret)), is_owned: true }; - let mut ret = InMemoryChannelKeys_as_ChannelKeys(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = std::ptr::null_mut(); - ret.free = Some(InMemoryChannelKeys_free_void); - ret - + ret.into() } #[must_use] extern "C" fn KeysManager_KeysInterface_get_secure_random_bytes(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes { let mut ret = unsafe { &mut *(this_arg as *mut nativeKeysManager) }.get_secure_random_bytes(); crate::c_types::ThirtyTwoBytes { data: ret } } +#[must_use] +extern "C" fn KeysManager_KeysInterface_read_chan_signer(this_arg: *const c_void, mut reader: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChanKeySignerDecodeErrorZ { + let mut ret = unsafe { &mut *(this_arg as *mut nativeKeysManager) }.read_chan_signer(reader.to_slice()); + 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::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; + local_ret +} diff --git a/lightning-c-bindings/src/chain/mod.rs b/lightning-c-bindings/src/chain/mod.rs index 6ea4d99db..5e19de7e6 100644 --- a/lightning-c-bindings/src/chain/mod.rs +++ b/lightning-c-bindings/src/chain/mod.rs @@ -156,7 +156,7 @@ unsafe impl Sync for Watch {} use lightning::chain::Watch as rustWatch; impl rustWatch for Watch { type Keys = crate::chain::keysinterface::ChannelKeys; - fn watch_channel(&self, funding_txo: lightning::chain::transaction::OutPoint, monitor: lightning::chain::channelmonitor::ChannelMonitor) -> Result<(), lightning::chain::channelmonitor::ChannelMonitorUpdateErr> { + fn watch_channel(&self, funding_txo: lightning::chain::transaction::OutPoint, monitor: lightning::chain::channelmonitor::ChannelMonitor) -> Result<(), lightning::chain::channelmonitor::ChannelMonitorUpdateErr> { let mut ret = (self.watch_channel)(self.this_arg, crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(funding_txo)), is_owned: true }, crate::chain::channelmonitor::ChannelMonitor { inner: Box::into_raw(Box::new(monitor)), is_owned: true }); let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(ret.contents.result.take_ptr()) })*/ }), false => Err( { (*unsafe { Box::from_raw(ret.contents.err.take_ptr()) }).into_native() })}; local_ret diff --git a/lightning-c-bindings/src/chain/transaction.rs b/lightning-c-bindings/src/chain/transaction.rs index 3a35c4727..698e90131 100644 --- a/lightning-c-bindings/src/chain/transaction.rs +++ b/lightning-c-bindings/src/chain/transaction.rs @@ -105,6 +105,10 @@ pub extern "C" fn OutPoint_write(obj: *const OutPoint) -> crate::c_types::derive crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn OutPoint_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeOutPoint) }) +} +#[no_mangle] pub extern "C" fn OutPoint_read(ser: crate::c_types::u8slice) -> OutPoint { if let Ok(res) = crate::c_types::deserialize_obj(ser) { OutPoint { inner: Box::into_raw(Box::new(res)), is_owned: true } diff --git a/lightning-c-bindings/src/ln/chan_utils.rs b/lightning-c-bindings/src/ln/chan_utils.rs index f9e6c407e..888f7912a 100644 --- a/lightning-c-bindings/src/ln/chan_utils.rs +++ b/lightning-c-bindings/src/ln/chan_utils.rs @@ -85,7 +85,7 @@ type nativeTxCreationKeys = nativeTxCreationKeysImport; /// /// These keys are assumed to be good, either because the code derived them from /// channel basepoints via the new function, or they were obtained via -/// PreCalculatedTxCreationKeys.trust_key_derivation because we trusted the source of the +/// CommitmentTransaction.trust().keys() because we trusted the source of the /// pre-calculated keys. #[must_use] #[repr(C)] @@ -212,6 +212,10 @@ pub extern "C" fn TxCreationKeys_write(obj: *const TxCreationKeys) -> crate::c_t crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn TxCreationKeys_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTxCreationKeys) }) +} +#[no_mangle] pub extern "C" fn TxCreationKeys_read(ser: crate::c_types::u8slice) -> TxCreationKeys { if let Ok(res) = crate::c_types::deserialize_obj(ser) { TxCreationKeys { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -220,89 +224,6 @@ pub extern "C" fn TxCreationKeys_read(ser: crate::c_types::u8slice) -> TxCreatio } } -use lightning::ln::chan_utils::PreCalculatedTxCreationKeys as nativePreCalculatedTxCreationKeysImport; -type nativePreCalculatedTxCreationKeys = nativePreCalculatedTxCreationKeysImport; - -/// The per-commitment point and a set of pre-calculated public keys used for transaction creation -/// in the signer. -/// The pre-calculated keys are an optimization, because ChannelKeys has enough -/// information to re-derive them. -#[must_use] -#[repr(C)] -pub struct PreCalculatedTxCreationKeys { - /// 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 nativePreCalculatedTxCreationKeys, - pub is_owned: bool, -} - -impl Drop for PreCalculatedTxCreationKeys { - fn drop(&mut self) { - if self.is_owned && !self.inner.is_null() { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn PreCalculatedTxCreationKeys_free(this_ptr: PreCalculatedTxCreationKeys) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn PreCalculatedTxCreationKeys_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativePreCalculatedTxCreationKeys); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl PreCalculatedTxCreationKeys { - pub(crate) fn take_ptr(mut self) -> *mut nativePreCalculatedTxCreationKeys { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -impl Clone for PreCalculatedTxCreationKeys { - fn clone(&self) -> Self { - Self { - inner: 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 PreCalculatedTxCreationKeys_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePreCalculatedTxCreationKeys)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn PreCalculatedTxCreationKeys_clone(orig: &PreCalculatedTxCreationKeys) -> PreCalculatedTxCreationKeys { - PreCalculatedTxCreationKeys { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } -} -/// Create a new PreCalculatedTxCreationKeys from TxCreationKeys -#[must_use] -#[no_mangle] -pub extern "C" fn PreCalculatedTxCreationKeys_new(mut keys: crate::ln::chan_utils::TxCreationKeys) -> PreCalculatedTxCreationKeys { - let mut ret = lightning::ln::chan_utils::PreCalculatedTxCreationKeys::new(*unsafe { Box::from_raw(keys.take_ptr()) }); - PreCalculatedTxCreationKeys { inner: Box::into_raw(Box::new(ret)), is_owned: true } -} - -/// The pre-calculated transaction creation public keys. -/// An external validating signer should not trust these keys. -#[must_use] -#[no_mangle] -pub extern "C" fn PreCalculatedTxCreationKeys_trust_key_derivation(this_arg: &PreCalculatedTxCreationKeys) -> crate::ln::chan_utils::TxCreationKeys { - let mut ret = unsafe { &*this_arg.inner }.trust_key_derivation(); - crate::ln::chan_utils::TxCreationKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false } -} - -/// The transaction per-commitment point -#[must_use] -#[no_mangle] -pub extern "C" fn PreCalculatedTxCreationKeys_per_commitment_point(this_arg: &PreCalculatedTxCreationKeys) -> crate::c_types::PublicKey { - let mut ret = unsafe { &*this_arg.inner }.per_commitment_point(); - crate::c_types::PublicKey::from_rust(&*ret) -} - - use lightning::ln::chan_utils::ChannelPublicKeys as nativeChannelPublicKeysImport; type nativeChannelPublicKeys = nativeChannelPublicKeysImport; @@ -446,6 +367,10 @@ pub extern "C" fn ChannelPublicKeys_write(obj: *const ChannelPublicKeys) -> crat crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn ChannelPublicKeys_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelPublicKeys) }) +} +#[no_mangle] pub extern "C" fn ChannelPublicKeys_read(ser: crate::c_types::u8slice) -> ChannelPublicKeys { if let Ok(res) = crate::c_types::deserialize_obj(ser) { ChannelPublicKeys { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -453,7 +378,8 @@ pub extern "C" fn ChannelPublicKeys_read(ser: crate::c_types::u8slice) -> Channe ChannelPublicKeys { inner: std::ptr::null_mut(), is_owned: true } } } -/// Create a new TxCreationKeys from channel base points and the per-commitment point +/// Create per-state keys from channel base points and the per-commitment point. +/// Key set is asymmetric and can't be used as part of counter-signatory set of transactions. #[must_use] #[no_mangle] pub extern "C" fn TxCreationKeys_derive_new(mut per_commitment_point: crate::c_types::PublicKey, mut broadcaster_delayed_payment_base: crate::c_types::PublicKey, mut broadcaster_htlc_base: crate::c_types::PublicKey, mut countersignatory_revocation_base: crate::c_types::PublicKey, mut countersignatory_htlc_base: crate::c_types::PublicKey) -> crate::c_types::derived::CResult_TxCreationKeysSecpErrorZ { @@ -462,6 +388,16 @@ pub extern "C" fn TxCreationKeys_derive_new(mut per_commitment_point: crate::c_t local_ret } +/// Generate per-state keys from channel static keys. +/// Key set is asymmetric and can't be used as part of counter-signatory set of transactions. +#[must_use] +#[no_mangle] +pub extern "C" fn TxCreationKeys_from_channel_static_keys(mut per_commitment_point: crate::c_types::PublicKey, broadcaster_keys: &crate::ln::chan_utils::ChannelPublicKeys, countersignatory_keys: &crate::ln::chan_utils::ChannelPublicKeys) -> crate::c_types::derived::CResult_TxCreationKeysSecpErrorZ { + let mut ret = lightning::ln::chan_utils::TxCreationKeys::from_channel_static_keys(&per_commitment_point.into_rust(), unsafe { &*broadcaster_keys.inner }, unsafe { &*countersignatory_keys.inner }, &bitcoin::secp256k1::Secp256k1::new()); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::chan_utils::TxCreationKeys { inner: Box::into_raw(Box::new(o)), is_owned: true } }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }) }; + local_ret +} + /// A script either spendable by the revocation /// key or the broadcaster_delayed_payment_key and satisfying the relative-locktime OP_CSV constrain. /// Encumbering a `to_holder` output on a commitment transaction or 2nd-stage HTLC transactions. @@ -583,6 +519,10 @@ pub extern "C" fn HTLCOutputInCommitment_write(obj: *const HTLCOutputInCommitmen crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn HTLCOutputInCommitment_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCOutputInCommitment) }) +} +#[no_mangle] pub extern "C" fn HTLCOutputInCommitment_read(ser: crate::c_types::u8slice) -> HTLCOutputInCommitment { if let Ok(res) = crate::c_types::deserialize_obj(ser) { HTLCOutputInCommitment { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -615,12 +555,380 @@ pub extern "C" fn build_htlc_transaction(prev_hash: *const [u8; 32], mut feerate } +use lightning::ln::chan_utils::ChannelTransactionParameters as nativeChannelTransactionParametersImport; +type nativeChannelTransactionParameters = nativeChannelTransactionParametersImport; + +/// Per-channel data used to build transactions in conjunction with the per-commitment data (CommitmentTransaction). +/// The fields are organized by holder/counterparty. +/// +/// Normally, this is converted to the broadcaster/countersignatory-organized DirectedChannelTransactionParameters +/// before use, via the as_holder_broadcastable and as_counterparty_broadcastable functions. +#[must_use] +#[repr(C)] +pub struct ChannelTransactionParameters { + /// 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 nativeChannelTransactionParameters, + pub is_owned: bool, +} + +impl Drop for ChannelTransactionParameters { + fn drop(&mut self) { + if self.is_owned && !self.inner.is_null() { + let _ = unsafe { Box::from_raw(self.inner) }; + } + } +} +#[no_mangle] +pub extern "C" fn ChannelTransactionParameters_free(this_ptr: ChannelTransactionParameters) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +extern "C" fn ChannelTransactionParameters_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelTransactionParameters); } +} +#[allow(unused)] +/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy +impl ChannelTransactionParameters { + pub(crate) fn take_ptr(mut self) -> *mut nativeChannelTransactionParameters { + assert!(self.is_owned); + let ret = self.inner; + self.inner = std::ptr::null_mut(); + ret + } +} +impl Clone for ChannelTransactionParameters { + fn clone(&self) -> Self { + Self { + inner: 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 ChannelTransactionParameters_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelTransactionParameters)).clone() })) as *mut c_void +} +#[no_mangle] +pub extern "C" fn ChannelTransactionParameters_clone(orig: &ChannelTransactionParameters) -> ChannelTransactionParameters { + ChannelTransactionParameters { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } +} +/// Holder public keys +#[no_mangle] +pub extern "C" fn ChannelTransactionParameters_get_holder_pubkeys(this_ptr: &ChannelTransactionParameters) -> crate::ln::chan_utils::ChannelPublicKeys { + let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.holder_pubkeys; + crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false } +} +/// Holder public keys +#[no_mangle] +pub extern "C" fn ChannelTransactionParameters_set_holder_pubkeys(this_ptr: &mut ChannelTransactionParameters, mut val: crate::ln::chan_utils::ChannelPublicKeys) { + unsafe { &mut *this_ptr.inner }.holder_pubkeys = *unsafe { Box::from_raw(val.take_ptr()) }; +} +/// The contest delay selected by the holder, which applies to counterparty-broadcast transactions +#[no_mangle] +pub extern "C" fn ChannelTransactionParameters_get_holder_selected_contest_delay(this_ptr: &ChannelTransactionParameters) -> u16 { + let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.holder_selected_contest_delay; + (*inner_val) +} +/// The contest delay selected by the holder, which applies to counterparty-broadcast transactions +#[no_mangle] +pub extern "C" fn ChannelTransactionParameters_set_holder_selected_contest_delay(this_ptr: &mut ChannelTransactionParameters, mut val: u16) { + unsafe { &mut *this_ptr.inner }.holder_selected_contest_delay = val; +} +/// Whether the holder is the initiator of this channel. +/// This is an input to the commitment number obscure factor computation. +#[no_mangle] +pub extern "C" fn ChannelTransactionParameters_get_is_outbound_from_holder(this_ptr: &ChannelTransactionParameters) -> bool { + let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.is_outbound_from_holder; + (*inner_val) +} +/// Whether the holder is the initiator of this channel. +/// This is an input to the commitment number obscure factor computation. +#[no_mangle] +pub extern "C" fn ChannelTransactionParameters_set_is_outbound_from_holder(this_ptr: &mut ChannelTransactionParameters, mut val: bool) { + unsafe { &mut *this_ptr.inner }.is_outbound_from_holder = val; +} +/// The late-bound counterparty channel transaction parameters. +/// These parameters are populated at the point in the protocol where the counterparty provides them. +#[no_mangle] +pub extern "C" fn ChannelTransactionParameters_get_counterparty_parameters(this_ptr: &ChannelTransactionParameters) -> crate::ln::chan_utils::CounterpartyChannelTransactionParameters { + let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.counterparty_parameters; + let mut local_inner_val = crate::ln::chan_utils::CounterpartyChannelTransactionParameters { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false }; + local_inner_val +} +/// The late-bound counterparty channel transaction parameters. +/// These parameters are populated at the point in the protocol where the counterparty provides them. +#[no_mangle] +pub extern "C" fn ChannelTransactionParameters_set_counterparty_parameters(this_ptr: &mut ChannelTransactionParameters, mut val: crate::ln::chan_utils::CounterpartyChannelTransactionParameters) { + let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_ptr()) } }) }; + unsafe { &mut *this_ptr.inner }.counterparty_parameters = local_val; +} +/// The late-bound funding outpoint +#[no_mangle] +pub extern "C" fn ChannelTransactionParameters_get_funding_outpoint(this_ptr: &ChannelTransactionParameters) -> crate::chain::transaction::OutPoint { + let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.funding_outpoint; + let mut local_inner_val = crate::chain::transaction::OutPoint { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false }; + local_inner_val +} +/// The late-bound funding outpoint +#[no_mangle] +pub extern "C" fn ChannelTransactionParameters_set_funding_outpoint(this_ptr: &mut ChannelTransactionParameters, mut val: crate::chain::transaction::OutPoint) { + let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_ptr()) } }) }; + unsafe { &mut *this_ptr.inner }.funding_outpoint = local_val; +} +#[must_use] +#[no_mangle] +pub extern "C" fn ChannelTransactionParameters_new(mut holder_pubkeys_arg: crate::ln::chan_utils::ChannelPublicKeys, mut holder_selected_contest_delay_arg: u16, mut is_outbound_from_holder_arg: bool, mut counterparty_parameters_arg: crate::ln::chan_utils::CounterpartyChannelTransactionParameters, mut funding_outpoint_arg: crate::chain::transaction::OutPoint) -> ChannelTransactionParameters { + let mut local_counterparty_parameters_arg = if counterparty_parameters_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(counterparty_parameters_arg.take_ptr()) } }) }; + let mut local_funding_outpoint_arg = if funding_outpoint_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(funding_outpoint_arg.take_ptr()) } }) }; + ChannelTransactionParameters { inner: Box::into_raw(Box::new(nativeChannelTransactionParameters { + holder_pubkeys: *unsafe { Box::from_raw(holder_pubkeys_arg.take_ptr()) }, + holder_selected_contest_delay: holder_selected_contest_delay_arg, + is_outbound_from_holder: is_outbound_from_holder_arg, + counterparty_parameters: local_counterparty_parameters_arg, + funding_outpoint: local_funding_outpoint_arg, + })), is_owned: true } +} + +use lightning::ln::chan_utils::CounterpartyChannelTransactionParameters as nativeCounterpartyChannelTransactionParametersImport; +type nativeCounterpartyChannelTransactionParameters = nativeCounterpartyChannelTransactionParametersImport; + +/// Late-bound per-channel counterparty data used to build transactions. +#[must_use] +#[repr(C)] +pub struct CounterpartyChannelTransactionParameters { + /// 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 nativeCounterpartyChannelTransactionParameters, + pub is_owned: bool, +} + +impl Drop for CounterpartyChannelTransactionParameters { + fn drop(&mut self) { + if self.is_owned && !self.inner.is_null() { + let _ = unsafe { Box::from_raw(self.inner) }; + } + } +} +#[no_mangle] +pub extern "C" fn CounterpartyChannelTransactionParameters_free(this_ptr: CounterpartyChannelTransactionParameters) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +extern "C" fn CounterpartyChannelTransactionParameters_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCounterpartyChannelTransactionParameters); } +} +#[allow(unused)] +/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy +impl CounterpartyChannelTransactionParameters { + pub(crate) fn take_ptr(mut self) -> *mut nativeCounterpartyChannelTransactionParameters { + assert!(self.is_owned); + let ret = self.inner; + self.inner = std::ptr::null_mut(); + ret + } +} +impl Clone for CounterpartyChannelTransactionParameters { + fn clone(&self) -> Self { + Self { + inner: 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 CounterpartyChannelTransactionParameters_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCounterpartyChannelTransactionParameters)).clone() })) as *mut c_void +} +#[no_mangle] +pub extern "C" fn CounterpartyChannelTransactionParameters_clone(orig: &CounterpartyChannelTransactionParameters) -> CounterpartyChannelTransactionParameters { + CounterpartyChannelTransactionParameters { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } +} +/// Counter-party public keys +#[no_mangle] +pub extern "C" fn CounterpartyChannelTransactionParameters_get_pubkeys(this_ptr: &CounterpartyChannelTransactionParameters) -> crate::ln::chan_utils::ChannelPublicKeys { + let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.pubkeys; + crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false } +} +/// Counter-party public keys +#[no_mangle] +pub extern "C" fn CounterpartyChannelTransactionParameters_set_pubkeys(this_ptr: &mut CounterpartyChannelTransactionParameters, mut val: crate::ln::chan_utils::ChannelPublicKeys) { + unsafe { &mut *this_ptr.inner }.pubkeys = *unsafe { Box::from_raw(val.take_ptr()) }; +} +/// The contest delay selected by the counterparty, which applies to holder-broadcast transactions +#[no_mangle] +pub extern "C" fn CounterpartyChannelTransactionParameters_get_selected_contest_delay(this_ptr: &CounterpartyChannelTransactionParameters) -> u16 { + let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.selected_contest_delay; + (*inner_val) +} +/// The contest delay selected by the counterparty, which applies to holder-broadcast transactions +#[no_mangle] +pub extern "C" fn CounterpartyChannelTransactionParameters_set_selected_contest_delay(this_ptr: &mut CounterpartyChannelTransactionParameters, mut val: u16) { + unsafe { &mut *this_ptr.inner }.selected_contest_delay = val; +} +#[must_use] +#[no_mangle] +pub extern "C" fn CounterpartyChannelTransactionParameters_new(mut pubkeys_arg: crate::ln::chan_utils::ChannelPublicKeys, mut selected_contest_delay_arg: u16) -> CounterpartyChannelTransactionParameters { + CounterpartyChannelTransactionParameters { inner: Box::into_raw(Box::new(nativeCounterpartyChannelTransactionParameters { + pubkeys: *unsafe { Box::from_raw(pubkeys_arg.take_ptr()) }, + selected_contest_delay: selected_contest_delay_arg, + })), is_owned: true } +} +/// Whether the late bound parameters are populated. +#[must_use] +#[no_mangle] +pub extern "C" fn ChannelTransactionParameters_is_populated(this_arg: &ChannelTransactionParameters) -> bool { + let mut ret = unsafe { &*this_arg.inner }.is_populated(); + ret +} + +/// Convert the holder/counterparty parameters to broadcaster/countersignatory-organized parameters, +/// given that the holder is the broadcaster. +/// +/// self.is_populated() must be true before calling this function. +#[must_use] +#[no_mangle] +pub extern "C" fn ChannelTransactionParameters_as_holder_broadcastable(this_arg: &ChannelTransactionParameters) -> crate::ln::chan_utils::DirectedChannelTransactionParameters { + let mut ret = unsafe { &*this_arg.inner }.as_holder_broadcastable(); + crate::ln::chan_utils::DirectedChannelTransactionParameters { inner: Box::into_raw(Box::new(ret)), is_owned: true } +} + +/// Convert the holder/counterparty parameters to broadcaster/countersignatory-organized parameters, +/// given that the counterparty is the broadcaster. +/// +/// self.is_populated() must be true before calling this function. +#[must_use] +#[no_mangle] +pub extern "C" fn ChannelTransactionParameters_as_counterparty_broadcastable(this_arg: &ChannelTransactionParameters) -> crate::ln::chan_utils::DirectedChannelTransactionParameters { + let mut ret = unsafe { &*this_arg.inner }.as_counterparty_broadcastable(); + crate::ln::chan_utils::DirectedChannelTransactionParameters { inner: Box::into_raw(Box::new(ret)), is_owned: true } +} + +#[no_mangle] +pub extern "C" fn CounterpartyChannelTransactionParameters_write(obj: *const CounterpartyChannelTransactionParameters) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) +} +#[no_mangle] +pub(crate) extern "C" fn CounterpartyChannelTransactionParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCounterpartyChannelTransactionParameters) }) +} +#[no_mangle] +pub extern "C" fn CounterpartyChannelTransactionParameters_read(ser: crate::c_types::u8slice) -> CounterpartyChannelTransactionParameters { + if let Ok(res) = crate::c_types::deserialize_obj(ser) { + CounterpartyChannelTransactionParameters { inner: Box::into_raw(Box::new(res)), is_owned: true } + } else { + CounterpartyChannelTransactionParameters { inner: std::ptr::null_mut(), is_owned: true } + } +} +#[no_mangle] +pub extern "C" fn ChannelTransactionParameters_write(obj: *const ChannelTransactionParameters) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) +} +#[no_mangle] +pub(crate) extern "C" fn ChannelTransactionParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelTransactionParameters) }) +} +#[no_mangle] +pub extern "C" fn ChannelTransactionParameters_read(ser: crate::c_types::u8slice) -> ChannelTransactionParameters { + if let Ok(res) = crate::c_types::deserialize_obj(ser) { + ChannelTransactionParameters { inner: Box::into_raw(Box::new(res)), is_owned: true } + } else { + ChannelTransactionParameters { inner: std::ptr::null_mut(), is_owned: true } + } +} + +use lightning::ln::chan_utils::DirectedChannelTransactionParameters as nativeDirectedChannelTransactionParametersImport; +type nativeDirectedChannelTransactionParameters = nativeDirectedChannelTransactionParametersImport<'static>; + +/// Static channel fields used to build transactions given per-commitment fields, organized by +/// broadcaster/countersignatory. +/// +/// This is derived from the holder/counterparty-organized ChannelTransactionParameters via the +/// as_holder_broadcastable and as_counterparty_broadcastable functions. +#[must_use] +#[repr(C)] +pub struct DirectedChannelTransactionParameters { + /// 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 nativeDirectedChannelTransactionParameters, + pub is_owned: bool, +} + +impl Drop for DirectedChannelTransactionParameters { + fn drop(&mut self) { + if self.is_owned && !self.inner.is_null() { + let _ = unsafe { Box::from_raw(self.inner) }; + } + } +} +#[no_mangle] +pub extern "C" fn DirectedChannelTransactionParameters_free(this_ptr: DirectedChannelTransactionParameters) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +extern "C" fn DirectedChannelTransactionParameters_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDirectedChannelTransactionParameters); } +} +#[allow(unused)] +/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy +impl DirectedChannelTransactionParameters { + pub(crate) fn take_ptr(mut self) -> *mut nativeDirectedChannelTransactionParameters { + assert!(self.is_owned); + let ret = self.inner; + self.inner = std::ptr::null_mut(); + ret + } +} +/// Get the channel pubkeys for the broadcaster +#[must_use] +#[no_mangle] +pub extern "C" fn DirectedChannelTransactionParameters_broadcaster_pubkeys(this_arg: &DirectedChannelTransactionParameters) -> crate::ln::chan_utils::ChannelPublicKeys { + let mut ret = unsafe { &*this_arg.inner }.broadcaster_pubkeys(); + crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false } +} + +/// Get the channel pubkeys for the countersignatory +#[must_use] +#[no_mangle] +pub extern "C" fn DirectedChannelTransactionParameters_countersignatory_pubkeys(this_arg: &DirectedChannelTransactionParameters) -> crate::ln::chan_utils::ChannelPublicKeys { + let mut ret = unsafe { &*this_arg.inner }.countersignatory_pubkeys(); + crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false } +} + +/// Get the contest delay applicable to the transactions. +/// Note that the contest delay was selected by the countersignatory. +#[must_use] +#[no_mangle] +pub extern "C" fn DirectedChannelTransactionParameters_contest_delay(this_arg: &DirectedChannelTransactionParameters) -> u16 { + let mut ret = unsafe { &*this_arg.inner }.contest_delay(); + ret +} + +/// Whether the channel is outbound from the broadcaster. +/// +/// The boolean representing the side that initiated the channel is +/// an input to the commitment number obscure factor computation. +#[must_use] +#[no_mangle] +pub extern "C" fn DirectedChannelTransactionParameters_is_outbound(this_arg: &DirectedChannelTransactionParameters) -> bool { + let mut ret = unsafe { &*this_arg.inner }.is_outbound(); + ret +} + +/// The funding outpoint +#[must_use] +#[no_mangle] +pub extern "C" fn DirectedChannelTransactionParameters_funding_outpoint(this_arg: &DirectedChannelTransactionParameters) -> crate::chain::transaction::OutPoint { + let mut ret = unsafe { &*this_arg.inner }.funding_outpoint(); + crate::c_types::bitcoin_to_C_outpoint(ret) +} + + use lightning::ln::chan_utils::HolderCommitmentTransaction as nativeHolderCommitmentTransactionImport; type nativeHolderCommitmentTransaction = nativeHolderCommitmentTransactionImport; -/// We use this to track holder commitment transactions and put off signing them until we are ready -/// to broadcast. This class can be used inside a signer implementation to generate a signature -/// given the relevant secret key. +/// Information needed to build and sign a holder's commitment transaction. +/// +/// The transaction is only signed once we are ready to broadcast. #[must_use] #[repr(C)] pub struct HolderCommitmentTransaction { @@ -671,124 +979,394 @@ pub(crate) extern "C" fn HolderCommitmentTransaction_clone_void(this_ptr: *const pub extern "C" fn HolderCommitmentTransaction_clone(orig: &HolderCommitmentTransaction) -> HolderCommitmentTransaction { HolderCommitmentTransaction { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } } -/// The commitment transaction itself, in unsigned form. +/// Our counterparty's signature for the transaction +#[no_mangle] +pub extern "C" fn HolderCommitmentTransaction_get_counterparty_sig(this_ptr: &HolderCommitmentTransaction) -> crate::c_types::Signature { + let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.counterparty_sig; + crate::c_types::Signature::from_rust(&(*inner_val)) +} +/// Our counterparty's signature for the transaction +#[no_mangle] +pub extern "C" fn HolderCommitmentTransaction_set_counterparty_sig(this_ptr: &mut HolderCommitmentTransaction, mut val: crate::c_types::Signature) { + unsafe { &mut *this_ptr.inner }.counterparty_sig = val.into_rust(); +} +/// All non-dust counterparty HTLC signatures, in the order they appear in the transaction +#[no_mangle] +pub extern "C" fn HolderCommitmentTransaction_set_counterparty_htlc_sigs(this_ptr: &mut HolderCommitmentTransaction, mut val: crate::c_types::derived::CVec_SignatureZ) { + let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_rust() }); }; + unsafe { &mut *this_ptr.inner }.counterparty_htlc_sigs = local_val; +} +#[no_mangle] +pub extern "C" fn HolderCommitmentTransaction_write(obj: *const HolderCommitmentTransaction) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) +} +#[no_mangle] +pub(crate) extern "C" fn HolderCommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHolderCommitmentTransaction) }) +} +#[no_mangle] +pub extern "C" fn HolderCommitmentTransaction_read(ser: crate::c_types::u8slice) -> HolderCommitmentTransaction { + if let Ok(res) = crate::c_types::deserialize_obj(ser) { + HolderCommitmentTransaction { inner: Box::into_raw(Box::new(res)), is_owned: true } + } else { + HolderCommitmentTransaction { inner: std::ptr::null_mut(), is_owned: true } + } +} +/// Create a new holder transaction with the given counterparty signatures. +/// The funding keys are used to figure out which signature should go first when building the transaction for broadcast. +#[must_use] +#[no_mangle] +pub extern "C" fn HolderCommitmentTransaction_new(mut commitment_tx: crate::ln::chan_utils::CommitmentTransaction, mut counterparty_sig: crate::c_types::Signature, mut counterparty_htlc_sigs: crate::c_types::derived::CVec_SignatureZ, mut holder_funding_key: crate::c_types::PublicKey, mut counterparty_funding_key: crate::c_types::PublicKey) -> HolderCommitmentTransaction { + let mut local_counterparty_htlc_sigs = Vec::new(); for mut item in counterparty_htlc_sigs.into_rust().drain(..) { local_counterparty_htlc_sigs.push( { item.into_rust() }); }; + let mut ret = lightning::ln::chan_utils::HolderCommitmentTransaction::new(*unsafe { Box::from_raw(commitment_tx.take_ptr()) }, counterparty_sig.into_rust(), local_counterparty_htlc_sigs, &holder_funding_key.into_rust(), &counterparty_funding_key.into_rust()); + HolderCommitmentTransaction { inner: Box::into_raw(Box::new(ret)), is_owned: true } +} + + +use lightning::ln::chan_utils::BuiltCommitmentTransaction as nativeBuiltCommitmentTransactionImport; +type nativeBuiltCommitmentTransaction = nativeBuiltCommitmentTransactionImport; + +/// A pre-built Bitcoin commitment transaction and its txid. +#[must_use] +#[repr(C)] +pub struct BuiltCommitmentTransaction { + /// 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 nativeBuiltCommitmentTransaction, + pub is_owned: bool, +} + +impl Drop for BuiltCommitmentTransaction { + fn drop(&mut self) { + if self.is_owned && !self.inner.is_null() { + let _ = unsafe { Box::from_raw(self.inner) }; + } + } +} +#[no_mangle] +pub extern "C" fn BuiltCommitmentTransaction_free(this_ptr: BuiltCommitmentTransaction) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +extern "C" fn BuiltCommitmentTransaction_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativeBuiltCommitmentTransaction); } +} +#[allow(unused)] +/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy +impl BuiltCommitmentTransaction { + pub(crate) fn take_ptr(mut self) -> *mut nativeBuiltCommitmentTransaction { + assert!(self.is_owned); + let ret = self.inner; + self.inner = std::ptr::null_mut(); + ret + } +} +impl Clone for BuiltCommitmentTransaction { + fn clone(&self) -> Self { + Self { + inner: 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 BuiltCommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBuiltCommitmentTransaction)).clone() })) as *mut c_void +} +#[no_mangle] +pub extern "C" fn BuiltCommitmentTransaction_clone(orig: &BuiltCommitmentTransaction) -> BuiltCommitmentTransaction { + BuiltCommitmentTransaction { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } +} +/// The commitment transaction #[no_mangle] -pub extern "C" fn HolderCommitmentTransaction_get_unsigned_tx(this_ptr: &HolderCommitmentTransaction) -> crate::c_types::Transaction { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.unsigned_tx; +pub extern "C" fn BuiltCommitmentTransaction_get_transaction(this_ptr: &BuiltCommitmentTransaction) -> crate::c_types::Transaction { + let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.transaction; let mut local_inner_val = ::bitcoin::consensus::encode::serialize(inner_val); crate::c_types::Transaction::from_vec(local_inner_val) } -/// The commitment transaction itself, in unsigned form. +/// The commitment transaction #[no_mangle] -pub extern "C" fn HolderCommitmentTransaction_set_unsigned_tx(this_ptr: &mut HolderCommitmentTransaction, mut val: crate::c_types::Transaction) { - unsafe { &mut *this_ptr.inner }.unsigned_tx = val.into_bitcoin(); +pub extern "C" fn BuiltCommitmentTransaction_set_transaction(this_ptr: &mut BuiltCommitmentTransaction, mut val: crate::c_types::Transaction) { + unsafe { &mut *this_ptr.inner }.transaction = val.into_bitcoin(); } -/// Our counterparty's signature for the transaction, above. +/// The txid for the commitment transaction. +/// +/// This is provided as a performance optimization, instead of calling transaction.txid() +/// multiple times. #[no_mangle] -pub extern "C" fn HolderCommitmentTransaction_get_counterparty_sig(this_ptr: &HolderCommitmentTransaction) -> crate::c_types::Signature { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.counterparty_sig; - crate::c_types::Signature::from_rust(&(*inner_val)) +pub extern "C" fn BuiltCommitmentTransaction_get_txid(this_ptr: &BuiltCommitmentTransaction) -> *const [u8; 32] { + let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.txid; + (*inner_val).as_inner() } -/// Our counterparty's signature for the transaction, above. +/// The txid for the commitment transaction. +/// +/// This is provided as a performance optimization, instead of calling transaction.txid() +/// multiple times. #[no_mangle] -pub extern "C" fn HolderCommitmentTransaction_set_counterparty_sig(this_ptr: &mut HolderCommitmentTransaction, mut val: crate::c_types::Signature) { - unsafe { &mut *this_ptr.inner }.counterparty_sig = val.into_rust(); +pub extern "C" fn BuiltCommitmentTransaction_set_txid(this_ptr: &mut BuiltCommitmentTransaction, mut val: crate::c_types::ThirtyTwoBytes) { + unsafe { &mut *this_ptr.inner }.txid = ::bitcoin::hash_types::Txid::from_slice(&val.data[..]).unwrap(); } -/// The feerate paid per 1000-weight-unit in this commitment transaction. This value is -/// controlled by the channel initiator. +#[must_use] #[no_mangle] -pub extern "C" fn HolderCommitmentTransaction_get_feerate_per_kw(this_ptr: &HolderCommitmentTransaction) -> u32 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.feerate_per_kw; - (*inner_val) +pub extern "C" fn BuiltCommitmentTransaction_new(mut transaction_arg: crate::c_types::Transaction, mut txid_arg: crate::c_types::ThirtyTwoBytes) -> BuiltCommitmentTransaction { + BuiltCommitmentTransaction { inner: Box::into_raw(Box::new(nativeBuiltCommitmentTransaction { + transaction: transaction_arg.into_bitcoin(), + txid: ::bitcoin::hash_types::Txid::from_slice(&txid_arg.data[..]).unwrap(), + })), is_owned: true } } -/// The feerate paid per 1000-weight-unit in this commitment transaction. This value is -/// controlled by the channel initiator. #[no_mangle] -pub extern "C" fn HolderCommitmentTransaction_set_feerate_per_kw(this_ptr: &mut HolderCommitmentTransaction, mut val: u32) { - unsafe { &mut *this_ptr.inner }.feerate_per_kw = val; +pub extern "C" fn BuiltCommitmentTransaction_write(obj: *const BuiltCommitmentTransaction) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) +} +#[no_mangle] +pub(crate) extern "C" fn BuiltCommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBuiltCommitmentTransaction) }) +} +#[no_mangle] +pub extern "C" fn BuiltCommitmentTransaction_read(ser: crate::c_types::u8slice) -> BuiltCommitmentTransaction { + if let Ok(res) = crate::c_types::deserialize_obj(ser) { + BuiltCommitmentTransaction { inner: Box::into_raw(Box::new(res)), is_owned: true } + } else { + BuiltCommitmentTransaction { inner: std::ptr::null_mut(), is_owned: true } + } } -/// The HTLCs and counterparty htlc signatures which were included in this commitment transaction. +/// Get the SIGHASH_ALL sighash value of the transaction. /// -/// Note that this includes all HTLCs, including ones which were considered dust and not -/// actually included in the transaction as it appears on-chain, but who's value is burned as -/// fees and not included in the to_holder or to_counterparty outputs. +/// This can be used to verify a signature. +#[must_use] +#[no_mangle] +pub extern "C" fn BuiltCommitmentTransaction_get_sighash_all(this_arg: &BuiltCommitmentTransaction, mut funding_redeemscript: crate::c_types::u8slice, mut channel_value_satoshis: u64) -> crate::c_types::ThirtyTwoBytes { + let mut ret = unsafe { &*this_arg.inner }.get_sighash_all(&::bitcoin::blockdata::script::Script::from(Vec::from(funding_redeemscript.to_slice())), channel_value_satoshis); + crate::c_types::ThirtyTwoBytes { data: ret.as_ref().clone() } +} + +/// Sign a transaction, either because we are counter-signing the counterparty's transaction or +/// because we are about to broadcast a holder transaction. +#[must_use] +#[no_mangle] +pub extern "C" fn BuiltCommitmentTransaction_sign(this_arg: &BuiltCommitmentTransaction, funding_key: *const [u8; 32], mut funding_redeemscript: crate::c_types::u8slice, mut channel_value_satoshis: u64) -> crate::c_types::Signature { + let mut ret = unsafe { &*this_arg.inner }.sign(&::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *funding_key}[..]).unwrap(), &::bitcoin::blockdata::script::Script::from(Vec::from(funding_redeemscript.to_slice())), channel_value_satoshis, &bitcoin::secp256k1::Secp256k1::new()); + crate::c_types::Signature::from_rust(&ret) +} + + +use lightning::ln::chan_utils::CommitmentTransaction as nativeCommitmentTransactionImport; +type nativeCommitmentTransaction = nativeCommitmentTransactionImport; + +/// This class tracks the per-transaction information needed to build a commitment transaction and to +/// actually build it and sign. It is used for holder transactions that we sign only when needed +/// and for transactions we sign for the counterparty. /// -/// The counterparty HTLC signatures in the second element will always be set for non-dust HTLCs, ie -/// those for which transaction_output_index.is_some(). +/// This class can be used inside a signer implementation to generate a signature given the relevant +/// secret key. +#[must_use] +#[repr(C)] +pub struct CommitmentTransaction { + /// 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 nativeCommitmentTransaction, + pub is_owned: bool, +} + +impl Drop for CommitmentTransaction { + fn drop(&mut self) { + if self.is_owned && !self.inner.is_null() { + let _ = unsafe { Box::from_raw(self.inner) }; + } + } +} +#[no_mangle] +pub extern "C" fn CommitmentTransaction_free(this_ptr: CommitmentTransaction) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +extern "C" fn CommitmentTransaction_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCommitmentTransaction); } +} +#[allow(unused)] +/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy +impl CommitmentTransaction { + pub(crate) fn take_ptr(mut self) -> *mut nativeCommitmentTransaction { + assert!(self.is_owned); + let ret = self.inner; + self.inner = std::ptr::null_mut(); + ret + } +} +impl Clone for CommitmentTransaction { + fn clone(&self) -> Self { + Self { + inner: 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 CommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCommitmentTransaction)).clone() })) as *mut c_void +} +#[no_mangle] +pub extern "C" fn CommitmentTransaction_clone(orig: &CommitmentTransaction) -> CommitmentTransaction { + CommitmentTransaction { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } +} +#[no_mangle] +pub extern "C" fn CommitmentTransaction_write(obj: *const CommitmentTransaction) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) +} +#[no_mangle] +pub(crate) extern "C" fn CommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCommitmentTransaction) }) +} +#[no_mangle] +pub extern "C" fn CommitmentTransaction_read(ser: crate::c_types::u8slice) -> CommitmentTransaction { + if let Ok(res) = crate::c_types::deserialize_obj(ser) { + CommitmentTransaction { inner: Box::into_raw(Box::new(res)), is_owned: true } + } else { + CommitmentTransaction { inner: std::ptr::null_mut(), is_owned: true } + } +} +/// The backwards-counting commitment number +#[must_use] +#[no_mangle] +pub extern "C" fn CommitmentTransaction_commitment_number(this_arg: &CommitmentTransaction) -> u64 { + let mut ret = unsafe { &*this_arg.inner }.commitment_number(); + ret +} + +/// The value to be sent to the broadcaster +#[must_use] +#[no_mangle] +pub extern "C" fn CommitmentTransaction_to_broadcaster_value_sat(this_arg: &CommitmentTransaction) -> u64 { + let mut ret = unsafe { &*this_arg.inner }.to_broadcaster_value_sat(); + ret +} + +/// The value to be sent to the counterparty +#[must_use] #[no_mangle] -pub extern "C" fn HolderCommitmentTransaction_set_per_htlc(this_ptr: &mut HolderCommitmentTransaction, mut val: crate::c_types::derived::CVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ) { - let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { let (mut orig_val_0_0, mut orig_val_0_1) = item.to_rust(); let mut local_orig_val_0_1 = if orig_val_0_1.is_null() { None } else { Some( { orig_val_0_1.into_rust() }) }; let mut local_val_0 = (*unsafe { Box::from_raw(orig_val_0_0.take_ptr()) }, local_orig_val_0_1); local_val_0 }); }; - unsafe { &mut *this_ptr.inner }.per_htlc = local_val; +pub extern "C" fn CommitmentTransaction_to_countersignatory_value_sat(this_arg: &CommitmentTransaction) -> u64 { + let mut ret = unsafe { &*this_arg.inner }.to_countersignatory_value_sat(); + ret } -/// Generate a new HolderCommitmentTransaction based on a raw commitment transaction, -/// counterparty signature and both parties keys. + +/// The feerate paid per 1000-weight-unit in this commitment transaction. +#[must_use] +#[no_mangle] +pub extern "C" fn CommitmentTransaction_feerate_per_kw(this_arg: &CommitmentTransaction) -> u32 { + let mut ret = unsafe { &*this_arg.inner }.feerate_per_kw(); + ret +} + +/// Trust our pre-built transaction and derived transaction creation public keys. +/// +/// Applies a wrapper which allows access to these fields. /// -/// The unsigned transaction outputs must be consistent with htlc_data. This function -/// only checks that the shape and amounts are consistent, but does not check the scriptPubkey. +/// This should only be used if you fully trust the builder of this object. It should not +///\tbe used by an external signer - instead use the verify function. #[must_use] #[no_mangle] -pub extern "C" fn HolderCommitmentTransaction_new_missing_holder_sig(mut unsigned_tx: crate::c_types::Transaction, mut counterparty_sig: crate::c_types::Signature, mut holder_funding_key: crate::c_types::PublicKey, mut counterparty_funding_key: crate::c_types::PublicKey, mut keys: crate::ln::chan_utils::TxCreationKeys, mut feerate_per_kw: u32, mut htlc_data: crate::c_types::derived::CVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ) -> crate::ln::chan_utils::HolderCommitmentTransaction { - let mut local_htlc_data = Vec::new(); for mut item in htlc_data.into_rust().drain(..) { local_htlc_data.push( { let (mut orig_htlc_data_0_0, mut orig_htlc_data_0_1) = item.to_rust(); let mut local_orig_htlc_data_0_1 = if orig_htlc_data_0_1.is_null() { None } else { Some( { orig_htlc_data_0_1.into_rust() }) }; let mut local_htlc_data_0 = (*unsafe { Box::from_raw(orig_htlc_data_0_0.take_ptr()) }, local_orig_htlc_data_0_1); local_htlc_data_0 }); }; - let mut ret = lightning::ln::chan_utils::HolderCommitmentTransaction::new_missing_holder_sig(unsigned_tx.into_bitcoin(), counterparty_sig.into_rust(), &holder_funding_key.into_rust(), &counterparty_funding_key.into_rust(), *unsafe { Box::from_raw(keys.take_ptr()) }, feerate_per_kw, local_htlc_data); - crate::ln::chan_utils::HolderCommitmentTransaction { inner: Box::into_raw(Box::new(ret)), is_owned: true } +pub extern "C" fn CommitmentTransaction_trust(this_arg: &CommitmentTransaction) -> crate::ln::chan_utils::TrustedCommitmentTransaction { + let mut ret = unsafe { &*this_arg.inner }.trust(); + crate::ln::chan_utils::TrustedCommitmentTransaction { inner: Box::into_raw(Box::new(ret)), is_owned: true } } -/// The pre-calculated transaction creation public keys. -/// An external validating signer should not trust these keys. +/// Verify our pre-built transaction and derived transaction creation public keys. +/// +/// Applies a wrapper which allows access to these fields. +/// +/// An external validating signer must call this method before signing +/// or using the built transaction. #[must_use] #[no_mangle] -pub extern "C" fn HolderCommitmentTransaction_trust_key_derivation(this_arg: &HolderCommitmentTransaction) -> crate::ln::chan_utils::TxCreationKeys { - let mut ret = unsafe { &*this_arg.inner }.trust_key_derivation(); - crate::ln::chan_utils::TxCreationKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false } +pub extern "C" fn CommitmentTransaction_verify(this_arg: &CommitmentTransaction, channel_parameters: &crate::ln::chan_utils::DirectedChannelTransactionParameters, broadcaster_keys: &crate::ln::chan_utils::ChannelPublicKeys, countersignatory_keys: &crate::ln::chan_utils::ChannelPublicKeys) -> crate::c_types::derived::CResult_TrustedCommitmentTransactionNoneZ { + let mut ret = unsafe { &*this_arg.inner }.verify(unsafe { &*channel_parameters.inner }, unsafe { &*broadcaster_keys.inner }, unsafe { &*countersignatory_keys.inner }, &bitcoin::secp256k1::Secp256k1::new()); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::chan_utils::TrustedCommitmentTransaction { inner: Box::into_raw(Box::new(o)), is_owned: true } }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) }; + local_ret } -/// Get the txid of the holder commitment transaction contained in this -/// HolderCommitmentTransaction + +use lightning::ln::chan_utils::TrustedCommitmentTransaction as nativeTrustedCommitmentTransactionImport; +type nativeTrustedCommitmentTransaction = nativeTrustedCommitmentTransactionImport<'static>; + +/// A wrapper on CommitmentTransaction indicating that the derived fields (the built bitcoin +/// transaction and the transaction creation keys) are trusted. +/// +/// See trust() and verify() functions on CommitmentTransaction. +/// +/// This structure implements Deref. #[must_use] +#[repr(C)] +pub struct TrustedCommitmentTransaction { + /// 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 nativeTrustedCommitmentTransaction, + pub is_owned: bool, +} + +impl Drop for TrustedCommitmentTransaction { + fn drop(&mut self) { + if self.is_owned && !self.inner.is_null() { + let _ = unsafe { Box::from_raw(self.inner) }; + } + } +} #[no_mangle] -pub extern "C" fn HolderCommitmentTransaction_txid(this_arg: &HolderCommitmentTransaction) -> crate::c_types::ThirtyTwoBytes { +pub extern "C" fn TrustedCommitmentTransaction_free(this_ptr: TrustedCommitmentTransaction) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +extern "C" fn TrustedCommitmentTransaction_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativeTrustedCommitmentTransaction); } +} +#[allow(unused)] +/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy +impl TrustedCommitmentTransaction { + pub(crate) fn take_ptr(mut self) -> *mut nativeTrustedCommitmentTransaction { + assert!(self.is_owned); + let ret = self.inner; + self.inner = std::ptr::null_mut(); + ret + } +} +/// The transaction ID of the built Bitcoin transaction +#[must_use] +#[no_mangle] +pub extern "C" fn TrustedCommitmentTransaction_txid(this_arg: &TrustedCommitmentTransaction) -> crate::c_types::ThirtyTwoBytes { let mut ret = unsafe { &*this_arg.inner }.txid(); crate::c_types::ThirtyTwoBytes { data: ret.into_inner() } } -/// Gets holder signature for the contained commitment transaction given holder funding private key. -/// -/// Funding key is your key included in the 2-2 funding_outpoint lock. Should be provided -/// by your ChannelKeys. -/// Funding redeemscript is script locking funding_outpoint. This is the mutlsig script -/// between your own funding key and your counterparty's. Currently, this is provided in -/// ChannelKeys::sign_holder_commitment() calls directly. -/// Channel value is amount locked in funding_outpoint. +/// The pre-built Bitcoin commitment transaction #[must_use] #[no_mangle] -pub extern "C" fn HolderCommitmentTransaction_get_holder_sig(this_arg: &HolderCommitmentTransaction, funding_key: *const [u8; 32], mut funding_redeemscript: crate::c_types::u8slice, mut channel_value_satoshis: u64) -> crate::c_types::Signature { - let mut ret = unsafe { &*this_arg.inner }.get_holder_sig(&::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *funding_key}[..]).unwrap(), &::bitcoin::blockdata::script::Script::from(Vec::from(funding_redeemscript.to_slice())), channel_value_satoshis, &bitcoin::secp256k1::Secp256k1::new()); - crate::c_types::Signature::from_rust(&ret) +pub extern "C" fn TrustedCommitmentTransaction_built_transaction(this_arg: &TrustedCommitmentTransaction) -> crate::ln::chan_utils::BuiltCommitmentTransaction { + let mut ret = unsafe { &*this_arg.inner }.built_transaction(); + crate::ln::chan_utils::BuiltCommitmentTransaction { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false } +} + +/// The pre-calculated transaction creation public keys. +#[must_use] +#[no_mangle] +pub extern "C" fn TrustedCommitmentTransaction_keys(this_arg: &TrustedCommitmentTransaction) -> crate::ln::chan_utils::TxCreationKeys { + let mut ret = unsafe { &*this_arg.inner }.keys(); + crate::ln::chan_utils::TxCreationKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false } } /// Get a signature for each HTLC which was included in the commitment transaction (ie for /// which HTLCOutputInCommitment::transaction_output_index.is_some()). /// -/// The returned Vec has one entry for each HTLC, and in the same order. For HTLCs which were -/// considered dust and not included, a None entry exists, for all others a signature is -/// included. +/// The returned Vec has one entry for each HTLC, and in the same order. #[must_use] #[no_mangle] -pub extern "C" fn HolderCommitmentTransaction_get_htlc_sigs(this_arg: &HolderCommitmentTransaction, htlc_base_key: *const [u8; 32], mut counterparty_selected_contest_delay: u16) -> crate::c_types::derived::CResult_CVec_SignatureZNoneZ { - let mut ret = unsafe { &*this_arg.inner }.get_htlc_sigs(&::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *htlc_base_key}[..]).unwrap(), counterparty_selected_contest_delay, &bitcoin::secp256k1::Secp256k1::new()); - let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = Vec::new(); for item in o.drain(..) { local_ret_0.push( { let mut local_ret_0_0 = if item.is_none() { crate::c_types::Signature::null() } else { { crate::c_types::Signature::from_rust(&(item.unwrap())) } }; local_ret_0_0 }); }; local_ret_0.into() }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) }; +pub extern "C" fn TrustedCommitmentTransaction_get_htlc_sigs(this_arg: &TrustedCommitmentTransaction, htlc_base_key: *const [u8; 32], channel_parameters: &crate::ln::chan_utils::DirectedChannelTransactionParameters) -> crate::c_types::derived::CResult_CVec_SignatureZNoneZ { + let mut ret = unsafe { &*this_arg.inner }.get_htlc_sigs(&::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *htlc_base_key}[..]).unwrap(), unsafe { &*channel_parameters.inner }, &bitcoin::secp256k1::Secp256k1::new()); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = Vec::new(); for item in o.drain(..) { local_ret_0.push( { crate::c_types::Signature::from_rust(&item) }); }; local_ret_0.into() }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) }; local_ret } +/// Get the transaction number obscure factor #[no_mangle] -pub extern "C" fn HolderCommitmentTransaction_write(obj: *const HolderCommitmentTransaction) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) -} -#[no_mangle] -pub extern "C" fn HolderCommitmentTransaction_read(ser: crate::c_types::u8slice) -> HolderCommitmentTransaction { - if let Ok(res) = crate::c_types::deserialize_obj(ser) { - HolderCommitmentTransaction { inner: Box::into_raw(Box::new(res)), is_owned: true } - } else { - HolderCommitmentTransaction { inner: std::ptr::null_mut(), is_owned: true } - } +pub extern "C" fn get_commitment_transaction_number_obscure_factor(mut broadcaster_payment_basepoint: crate::c_types::PublicKey, mut countersignatory_payment_basepoint: crate::c_types::PublicKey, mut outbound_from_broadcaster: bool) -> u64 { + let mut ret = lightning::ln::chan_utils::get_commitment_transaction_number_obscure_factor(&broadcaster_payment_basepoint.into_rust(), &countersignatory_payment_basepoint.into_rust(), outbound_from_broadcaster); + ret } + diff --git a/lightning-c-bindings/src/ln/channelmanager.rs b/lightning-c-bindings/src/ln/channelmanager.rs index c21f26e94..28f0d7fc6 100644 --- a/lightning-c-bindings/src/ln/channelmanager.rs +++ b/lightning-c-bindings/src/ln/channelmanager.rs @@ -556,6 +556,16 @@ pub extern "C" fn ChannelManager_channel_monitor_updated(this_arg: &ChannelManag unsafe { &*this_arg.inner }.channel_monitor_updated(unsafe { &*funding_txo.inner }, highest_applied_update_id) } +impl From for crate::util::events::MessageSendEventsProvider { + fn from(obj: nativeChannelManager) -> Self { + let mut rust_obj = ChannelManager { inner: Box::into_raw(Box::new(obj)), is_owned: true }; + let mut ret = ChannelManager_as_MessageSendEventsProvider(&rust_obj); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn + rust_obj.inner = std::ptr::null_mut(); + ret.free = Some(ChannelManager_free_void); + ret + } +} #[no_mangle] pub extern "C" fn ChannelManager_as_MessageSendEventsProvider(this_arg: *const ChannelManager) -> crate::util::events::MessageSendEventsProvider { crate::util::events::MessageSendEventsProvider { @@ -572,6 +582,16 @@ extern "C" fn ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg local_ret.into() } +impl From for crate::util::events::EventsProvider { + fn from(obj: nativeChannelManager) -> Self { + let mut rust_obj = ChannelManager { inner: Box::into_raw(Box::new(obj)), is_owned: true }; + let mut ret = ChannelManager_as_EventsProvider(&rust_obj); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn + rust_obj.inner = std::ptr::null_mut(); + ret.free = Some(ChannelManager_free_void); + ret + } +} #[no_mangle] pub extern "C" fn ChannelManager_as_EventsProvider(this_arg: *const ChannelManager) -> crate::util::events::EventsProvider { crate::util::events::EventsProvider { @@ -604,6 +624,16 @@ pub extern "C" fn ChannelManager_block_disconnected(this_arg: &ChannelManager, h unsafe { &*this_arg.inner }.block_disconnected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap()) } +impl From for crate::ln::msgs::ChannelMessageHandler { + fn from(obj: nativeChannelManager) -> Self { + let mut rust_obj = ChannelManager { inner: Box::into_raw(Box::new(obj)), is_owned: true }; + let mut ret = ChannelManager_as_ChannelMessageHandler(&rust_obj); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn + rust_obj.inner = std::ptr::null_mut(); + ret.free = Some(ChannelManager_free_void); + ret + } +} #[no_mangle] pub extern "C" fn ChannelManager_as_ChannelMessageHandler(this_arg: *const ChannelManager) -> crate::ln::msgs::ChannelMessageHandler { crate::ln::msgs::ChannelMessageHandler { @@ -753,14 +783,16 @@ impl ChannelManagerReadArgs { } } /// The keys provider which will give us relevant keys. Some keys will be loaded during -/// deserialization. +/// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel +/// signing data. #[no_mangle] pub extern "C" fn ChannelManagerReadArgs_get_keys_manager(this_ptr: &ChannelManagerReadArgs) -> *const crate::chain::keysinterface::KeysInterface { let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.keys_manager; &(*inner_val) } /// The keys provider which will give us relevant keys. Some keys will be loaded during -/// deserialization. +/// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel +/// signing data. #[no_mangle] pub extern "C" fn ChannelManagerReadArgs_set_keys_manager(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::chain::keysinterface::KeysInterface) { unsafe { &mut *this_ptr.inner }.keys_manager = val; diff --git a/lightning-c-bindings/src/ln/msgs.rs b/lightning-c-bindings/src/ln/msgs.rs index 401da3777..6dfc94bfa 100644 --- a/lightning-c-bindings/src/ln/msgs.rs +++ b/lightning-c-bindings/src/ln/msgs.rs @@ -4149,6 +4149,12 @@ impl Drop for ChannelMessageHandler { } } /// A trait to describe an object which can receive routing messages. +/// +/// # Implementor DoS Warnings +/// +/// For `gossip_queries` messages there are potential DoS vectors when handling +/// inbound queries. Implementors using an on-disk network graph should be aware of +/// repeated disk I/O for queries accessing different parts of the network graph. #[repr(C)] pub struct RoutingMessageHandler { pub this_arg: *mut c_void, @@ -4177,13 +4183,39 @@ pub struct RoutingMessageHandler { /// If None is provided for starting_point, we start at the first node. #[must_use] pub get_next_node_announcements: extern "C" fn (this_arg: *const c_void, starting_point: crate::c_types::PublicKey, batch_amount: u8) -> crate::c_types::derived::CVec_NodeAnnouncementZ, - /// Returns whether a full sync should be requested from a peer. + /// Called when a connection is established with a peer. This can be used to + /// perform routing table synchronization using a strategy defined by the + /// implementor. + pub sync_routing_table: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, init: &crate::ln::msgs::Init), + /// Handles the reply of a query we initiated to learn about channels + /// for a given range of blocks. We can expect to receive one or more + /// replies to a single query. + #[must_use] + pub handle_reply_channel_range: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: crate::ln::msgs::ReplyChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ, + /// Handles the reply of a query we initiated asking for routing gossip + /// messages for a list of channels. We should receive this message when + /// a node has completed its best effort to send us the pertaining routing + /// gossip messages. #[must_use] - pub should_request_full_sync: extern "C" fn (this_arg: *const c_void, node_id: crate::c_types::PublicKey) -> bool, + pub handle_reply_short_channel_ids_end: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: crate::ln::msgs::ReplyShortChannelIdsEnd) -> crate::c_types::derived::CResult_NoneLightningErrorZ, + /// Handles when a peer asks us to send a list of short_channel_ids + /// for the requested range of blocks. + #[must_use] + pub handle_query_channel_range: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: crate::ln::msgs::QueryChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ, + /// Handles when a peer asks us to send routing gossip messages for a + /// list of short_channel_ids. + #[must_use] + pub handle_query_short_channel_ids: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: crate::ln::msgs::QueryShortChannelIds) -> crate::c_types::derived::CResult_NoneLightningErrorZ, + pub MessageSendEventsProvider: crate::util::events::MessageSendEventsProvider, pub free: Option, } unsafe impl Send for RoutingMessageHandler {} unsafe impl Sync for RoutingMessageHandler {} +impl lightning::util::events::MessageSendEventsProvider for RoutingMessageHandler { + fn get_and_clear_pending_msg_events(&self) -> Vec { + ::get_and_clear_pending_msg_events(&self.MessageSendEventsProvider) + } +} use lightning::ln::msgs::RoutingMessageHandler as rustRoutingMessageHandler; impl rustRoutingMessageHandler for RoutingMessageHandler { @@ -4216,9 +4248,28 @@ impl rustRoutingMessageHandler for RoutingMessageHandler { let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { *unsafe { Box::from_raw(item.take_ptr()) } }); }; local_ret } - fn should_request_full_sync(&self, node_id: &bitcoin::secp256k1::key::PublicKey) -> bool { - let mut ret = (self.should_request_full_sync)(self.this_arg, crate::c_types::PublicKey::from_rust(&node_id)); - ret + fn sync_routing_table(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, init: &lightning::ln::msgs::Init) { + (self.sync_routing_table)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::ln::msgs::Init { inner: unsafe { (init as *const _) as *mut _ }, is_owned: false }) + } + fn handle_reply_channel_range(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, msg: lightning::ln::msgs::ReplyChannelRange) -> Result<(), lightning::ln::msgs::LightningError> { + let mut ret = (self.handle_reply_channel_range)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), crate::ln::msgs::ReplyChannelRange { inner: Box::into_raw(Box::new(msg)), is_owned: true }); + let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(ret.contents.result.take_ptr()) })*/ }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(ret.contents.err.take_ptr()) }).take_ptr()) } })}; + local_ret + } + fn handle_reply_short_channel_ids_end(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, msg: lightning::ln::msgs::ReplyShortChannelIdsEnd) -> Result<(), lightning::ln::msgs::LightningError> { + let mut ret = (self.handle_reply_short_channel_ids_end)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), crate::ln::msgs::ReplyShortChannelIdsEnd { inner: Box::into_raw(Box::new(msg)), is_owned: true }); + let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(ret.contents.result.take_ptr()) })*/ }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(ret.contents.err.take_ptr()) }).take_ptr()) } })}; + local_ret + } + fn handle_query_channel_range(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, msg: lightning::ln::msgs::QueryChannelRange) -> Result<(), lightning::ln::msgs::LightningError> { + let mut ret = (self.handle_query_channel_range)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), crate::ln::msgs::QueryChannelRange { inner: Box::into_raw(Box::new(msg)), is_owned: true }); + let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(ret.contents.result.take_ptr()) })*/ }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(ret.contents.err.take_ptr()) }).take_ptr()) } })}; + local_ret + } + fn handle_query_short_channel_ids(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, msg: lightning::ln::msgs::QueryShortChannelIds) -> Result<(), lightning::ln::msgs::LightningError> { + let mut ret = (self.handle_query_short_channel_ids)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), crate::ln::msgs::QueryShortChannelIds { inner: Box::into_raw(Box::new(msg)), is_owned: true }); + let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(ret.contents.result.take_ptr()) })*/ }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(ret.contents.err.take_ptr()) }).take_ptr()) } })}; + local_ret } } @@ -4245,6 +4296,10 @@ pub extern "C" fn AcceptChannel_write(obj: *const AcceptChannel) -> crate::c_typ crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn AcceptChannel_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeAcceptChannel) }) +} +#[no_mangle] pub extern "C" fn AcceptChannel_read(ser: crate::c_types::u8slice) -> AcceptChannel { if let Ok(res) = crate::c_types::deserialize_obj(ser) { AcceptChannel { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4257,6 +4312,10 @@ pub extern "C" fn AnnouncementSignatures_write(obj: *const AnnouncementSignature crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn AnnouncementSignatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeAnnouncementSignatures) }) +} +#[no_mangle] pub extern "C" fn AnnouncementSignatures_read(ser: crate::c_types::u8slice) -> AnnouncementSignatures { if let Ok(res) = crate::c_types::deserialize_obj(ser) { AnnouncementSignatures { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4269,6 +4328,10 @@ pub extern "C" fn ChannelReestablish_write(obj: *const ChannelReestablish) -> cr crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn ChannelReestablish_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelReestablish) }) +} +#[no_mangle] pub extern "C" fn ChannelReestablish_read(ser: crate::c_types::u8slice) -> ChannelReestablish { if let Ok(res) = crate::c_types::deserialize_obj(ser) { ChannelReestablish { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4281,6 +4344,10 @@ pub extern "C" fn ClosingSigned_write(obj: *const ClosingSigned) -> crate::c_typ crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn ClosingSigned_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeClosingSigned) }) +} +#[no_mangle] pub extern "C" fn ClosingSigned_read(ser: crate::c_types::u8slice) -> ClosingSigned { if let Ok(res) = crate::c_types::deserialize_obj(ser) { ClosingSigned { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4293,6 +4360,10 @@ pub extern "C" fn CommitmentSigned_write(obj: *const CommitmentSigned) -> crate: crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn CommitmentSigned_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCommitmentSigned) }) +} +#[no_mangle] pub extern "C" fn CommitmentSigned_read(ser: crate::c_types::u8slice) -> CommitmentSigned { if let Ok(res) = crate::c_types::deserialize_obj(ser) { CommitmentSigned { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4305,6 +4376,10 @@ pub extern "C" fn FundingCreated_write(obj: *const FundingCreated) -> crate::c_t crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn FundingCreated_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeFundingCreated) }) +} +#[no_mangle] pub extern "C" fn FundingCreated_read(ser: crate::c_types::u8slice) -> FundingCreated { if let Ok(res) = crate::c_types::deserialize_obj(ser) { FundingCreated { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4317,6 +4392,10 @@ pub extern "C" fn FundingSigned_write(obj: *const FundingSigned) -> crate::c_typ crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn FundingSigned_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeFundingSigned) }) +} +#[no_mangle] pub extern "C" fn FundingSigned_read(ser: crate::c_types::u8slice) -> FundingSigned { if let Ok(res) = crate::c_types::deserialize_obj(ser) { FundingSigned { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4329,6 +4408,10 @@ pub extern "C" fn FundingLocked_write(obj: *const FundingLocked) -> crate::c_typ crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn FundingLocked_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeFundingLocked) }) +} +#[no_mangle] pub extern "C" fn FundingLocked_read(ser: crate::c_types::u8slice) -> FundingLocked { if let Ok(res) = crate::c_types::deserialize_obj(ser) { FundingLocked { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4341,6 +4424,10 @@ pub extern "C" fn Init_write(obj: *const Init) -> crate::c_types::derived::CVec_ crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn Init_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInit) }) +} +#[no_mangle] pub extern "C" fn Init_read(ser: crate::c_types::u8slice) -> Init { if let Ok(res) = crate::c_types::deserialize_obj(ser) { Init { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4353,6 +4440,10 @@ pub extern "C" fn OpenChannel_write(obj: *const OpenChannel) -> crate::c_types:: crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn OpenChannel_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeOpenChannel) }) +} +#[no_mangle] pub extern "C" fn OpenChannel_read(ser: crate::c_types::u8slice) -> OpenChannel { if let Ok(res) = crate::c_types::deserialize_obj(ser) { OpenChannel { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4365,6 +4456,10 @@ pub extern "C" fn RevokeAndACK_write(obj: *const RevokeAndACK) -> crate::c_types crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn RevokeAndACK_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRevokeAndACK) }) +} +#[no_mangle] pub extern "C" fn RevokeAndACK_read(ser: crate::c_types::u8slice) -> RevokeAndACK { if let Ok(res) = crate::c_types::deserialize_obj(ser) { RevokeAndACK { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4377,6 +4472,10 @@ pub extern "C" fn Shutdown_write(obj: *const Shutdown) -> crate::c_types::derive crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn Shutdown_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeShutdown) }) +} +#[no_mangle] pub extern "C" fn Shutdown_read(ser: crate::c_types::u8slice) -> Shutdown { if let Ok(res) = crate::c_types::deserialize_obj(ser) { Shutdown { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4389,6 +4488,10 @@ pub extern "C" fn UpdateFailHTLC_write(obj: *const UpdateFailHTLC) -> crate::c_t crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn UpdateFailHTLC_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUpdateFailHTLC) }) +} +#[no_mangle] pub extern "C" fn UpdateFailHTLC_read(ser: crate::c_types::u8slice) -> UpdateFailHTLC { if let Ok(res) = crate::c_types::deserialize_obj(ser) { UpdateFailHTLC { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4401,6 +4504,10 @@ pub extern "C" fn UpdateFailMalformedHTLC_write(obj: *const UpdateFailMalformedH crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn UpdateFailMalformedHTLC_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUpdateFailMalformedHTLC) }) +} +#[no_mangle] pub extern "C" fn UpdateFailMalformedHTLC_read(ser: crate::c_types::u8slice) -> UpdateFailMalformedHTLC { if let Ok(res) = crate::c_types::deserialize_obj(ser) { UpdateFailMalformedHTLC { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4413,6 +4520,10 @@ pub extern "C" fn UpdateFee_write(obj: *const UpdateFee) -> crate::c_types::deri crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn UpdateFee_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUpdateFee) }) +} +#[no_mangle] pub extern "C" fn UpdateFee_read(ser: crate::c_types::u8slice) -> UpdateFee { if let Ok(res) = crate::c_types::deserialize_obj(ser) { UpdateFee { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4425,6 +4536,10 @@ pub extern "C" fn UpdateFulfillHTLC_write(obj: *const UpdateFulfillHTLC) -> crat crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn UpdateFulfillHTLC_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUpdateFulfillHTLC) }) +} +#[no_mangle] pub extern "C" fn UpdateFulfillHTLC_read(ser: crate::c_types::u8slice) -> UpdateFulfillHTLC { if let Ok(res) = crate::c_types::deserialize_obj(ser) { UpdateFulfillHTLC { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4437,6 +4552,10 @@ pub extern "C" fn UpdateAddHTLC_write(obj: *const UpdateAddHTLC) -> crate::c_typ crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn UpdateAddHTLC_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUpdateAddHTLC) }) +} +#[no_mangle] pub extern "C" fn UpdateAddHTLC_read(ser: crate::c_types::u8slice) -> UpdateAddHTLC { if let Ok(res) = crate::c_types::deserialize_obj(ser) { UpdateAddHTLC { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4449,6 +4568,10 @@ pub extern "C" fn Ping_write(obj: *const Ping) -> crate::c_types::derived::CVec_ crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn Ping_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePing) }) +} +#[no_mangle] pub extern "C" fn Ping_read(ser: crate::c_types::u8slice) -> Ping { if let Ok(res) = crate::c_types::deserialize_obj(ser) { Ping { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4461,6 +4584,10 @@ pub extern "C" fn Pong_write(obj: *const Pong) -> crate::c_types::derived::CVec_ crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn Pong_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePong) }) +} +#[no_mangle] pub extern "C" fn Pong_read(ser: crate::c_types::u8slice) -> Pong { if let Ok(res) = crate::c_types::deserialize_obj(ser) { Pong { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4473,6 +4600,10 @@ pub extern "C" fn UnsignedChannelAnnouncement_write(obj: *const UnsignedChannelA crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn UnsignedChannelAnnouncement_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUnsignedChannelAnnouncement) }) +} +#[no_mangle] pub extern "C" fn UnsignedChannelAnnouncement_read(ser: crate::c_types::u8slice) -> UnsignedChannelAnnouncement { if let Ok(res) = crate::c_types::deserialize_obj(ser) { UnsignedChannelAnnouncement { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4485,6 +4616,10 @@ pub extern "C" fn ChannelAnnouncement_write(obj: *const ChannelAnnouncement) -> crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn ChannelAnnouncement_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelAnnouncement) }) +} +#[no_mangle] pub extern "C" fn ChannelAnnouncement_read(ser: crate::c_types::u8slice) -> ChannelAnnouncement { if let Ok(res) = crate::c_types::deserialize_obj(ser) { ChannelAnnouncement { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4497,6 +4632,10 @@ pub extern "C" fn UnsignedChannelUpdate_write(obj: *const UnsignedChannelUpdate) crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn UnsignedChannelUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUnsignedChannelUpdate) }) +} +#[no_mangle] pub extern "C" fn UnsignedChannelUpdate_read(ser: crate::c_types::u8slice) -> UnsignedChannelUpdate { if let Ok(res) = crate::c_types::deserialize_obj(ser) { UnsignedChannelUpdate { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4509,6 +4648,10 @@ pub extern "C" fn ChannelUpdate_write(obj: *const ChannelUpdate) -> crate::c_typ crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn ChannelUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelUpdate) }) +} +#[no_mangle] pub extern "C" fn ChannelUpdate_read(ser: crate::c_types::u8slice) -> ChannelUpdate { if let Ok(res) = crate::c_types::deserialize_obj(ser) { ChannelUpdate { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4521,6 +4664,10 @@ pub extern "C" fn ErrorMessage_write(obj: *const ErrorMessage) -> crate::c_types crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn ErrorMessage_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeErrorMessage) }) +} +#[no_mangle] pub extern "C" fn ErrorMessage_read(ser: crate::c_types::u8slice) -> ErrorMessage { if let Ok(res) = crate::c_types::deserialize_obj(ser) { ErrorMessage { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4533,6 +4680,10 @@ pub extern "C" fn UnsignedNodeAnnouncement_write(obj: *const UnsignedNodeAnnounc crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn UnsignedNodeAnnouncement_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUnsignedNodeAnnouncement) }) +} +#[no_mangle] pub extern "C" fn UnsignedNodeAnnouncement_read(ser: crate::c_types::u8slice) -> UnsignedNodeAnnouncement { if let Ok(res) = crate::c_types::deserialize_obj(ser) { UnsignedNodeAnnouncement { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4545,6 +4696,10 @@ pub extern "C" fn NodeAnnouncement_write(obj: *const NodeAnnouncement) -> crate: crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn NodeAnnouncement_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncement) }) +} +#[no_mangle] pub extern "C" fn NodeAnnouncement_read(ser: crate::c_types::u8slice) -> NodeAnnouncement { if let Ok(res) = crate::c_types::deserialize_obj(ser) { NodeAnnouncement { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4565,6 +4720,10 @@ pub extern "C" fn QueryShortChannelIds_write(obj: *const QueryShortChannelIds) - crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn QueryShortChannelIds_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeQueryShortChannelIds) }) +} +#[no_mangle] pub extern "C" fn ReplyShortChannelIdsEnd_read(ser: crate::c_types::u8slice) -> ReplyShortChannelIdsEnd { if let Ok(res) = crate::c_types::deserialize_obj(ser) { ReplyShortChannelIdsEnd { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4577,6 +4736,10 @@ pub extern "C" fn ReplyShortChannelIdsEnd_write(obj: *const ReplyShortChannelIds crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn ReplyShortChannelIdsEnd_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeReplyShortChannelIdsEnd) }) +} +#[no_mangle] pub extern "C" fn QueryChannelRange_read(ser: crate::c_types::u8slice) -> QueryChannelRange { if let Ok(res) = crate::c_types::deserialize_obj(ser) { QueryChannelRange { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4589,6 +4752,10 @@ pub extern "C" fn QueryChannelRange_write(obj: *const QueryChannelRange) -> crat crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn QueryChannelRange_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeQueryChannelRange) }) +} +#[no_mangle] pub extern "C" fn ReplyChannelRange_read(ser: crate::c_types::u8slice) -> ReplyChannelRange { if let Ok(res) = crate::c_types::deserialize_obj(ser) { ReplyChannelRange { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4601,6 +4768,10 @@ pub extern "C" fn ReplyChannelRange_write(obj: *const ReplyChannelRange) -> crat crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn ReplyChannelRange_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeReplyChannelRange) }) +} +#[no_mangle] pub extern "C" fn GossipTimestampFilter_read(ser: crate::c_types::u8slice) -> GossipTimestampFilter { if let Ok(res) = crate::c_types::deserialize_obj(ser) { GossipTimestampFilter { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -4612,3 +4783,7 @@ pub extern "C" fn GossipTimestampFilter_read(ser: crate::c_types::u8slice) -> Go pub extern "C" fn GossipTimestampFilter_write(obj: *const GossipTimestampFilter) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } +#[no_mangle] +pub(crate) extern "C" fn GossipTimestampFilter_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeGossipTimestampFilter) }) +} diff --git a/lightning-c-bindings/src/routing/network_graph.rs b/lightning-c-bindings/src/routing/network_graph.rs index b4c8de585..9f80bc6d9 100644 --- a/lightning-c-bindings/src/routing/network_graph.rs +++ b/lightning-c-bindings/src/routing/network_graph.rs @@ -131,9 +131,9 @@ impl NetGraphMsgHandler { /// channel owners' keys. #[must_use] #[no_mangle] -pub extern "C" fn NetGraphMsgHandler_new(chain_access: *mut crate::chain::Access, mut logger: crate::util::logger::Logger) -> NetGraphMsgHandler { +pub extern "C" fn NetGraphMsgHandler_new(mut genesis_hash: crate::c_types::ThirtyTwoBytes, chain_access: *mut crate::chain::Access, mut logger: crate::util::logger::Logger) -> NetGraphMsgHandler { let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) }; - let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::new(local_chain_access, logger); + let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::new(::bitcoin::hash_types::BlockHash::from_slice(&genesis_hash.data[..]).unwrap(), local_chain_access, logger); NetGraphMsgHandler { inner: Box::into_raw(Box::new(ret)), is_owned: true } } @@ -166,6 +166,16 @@ pub extern "C" fn LockedNetworkGraph_graph(this_arg: &LockedNetworkGraph) -> cra crate::routing::network_graph::NetworkGraph { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false } } +impl From for crate::ln::msgs::RoutingMessageHandler { + fn from(obj: nativeNetGraphMsgHandler) -> Self { + let mut rust_obj = NetGraphMsgHandler { inner: Box::into_raw(Box::new(obj)), is_owned: true }; + let mut ret = NetGraphMsgHandler_as_RoutingMessageHandler(&rust_obj); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn + rust_obj.inner = std::ptr::null_mut(); + ret.free = Some(NetGraphMsgHandler_free_void); + ret + } +} #[no_mangle] pub extern "C" fn NetGraphMsgHandler_as_RoutingMessageHandler(this_arg: *const NetGraphMsgHandler) -> crate::ln::msgs::RoutingMessageHandler { crate::ln::msgs::RoutingMessageHandler { @@ -177,7 +187,16 @@ pub extern "C" fn NetGraphMsgHandler_as_RoutingMessageHandler(this_arg: *const N handle_htlc_fail_channel_update: NetGraphMsgHandler_RoutingMessageHandler_handle_htlc_fail_channel_update, get_next_channel_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_channel_announcements, get_next_node_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_node_announcements, - should_request_full_sync: NetGraphMsgHandler_RoutingMessageHandler_should_request_full_sync, + sync_routing_table: NetGraphMsgHandler_RoutingMessageHandler_sync_routing_table, + handle_reply_channel_range: NetGraphMsgHandler_RoutingMessageHandler_handle_reply_channel_range, + handle_reply_short_channel_ids_end: NetGraphMsgHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end, + handle_query_channel_range: NetGraphMsgHandler_RoutingMessageHandler_handle_query_channel_range, + handle_query_short_channel_ids: NetGraphMsgHandler_RoutingMessageHandler_handle_query_short_channel_ids, + MessageSendEventsProvider: crate::util::events::MessageSendEventsProvider { + this_arg: unsafe { (*this_arg).inner as *mut c_void }, + free: None, + get_and_clear_pending_msg_events: NetGraphMsgHandler_RoutingMessageHandler_get_and_clear_pending_msg_events, + }, } } use lightning::ln::msgs::RoutingMessageHandler as RoutingMessageHandlerTraitImport; @@ -215,10 +234,65 @@ extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_get_next_node_announcemen let mut local_ret = Vec::new(); for item in ret.drain(..) { local_ret.push( { crate::ln::msgs::NodeAnnouncement { inner: Box::into_raw(Box::new(item)), is_owned: true } }); }; local_ret.into() } +extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_sync_routing_table(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, init_msg: &crate::ln::msgs::Init) { + unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.sync_routing_table(&their_node_id.into_rust(), unsafe { &*init_msg.inner }) +} #[must_use] -extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_should_request_full_sync(this_arg: *const c_void, mut _node_id: crate::c_types::PublicKey) -> bool { - let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.should_request_full_sync(&_node_id.into_rust()); - ret +extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_reply_channel_range(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut msg: crate::ln::msgs::ReplyChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ { + let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_reply_channel_range(&their_node_id.into_rust(), *unsafe { Box::from_raw(msg.take_ptr()) }); + 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 } }) }; + local_ret +} +#[must_use] +extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut msg: crate::ln::msgs::ReplyShortChannelIdsEnd) -> crate::c_types::derived::CResult_NoneLightningErrorZ { + let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_reply_short_channel_ids_end(&their_node_id.into_rust(), *unsafe { Box::from_raw(msg.take_ptr()) }); + 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 } }) }; + local_ret +} +#[must_use] +extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_query_channel_range(this_arg: *const c_void, mut _their_node_id: crate::c_types::PublicKey, mut _msg: crate::ln::msgs::QueryChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ { + let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_query_channel_range(&_their_node_id.into_rust(), *unsafe { Box::from_raw(_msg.take_ptr()) }); + 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 } }) }; + local_ret +} +#[must_use] +extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_query_short_channel_ids(this_arg: *const c_void, mut _their_node_id: crate::c_types::PublicKey, mut _msg: crate::ln::msgs::QueryShortChannelIds) -> crate::c_types::derived::CResult_NoneLightningErrorZ { + let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_query_short_channel_ids(&_their_node_id.into_rust(), *unsafe { Box::from_raw(_msg.take_ptr()) }); + 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 } }) }; + local_ret +} +use lightning::util::events::MessageSendEventsProvider as nativeMessageSendEventsProviderTrait; +#[must_use] +extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ { + let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.get_and_clear_pending_msg_events(); + let mut local_ret = Vec::new(); for item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); }; + local_ret.into() +} + +impl From for crate::util::events::MessageSendEventsProvider { + fn from(obj: nativeNetGraphMsgHandler) -> Self { + let mut rust_obj = NetGraphMsgHandler { inner: Box::into_raw(Box::new(obj)), is_owned: true }; + let mut ret = NetGraphMsgHandler_as_MessageSendEventsProvider(&rust_obj); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn + rust_obj.inner = std::ptr::null_mut(); + ret.free = Some(NetGraphMsgHandler_free_void); + ret + } +} +#[no_mangle] +pub extern "C" fn NetGraphMsgHandler_as_MessageSendEventsProvider(this_arg: *const NetGraphMsgHandler) -> crate::util::events::MessageSendEventsProvider { + crate::util::events::MessageSendEventsProvider { + this_arg: unsafe { (*this_arg).inner as *mut c_void }, + free: None, + get_and_clear_pending_msg_events: NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events, + } +} +use lightning::util::events::MessageSendEventsProvider as MessageSendEventsProviderTraitImport; +#[must_use] +extern "C" fn NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ { + let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.get_and_clear_pending_msg_events(); + let mut local_ret = Vec::new(); for item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); }; + local_ret.into() } @@ -306,6 +380,17 @@ pub extern "C" fn DirectionalChannelInfo_get_htlc_minimum_msat(this_ptr: &Direct pub extern "C" fn DirectionalChannelInfo_set_htlc_minimum_msat(this_ptr: &mut DirectionalChannelInfo, mut val: u64) { unsafe { &mut *this_ptr.inner }.htlc_minimum_msat = val; } +/// Fees charged when the channel is used for routing +#[no_mangle] +pub extern "C" fn DirectionalChannelInfo_get_fees(this_ptr: &DirectionalChannelInfo) -> crate::routing::network_graph::RoutingFees { + let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fees; + crate::routing::network_graph::RoutingFees { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false } +} +/// Fees charged when the channel is used for routing +#[no_mangle] +pub extern "C" fn DirectionalChannelInfo_set_fees(this_ptr: &mut DirectionalChannelInfo, mut val: crate::routing::network_graph::RoutingFees) { + unsafe { &mut *this_ptr.inner }.fees = *unsafe { Box::from_raw(val.take_ptr()) }; +} /// Most recent update for the channel received from the network /// Mostly redundant with the data we store in fields explicitly. /// Everything else is useful only for sending out for initial routing sync. @@ -330,6 +415,10 @@ pub extern "C" fn DirectionalChannelInfo_write(obj: *const DirectionalChannelInf crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn DirectionalChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeDirectionalChannelInfo) }) +} +#[no_mangle] pub extern "C" fn DirectionalChannelInfo_read(ser: crate::c_types::u8slice) -> DirectionalChannelInfo { if let Ok(res) = crate::c_types::deserialize_obj(ser) { DirectionalChannelInfo { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -459,6 +548,10 @@ pub extern "C" fn ChannelInfo_write(obj: *const ChannelInfo) -> crate::c_types:: crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn ChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelInfo) }) +} +#[no_mangle] pub extern "C" fn ChannelInfo_read(ser: crate::c_types::u8slice) -> ChannelInfo { if let Ok(res) = crate::c_types::deserialize_obj(ser) { ChannelInfo { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -565,6 +658,10 @@ pub extern "C" fn RoutingFees_read(ser: crate::c_types::u8slice) -> RoutingFees pub extern "C" fn RoutingFees_write(obj: *const RoutingFees) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } +#[no_mangle] +pub(crate) extern "C" fn RoutingFees_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoutingFees) }) +} use lightning::routing::network_graph::NodeAnnouncementInfo as nativeNodeAnnouncementInfoImport; type nativeNodeAnnouncementInfo = nativeNodeAnnouncementInfoImport; @@ -697,6 +794,10 @@ pub extern "C" fn NodeAnnouncementInfo_write(obj: *const NodeAnnouncementInfo) - crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn NodeAnnouncementInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncementInfo) }) +} +#[no_mangle] pub extern "C" fn NodeAnnouncementInfo_read(ser: crate::c_types::u8slice) -> NodeAnnouncementInfo { if let Ok(res) = crate::c_types::deserialize_obj(ser) { NodeAnnouncementInfo { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -799,6 +900,10 @@ pub extern "C" fn NodeInfo_write(obj: *const NodeInfo) -> crate::c_types::derive crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn NodeInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeInfo) }) +} +#[no_mangle] pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> NodeInfo { if let Ok(res) = crate::c_types::deserialize_obj(ser) { NodeInfo { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -811,6 +916,10 @@ pub extern "C" fn NetworkGraph_write(obj: *const NetworkGraph) -> crate::c_types crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn NetworkGraph_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNetworkGraph) }) +} +#[no_mangle] pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice) -> NetworkGraph { if let Ok(res) = crate::c_types::deserialize_obj(ser) { NetworkGraph { inner: Box::into_raw(Box::new(res)), is_owned: true } @@ -821,8 +930,8 @@ pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice) -> NetworkGrap /// Creates a new, empty, network graph. #[must_use] #[no_mangle] -pub extern "C" fn NetworkGraph_new() -> crate::routing::network_graph::NetworkGraph { - let mut ret = lightning::routing::network_graph::NetworkGraph::new(); +pub extern "C" fn NetworkGraph_new(mut genesis_hash: crate::c_types::ThirtyTwoBytes) -> crate::routing::network_graph::NetworkGraph { + let mut ret = lightning::routing::network_graph::NetworkGraph::new(::bitcoin::hash_types::BlockHash::from_slice(&genesis_hash.data[..]).unwrap()); crate::routing::network_graph::NetworkGraph { inner: Box::into_raw(Box::new(ret)), is_owned: true } } diff --git a/lightning-c-bindings/src/routing/router.rs b/lightning-c-bindings/src/routing/router.rs index 8be952833..095c1598a 100644 --- a/lightning-c-bindings/src/routing/router.rs +++ b/lightning-c-bindings/src/routing/router.rs @@ -226,6 +226,10 @@ pub extern "C" fn Route_write(obj: *const Route) -> crate::c_types::derived::CVe crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn Route_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoute) }) +} +#[no_mangle] pub extern "C" fn Route_read(ser: crate::c_types::u8slice) -> Route { if let Ok(res) = crate::c_types::deserialize_obj(ser) { Route { inner: Box::into_raw(Box::new(res)), is_owned: true } diff --git a/lightning-c-bindings/src/util/config.rs b/lightning-c-bindings/src/util/config.rs index 346ddc344..d4ffe1fbb 100644 --- a/lightning-c-bindings/src/util/config.rs +++ b/lightning-c-bindings/src/util/config.rs @@ -589,6 +589,10 @@ pub extern "C" fn ChannelConfig_write(obj: *const ChannelConfig) -> crate::c_typ crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) }) } #[no_mangle] +pub(crate) extern "C" fn ChannelConfig_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelConfig) }) +} +#[no_mangle] pub extern "C" fn ChannelConfig_read(ser: crate::c_types::u8slice) -> ChannelConfig { if let Ok(res) = crate::c_types::deserialize_obj(ser) { ChannelConfig { inner: Box::into_raw(Box::new(res)), is_owned: true } diff --git a/lightning-c-bindings/src/util/events.rs b/lightning-c-bindings/src/util/events.rs index e596774b6..8ee99485b 100644 --- a/lightning-c-bindings/src/util/events.rs +++ b/lightning-c-bindings/src/util/events.rs @@ -407,6 +407,17 @@ pub enum MessageSendEvent { PaymentFailureNetworkUpdate { update: crate::ln::msgs::HTLCFailChannelUpdate, }, + /// Query a peer for channels with funding transaction UTXOs in a block range. + SendChannelRangeQuery { + node_id: crate::c_types::PublicKey, + msg: crate::ln::msgs::QueryChannelRange, + }, + /// Request routing gossip messages from a peer for a list of channels identified by + /// their short_channel_ids. + SendShortIdsQuery { + node_id: crate::c_types::PublicKey, + msg: crate::ln::msgs::QueryShortChannelIds, + }, } use lightning::util::events::MessageSendEvent as nativeMessageSendEvent; impl MessageSendEvent { @@ -535,6 +546,22 @@ impl MessageSendEvent { update: update_nonref.into_native(), } }, + MessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => { + let mut node_id_nonref = (*node_id).clone(); + let mut msg_nonref = (*msg).clone(); + nativeMessageSendEvent::SendChannelRangeQuery { + node_id: node_id_nonref.into_rust(), + msg: *unsafe { Box::from_raw(msg_nonref.take_ptr()) }, + } + }, + MessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => { + let mut node_id_nonref = (*node_id).clone(); + let mut msg_nonref = (*msg).clone(); + nativeMessageSendEvent::SendShortIdsQuery { + node_id: node_id_nonref.into_rust(), + msg: *unsafe { Box::from_raw(msg_nonref.take_ptr()) }, + } + }, } } #[allow(unused)] @@ -633,6 +660,18 @@ impl MessageSendEvent { update: update.into_native(), } }, + MessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => { + nativeMessageSendEvent::SendChannelRangeQuery { + node_id: node_id.into_rust(), + msg: *unsafe { Box::from_raw(msg.take_ptr()) }, + } + }, + MessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => { + nativeMessageSendEvent::SendShortIdsQuery { + node_id: node_id.into_rust(), + msg: *unsafe { Box::from_raw(msg.take_ptr()) }, + } + }, } } #[allow(unused)] @@ -760,6 +799,22 @@ impl MessageSendEvent { update: crate::ln::msgs::HTLCFailChannelUpdate::native_into(update_nonref), } }, + nativeMessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => { + let mut node_id_nonref = (*node_id).clone(); + let mut msg_nonref = (*msg).clone(); + MessageSendEvent::SendChannelRangeQuery { + node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref), + msg: crate::ln::msgs::QueryChannelRange { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true }, + } + }, + nativeMessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => { + let mut node_id_nonref = (*node_id).clone(); + let mut msg_nonref = (*msg).clone(); + MessageSendEvent::SendShortIdsQuery { + node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref), + msg: crate::ln::msgs::QueryShortChannelIds { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true }, + } + }, } } #[allow(unused)] @@ -858,6 +913,18 @@ impl MessageSendEvent { update: crate::ln::msgs::HTLCFailChannelUpdate::native_into(update), } }, + nativeMessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => { + MessageSendEvent::SendChannelRangeQuery { + node_id: crate::c_types::PublicKey::from_rust(&node_id), + msg: crate::ln::msgs::QueryChannelRange { inner: Box::into_raw(Box::new(msg)), is_owned: true }, + } + }, + nativeMessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => { + MessageSendEvent::SendShortIdsQuery { + node_id: crate::c_types::PublicKey::from_rust(&node_id), + msg: crate::ln::msgs::QueryShortChannelIds { inner: Box::into_raw(Box::new(msg)), is_owned: true }, + } + }, } } } diff --git a/lightning-c-bindings/src/util/ser.rs b/lightning-c-bindings/src/util/ser.rs index deb9383ae..db9549c65 100644 --- a/lightning-c-bindings/src/util/ser.rs +++ b/lightning-c-bindings/src/util/ser.rs @@ -5,3 +5,6 @@ use std::ffi::c_void; use bitcoin::hashes::Hash; use crate::c_types::*; + +#[no_mangle] +pub static MAX_BUF_SIZE: usize = lightning::util::ser::MAX_BUF_SIZE; -- 2.39.5