Skip to content

Commit 5f09772

Browse files
committed
- bindings updates
1 parent b7538b6 commit 5f09772

File tree

10 files changed

+694
-218
lines changed

10 files changed

+694
-218
lines changed

lightning-c-bindings/include/lightning.h

Lines changed: 213 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,21 +1551,20 @@ typedef struct LDKCResult_NoneChannelMonitorUpdateErrZ {
15511551

15521552

15531553
/**
1554-
* An event to be processed by the ChannelManager.
1554+
* Simple structure sent back by `chain::Watch` when an HTLC from a forward channel is detected on
1555+
* chain. Used to update the corresponding HTLC in the backward channel. Failing to pass the
1556+
* preimage claim backward will lead to loss of funds.
1557+
*
1558+
* [`chain::Watch`]: ../trait.Watch.html
15551559
*/
1556-
typedef struct MUST_USE_STRUCT LDKMonitorEvent {
1560+
typedef struct MUST_USE_STRUCT LDKHTLCUpdate {
15571561
/**
15581562
* Nearly everywhere, inner must be non-null, however in places where
15591563
* the Rust equivalent takes an Option, it may be set to null to indicate None.
15601564
*/
1561-
LDKnativeMonitorEvent *inner;
1565+
LDKnativeHTLCUpdate *inner;
15621566
bool is_owned;
1563-
} LDKMonitorEvent;
1564-
1565-
typedef struct LDKCVec_MonitorEventZ {
1566-
struct LDKMonitorEvent *data;
1567-
uintptr_t datalen;
1568-
} LDKCVec_MonitorEventZ;
1567+
} LDKHTLCUpdate;
15691568

15701569

15711570

@@ -1584,22 +1583,150 @@ typedef struct MUST_USE_STRUCT LDKOutPoint {
15841583
bool is_owned;
15851584
} LDKOutPoint;
15861585

1586+
/**
1587+
* An event to be processed by the ChannelManager.
1588+
*/
1589+
typedef enum LDKMonitorEvent_Tag {
1590+
/**
1591+
* A monitor event containing an HTLCUpdate.
1592+
*/
1593+
LDKMonitorEvent_HTLCEvent,
1594+
/**
1595+
* A monitor event that the Channel's commitment transaction was broadcasted.
1596+
*/
1597+
LDKMonitorEvent_CommitmentTxBroadcasted,
1598+
/**
1599+
* Must be last for serialization purposes
1600+
*/
1601+
LDKMonitorEvent_Sentinel,
1602+
} LDKMonitorEvent_Tag;
1603+
1604+
typedef struct MUST_USE_STRUCT LDKMonitorEvent {
1605+
LDKMonitorEvent_Tag tag;
1606+
union {
1607+
struct {
1608+
struct LDKHTLCUpdate htlc_event;
1609+
};
1610+
struct {
1611+
struct LDKOutPoint commitment_tx_broadcasted;
1612+
};
1613+
};
1614+
} LDKMonitorEvent;
1615+
1616+
typedef struct LDKCVec_MonitorEventZ {
1617+
struct LDKMonitorEvent *data;
1618+
uintptr_t datalen;
1619+
} LDKCVec_MonitorEventZ;
1620+
1621+
1622+
1623+
/**
1624+
* Information about a spendable output to a P2WSH script. See
1625+
* SpendableOutputDescriptor::DelayedPaymentOutput for more details on how to spend this.
1626+
*/
1627+
typedef struct MUST_USE_STRUCT LDKDelayedPaymentOutputDescriptor {
1628+
/**
1629+
* Nearly everywhere, inner must be non-null, however in places where
1630+
* the Rust equivalent takes an Option, it may be set to null to indicate None.
1631+
*/
1632+
LDKnativeDelayedPaymentOutputDescriptor *inner;
1633+
bool is_owned;
1634+
} LDKDelayedPaymentOutputDescriptor;
1635+
15871636

15881637

1638+
/**
1639+
* Information about a spendable output to our \"payment key\". See
1640+
* SpendableOutputDescriptor::StaticPaymentOutput for more details on how to spend this.
1641+
*/
1642+
typedef struct MUST_USE_STRUCT LDKStaticPaymentOutputDescriptor {
1643+
/**
1644+
* Nearly everywhere, inner must be non-null, however in places where
1645+
* the Rust equivalent takes an Option, it may be set to null to indicate None.
1646+
*/
1647+
LDKnativeStaticPaymentOutputDescriptor *inner;
1648+
bool is_owned;
1649+
} LDKStaticPaymentOutputDescriptor;
1650+
15891651
/**
15901652
* When on-chain outputs are created by rust-lightning (which our counterparty is not able to
15911653
* claim at any point in the future) an event is generated which you must track and be able to
15921654
* spend on-chain. The information needed to do this is provided in this enum, including the
15931655
* outpoint describing which txid and output index is available, the full output which exists at
15941656
* that txid/index, and any keys or other information required to sign.
15951657
*/
1596-
typedef struct MUST_USE_STRUCT LDKSpendableOutputDescriptor {
1658+
typedef enum LDKSpendableOutputDescriptor_Tag {
15971659
/**
1598-
* Nearly everywhere, inner must be non-null, however in places where
1599-
* the Rust equivalent takes an Option, it may be set to null to indicate None.
1660+
* An output to a script which was provided via KeysInterface directly, either from
1661+
* `get_destination_script()` or `get_shutdown_pubkey()`, thus you should already know how to
1662+
* spend it. No secret keys are provided as rust-lightning was never given any key.
1663+
* These may include outputs from a transaction punishing our counterparty or claiming an HTLC
1664+
* on-chain using the payment preimage or after it has timed out.
16001665
*/
1601-
LDKnativeSpendableOutputDescriptor *inner;
1602-
bool is_owned;
1666+
LDKSpendableOutputDescriptor_StaticOutput,
1667+
/**
1668+
* An output to a P2WSH script which can be spent with a single signature after a CSV delay.
1669+
*
1670+
* The witness in the spending input should be:
1671+
* <BIP 143 signature> <empty vector> (MINIMALIF standard rule) <provided witnessScript>
1672+
*
1673+
* Note that the nSequence field in the spending input must be set to to_self_delay
1674+
* (which means the transaction is not broadcastable until at least to_self_delay
1675+
* blocks after the outpoint confirms).
1676+
*
1677+
* These are generally the result of a \"revocable\" output to us, spendable only by us unless
1678+
* it is an output from an old state which we broadcast (which should never happen).
1679+
*
1680+
* To derive the delayed_payment key which is used to sign for this input, you must pass the
1681+
* holder delayed_payment_base_key (ie the private key which corresponds to the pubkey in
1682+
* ChannelKeys::pubkeys().delayed_payment_basepoint) and the provided per_commitment_point to
1683+
* chan_utils::derive_private_key. The public key can be generated without the secret key
1684+
* using chan_utils::derive_public_key and only the delayed_payment_basepoint which appears in
1685+
* ChannelKeys::pubkeys().
1686+
*
1687+
* To derive the revocation_pubkey provided here (which is used in the witness
1688+
* script generation), you must pass the counterparty revocation_basepoint (which appears in the
1689+
* call to ChannelKeys::ready_channel) and the provided per_commitment point
1690+
* to chan_utils::derive_public_revocation_key.
1691+
*
1692+
* The witness script which is hashed and included in the output script_pubkey may be
1693+
* regenerated by passing the revocation_pubkey (derived as above), our delayed_payment pubkey
1694+
* (derived as above), and the to_self_delay contained here to
1695+
* chan_utils::get_revokeable_redeemscript.
1696+
*/
1697+
LDKSpendableOutputDescriptor_DelayedPaymentOutput,
1698+
/**
1699+
* An output to a P2WPKH, spendable exclusively by our payment key (ie the private key which
1700+
* corresponds to the public key in ChannelKeys::pubkeys().payment_point).
1701+
* The witness in the spending input, is, thus, simply:
1702+
* <BIP 143 signature> <payment key>
1703+
*
1704+
* These are generally the result of our counterparty having broadcast the current state,
1705+
* allowing us to claim the non-HTLC-encumbered outputs immediately.
1706+
*/
1707+
LDKSpendableOutputDescriptor_StaticPaymentOutput,
1708+
/**
1709+
* Must be last for serialization purposes
1710+
*/
1711+
LDKSpendableOutputDescriptor_Sentinel,
1712+
} LDKSpendableOutputDescriptor_Tag;
1713+
1714+
typedef struct LDKSpendableOutputDescriptor_LDKStaticOutput_Body {
1715+
struct LDKOutPoint outpoint;
1716+
struct LDKTxOut output;
1717+
} LDKSpendableOutputDescriptor_LDKStaticOutput_Body;
1718+
1719+
typedef struct MUST_USE_STRUCT LDKSpendableOutputDescriptor {
1720+
LDKSpendableOutputDescriptor_Tag tag;
1721+
union {
1722+
LDKSpendableOutputDescriptor_LDKStaticOutput_Body static_output;
1723+
struct {
1724+
struct LDKDelayedPaymentOutputDescriptor delayed_payment_output;
1725+
};
1726+
struct {
1727+
struct LDKStaticPaymentOutputDescriptor static_payment_output;
1728+
};
1729+
};
16031730
} LDKSpendableOutputDescriptor;
16041731

16051732
typedef struct LDKCVec_SpendableOutputDescriptorZ {
@@ -1762,24 +1889,6 @@ typedef struct LDKCResult_ChannelMonitorUpdateDecodeErrorZ {
17621889
bool result_ok;
17631890
} LDKCResult_ChannelMonitorUpdateDecodeErrorZ;
17641891

1765-
1766-
1767-
/**
1768-
* Simple structure sent back by `chain::Watch` when an HTLC from a forward channel is detected on
1769-
* chain. Used to update the corresponding HTLC in the backward channel. Failing to pass the
1770-
* preimage claim backward will lead to loss of funds.
1771-
*
1772-
* [`chain::Watch`]: ../trait.Watch.html
1773-
*/
1774-
typedef struct MUST_USE_STRUCT LDKHTLCUpdate {
1775-
/**
1776-
* Nearly everywhere, inner must be non-null, however in places where
1777-
* the Rust equivalent takes an Option, it may be set to null to indicate None.
1778-
*/
1779-
LDKnativeHTLCUpdate *inner;
1780-
bool is_owned;
1781-
} LDKHTLCUpdate;
1782-
17831892
typedef union LDKCResult_HTLCUpdateDecodeErrorZPtr {
17841893
struct LDKHTLCUpdate *result;
17851894
struct LDKDecodeError *err;
@@ -2186,6 +2295,16 @@ typedef struct LDKCResult_NoneAPIErrorZ {
21862295
bool result_ok;
21872296
} LDKCResult_NoneAPIErrorZ;
21882297

2298+
typedef struct LDKCVec_CResult_NoneAPIErrorZZ {
2299+
struct LDKCResult_NoneAPIErrorZ *data;
2300+
uintptr_t datalen;
2301+
} LDKCVec_CResult_NoneAPIErrorZZ;
2302+
2303+
typedef struct LDKCVec_APIErrorZ {
2304+
struct LDKAPIError *data;
2305+
uintptr_t datalen;
2306+
} LDKCVec_APIErrorZ;
2307+
21892308

21902309

21912310
/**
@@ -2205,20 +2324,71 @@ typedef struct LDKCVec_ChannelDetailsZ {
22052324
uintptr_t datalen;
22062325
} LDKCVec_ChannelDetailsZ;
22072326

2208-
2209-
22102327
/**
22112328
* If a payment fails to send, it can be in one of several states. This enum is returned as the
22122329
* Err() type describing which state the payment is in, see the description of individual enum
22132330
* states for more.
22142331
*/
2215-
typedef struct MUST_USE_STRUCT LDKPaymentSendFailure {
2332+
typedef enum LDKPaymentSendFailure_Tag {
22162333
/**
2217-
* Nearly everywhere, inner must be non-null, however in places where
2218-
* the Rust equivalent takes an Option, it may be set to null to indicate None.
2334+
* A parameter which was passed to send_payment was invalid, preventing us from attempting to
2335+
* send the payment at all. No channel state has been changed or messages sent to peers, and
2336+
* once you've changed the parameter at error, you can freely retry the payment in full.
22192337
*/
2220-
LDKnativePaymentSendFailure *inner;
2221-
bool is_owned;
2338+
LDKPaymentSendFailure_ParameterError,
2339+
/**
2340+
* A parameter in a single path which was passed to send_payment was invalid, preventing us
2341+
* from attempting to send the payment at all. No channel state has been changed or messages
2342+
* sent to peers, and once you've changed the parameter at error, you can freely retry the
2343+
* payment in full.
2344+
*
2345+
* The results here are ordered the same as the paths in the route object which was passed to
2346+
* send_payment.
2347+
*/
2348+
LDKPaymentSendFailure_PathParameterError,
2349+
/**
2350+
* All paths which were attempted failed to send, with no channel state change taking place.
2351+
* You can freely retry the payment in full (though you probably want to do so over different
2352+
* paths than the ones selected).
2353+
*/
2354+
LDKPaymentSendFailure_AllFailedRetrySafe,
2355+
/**
2356+
* Some paths which were attempted failed to send, though possibly not all. At least some
2357+
* paths have irrevocably committed to the HTLC and retrying the payment in full would result
2358+
* in over-/re-payment.
2359+
*
2360+
* The results here are ordered the same as the paths in the route object which was passed to
2361+
* send_payment, and any Errs which are not APIError::MonitorUpdateFailed can be safely
2362+
* retried (though there is currently no API with which to do so).
2363+
*
2364+
* Any entries which contain Err(APIError::MonitorUpdateFailed) or Ok(()) MUST NOT be retried
2365+
* as they will result in over-/re-payment. These HTLCs all either successfully sent (in the
2366+
* case of Ok(())) or will send once channel_monitor_updated is called on the next-hop channel
2367+
* with the latest update_id.
2368+
*/
2369+
LDKPaymentSendFailure_PartialFailure,
2370+
/**
2371+
* Must be last for serialization purposes
2372+
*/
2373+
LDKPaymentSendFailure_Sentinel,
2374+
} LDKPaymentSendFailure_Tag;
2375+
2376+
typedef struct MUST_USE_STRUCT LDKPaymentSendFailure {
2377+
LDKPaymentSendFailure_Tag tag;
2378+
union {
2379+
struct {
2380+
struct LDKAPIError parameter_error;
2381+
};
2382+
struct {
2383+
struct LDKCVec_CResult_NoneAPIErrorZZ path_parameter_error;
2384+
};
2385+
struct {
2386+
struct LDKCVec_APIErrorZ all_failed_retry_safe;
2387+
};
2388+
struct {
2389+
struct LDKCVec_CResult_NoneAPIErrorZZ partial_failure;
2390+
};
2391+
};
22222392
} LDKPaymentSendFailure;
22232393

22242394
typedef union LDKCResult_NonePaymentSendFailureZPtr {
@@ -3406,36 +3576,6 @@ typedef struct MUST_USE_STRUCT LDKChainMonitor {
34063576

34073577

34083578

3409-
/**
3410-
* Information about a spendable output to a P2WSH script. See
3411-
* SpendableOutputDescriptor::DelayedPaymentOutput for more details on how to spend this.
3412-
*/
3413-
typedef struct MUST_USE_STRUCT LDKDelayedPaymentOutputDescriptor {
3414-
/**
3415-
* Nearly everywhere, inner must be non-null, however in places where
3416-
* the Rust equivalent takes an Option, it may be set to null to indicate None.
3417-
*/
3418-
LDKnativeDelayedPaymentOutputDescriptor *inner;
3419-
bool is_owned;
3420-
} LDKDelayedPaymentOutputDescriptor;
3421-
3422-
3423-
3424-
/**
3425-
* Information about a spendable output to our \"payment key\". See
3426-
* SpendableOutputDescriptor::StaticPaymentOutput for more details on how to spend this.
3427-
*/
3428-
typedef struct MUST_USE_STRUCT LDKStaticPaymentOutputDescriptor {
3429-
/**
3430-
* Nearly everywhere, inner must be non-null, however in places where
3431-
* the Rust equivalent takes an Option, it may be set to null to indicate None.
3432-
*/
3433-
LDKnativeStaticPaymentOutputDescriptor *inner;
3434-
bool is_owned;
3435-
} LDKStaticPaymentOutputDescriptor;
3436-
3437-
3438-
34393579
/**
34403580
* Simple KeysInterface implementor that takes a 32-byte seed for use as a BIP 32 extended key
34413581
* and derives keys from that.
@@ -4144,6 +4284,10 @@ void CResult_NoneAPIErrorZ_free(struct LDKCResult_NoneAPIErrorZ _res);
41444284

41454285
struct LDKCResult_NoneAPIErrorZ CResult_NoneAPIErrorZ_clone(const struct LDKCResult_NoneAPIErrorZ *NONNULL_PTR orig);
41464286

4287+
void CVec_CResult_NoneAPIErrorZZ_free(struct LDKCVec_CResult_NoneAPIErrorZZ _res);
4288+
4289+
void CVec_APIErrorZ_free(struct LDKCVec_APIErrorZ _res);
4290+
41474291
void CVec_ChannelDetailsZ_free(struct LDKCVec_ChannelDetailsZ _res);
41484292

41494293
struct LDKCResult_NonePaymentSendFailureZ CResult_NonePaymentSendFailureZ_ok(void);

lightning-c-bindings/include/lightningpp.hpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,6 +2321,21 @@ class CResult_HolderCommitmentTransactionDecodeErrorZ {
23212321
const LDKCResult_HolderCommitmentTransactionDecodeErrorZ* operator &() const { return &self; }
23222322
const LDKCResult_HolderCommitmentTransactionDecodeErrorZ* operator ->() const { return &self; }
23232323
};
2324+
class CVec_CResult_NoneAPIErrorZZ {
2325+
private:
2326+
LDKCVec_CResult_NoneAPIErrorZZ self;
2327+
public:
2328+
CVec_CResult_NoneAPIErrorZZ(const CVec_CResult_NoneAPIErrorZZ&) = delete;
2329+
CVec_CResult_NoneAPIErrorZZ(CVec_CResult_NoneAPIErrorZZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_CResult_NoneAPIErrorZZ)); }
2330+
CVec_CResult_NoneAPIErrorZZ(LDKCVec_CResult_NoneAPIErrorZZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_CResult_NoneAPIErrorZZ)); }
2331+
operator LDKCVec_CResult_NoneAPIErrorZZ() && { LDKCVec_CResult_NoneAPIErrorZZ res = self; memset(&self, 0, sizeof(LDKCVec_CResult_NoneAPIErrorZZ)); return res; }
2332+
~CVec_CResult_NoneAPIErrorZZ() { CVec_CResult_NoneAPIErrorZZ_free(self); }
2333+
CVec_CResult_NoneAPIErrorZZ& operator=(CVec_CResult_NoneAPIErrorZZ&& o) { CVec_CResult_NoneAPIErrorZZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_CResult_NoneAPIErrorZZ)); return *this; }
2334+
LDKCVec_CResult_NoneAPIErrorZZ* operator &() { return &self; }
2335+
LDKCVec_CResult_NoneAPIErrorZZ* operator ->() { return &self; }
2336+
const LDKCVec_CResult_NoneAPIErrorZZ* operator &() const { return &self; }
2337+
const LDKCVec_CResult_NoneAPIErrorZZ* operator ->() const { return &self; }
2338+
};
23242339
class CResult_SignatureNoneZ {
23252340
private:
23262341
LDKCResult_SignatureNoneZ self;
@@ -3101,6 +3116,21 @@ class CResult_ChannelUpdateDecodeErrorZ {
31013116
const LDKCResult_ChannelUpdateDecodeErrorZ* operator &() const { return &self; }
31023117
const LDKCResult_ChannelUpdateDecodeErrorZ* operator ->() const { return &self; }
31033118
};
3119+
class CVec_APIErrorZ {
3120+
private:
3121+
LDKCVec_APIErrorZ self;
3122+
public:
3123+
CVec_APIErrorZ(const CVec_APIErrorZ&) = delete;
3124+
CVec_APIErrorZ(CVec_APIErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_APIErrorZ)); }
3125+
CVec_APIErrorZ(LDKCVec_APIErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_APIErrorZ)); }
3126+
operator LDKCVec_APIErrorZ() && { LDKCVec_APIErrorZ res = self; memset(&self, 0, sizeof(LDKCVec_APIErrorZ)); return res; }
3127+
~CVec_APIErrorZ() { CVec_APIErrorZ_free(self); }
3128+
CVec_APIErrorZ& operator=(CVec_APIErrorZ&& o) { CVec_APIErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_APIErrorZ)); return *this; }
3129+
LDKCVec_APIErrorZ* operator &() { return &self; }
3130+
LDKCVec_APIErrorZ* operator ->() { return &self; }
3131+
const LDKCVec_APIErrorZ* operator &() const { return &self; }
3132+
const LDKCVec_APIErrorZ* operator ->() const { return &self; }
3133+
};
31043134
class CVec_UpdateFulfillHTLCZ {
31053135
private:
31063136
LDKCVec_UpdateFulfillHTLCZ self;

0 commit comments

Comments
 (0)