Skip to content

Commit ebe96ac

Browse files
committed
Add automatically generated C wrapper bindings
1 parent 7248fc9 commit ebe96ac

19 files changed

+3728
-0
lines changed

lightning-c-bindings/include/lightning.h

Lines changed: 1226 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
2+
struct lnEventOpaque;
3+
typedef struct lnEventOpaque LDKlnEvent;
4+
struct lnMessageSendEventOpaque;
5+
typedef struct lnMessageSendEventOpaque LDKlnMessageSendEvent;
6+
struct lnAPIErrorOpaque;
7+
typedef struct lnAPIErrorOpaque LDKlnAPIError;
8+
struct lnUserConfigOpaque;
9+
typedef struct lnUserConfigOpaque LDKlnUserConfig;
10+
struct lnChannelHandshakeConfigOpaque;
11+
typedef struct lnChannelHandshakeConfigOpaque LDKlnChannelHandshakeConfig;
12+
struct lnChannelHandshakeLimitsOpaque;
13+
typedef struct lnChannelHandshakeLimitsOpaque LDKlnChannelHandshakeLimits;
14+
struct lnChannelConfigOpaque;
15+
typedef struct lnChannelConfigOpaque LDKlnChannelConfig;
16+
struct lnOutPointOpaque;
17+
typedef struct lnOutPointOpaque LDKlnOutPoint;
18+
struct lnSpendableOutputDescriptorOpaque;
19+
typedef struct lnSpendableOutputDescriptorOpaque LDKlnSpendableOutputDescriptor;
20+
struct lnInMemoryChannelKeysOpaque;
21+
typedef struct lnInMemoryChannelKeysOpaque LDKlnInMemoryChannelKeys;
22+
struct lnKeysManagerOpaque;
23+
typedef struct lnKeysManagerOpaque LDKlnKeysManager;
24+
struct lnChannelManagerOpaque;
25+
typedef struct lnChannelManagerOpaque LDKlnChannelManager;
26+
struct lnChannelDetailsOpaque;
27+
typedef struct lnChannelDetailsOpaque LDKlnChannelDetails;
28+
struct lnPaymentSendFailureOpaque;
29+
typedef struct lnPaymentSendFailureOpaque LDKlnPaymentSendFailure;
30+
struct lnChannelMonitorUpdateOpaque;
31+
typedef struct lnChannelMonitorUpdateOpaque LDKlnChannelMonitorUpdate;
32+
struct lnMonitorUpdateErrorOpaque;
33+
typedef struct lnMonitorUpdateErrorOpaque LDKlnMonitorUpdateError;
34+
struct lnHTLCUpdateOpaque;
35+
typedef struct lnHTLCUpdateOpaque LDKlnHTLCUpdate;
36+
struct lnChannelMonitorOpaque;
37+
typedef struct lnChannelMonitorOpaque LDKlnChannelMonitor;
38+
struct lnDecodeErrorOpaque;
39+
typedef struct lnDecodeErrorOpaque LDKlnDecodeError;
40+
struct lnInitOpaque;
41+
typedef struct lnInitOpaque LDKlnInit;
42+
struct lnErrorMessageOpaque;
43+
typedef struct lnErrorMessageOpaque LDKlnErrorMessage;
44+
struct lnPingOpaque;
45+
typedef struct lnPingOpaque LDKlnPing;
46+
struct lnPongOpaque;
47+
typedef struct lnPongOpaque LDKlnPong;
48+
struct lnOpenChannelOpaque;
49+
typedef struct lnOpenChannelOpaque LDKlnOpenChannel;
50+
struct lnAcceptChannelOpaque;
51+
typedef struct lnAcceptChannelOpaque LDKlnAcceptChannel;
52+
struct lnFundingCreatedOpaque;
53+
typedef struct lnFundingCreatedOpaque LDKlnFundingCreated;
54+
struct lnFundingSignedOpaque;
55+
typedef struct lnFundingSignedOpaque LDKlnFundingSigned;
56+
struct lnFundingLockedOpaque;
57+
typedef struct lnFundingLockedOpaque LDKlnFundingLocked;
58+
struct lnShutdownOpaque;
59+
typedef struct lnShutdownOpaque LDKlnShutdown;
60+
struct lnClosingSignedOpaque;
61+
typedef struct lnClosingSignedOpaque LDKlnClosingSigned;
62+
struct lnUpdateAddHTLCOpaque;
63+
typedef struct lnUpdateAddHTLCOpaque LDKlnUpdateAddHTLC;
64+
struct lnUpdateFulfillHTLCOpaque;
65+
typedef struct lnUpdateFulfillHTLCOpaque LDKlnUpdateFulfillHTLC;
66+
struct lnUpdateFailHTLCOpaque;
67+
typedef struct lnUpdateFailHTLCOpaque LDKlnUpdateFailHTLC;
68+
struct lnUpdateFailMalformedHTLCOpaque;
69+
typedef struct lnUpdateFailMalformedHTLCOpaque LDKlnUpdateFailMalformedHTLC;
70+
struct lnCommitmentSignedOpaque;
71+
typedef struct lnCommitmentSignedOpaque LDKlnCommitmentSigned;
72+
struct lnRevokeAndACKOpaque;
73+
typedef struct lnRevokeAndACKOpaque LDKlnRevokeAndACK;
74+
struct lnUpdateFeeOpaque;
75+
typedef struct lnUpdateFeeOpaque LDKlnUpdateFee;
76+
struct lnChannelReestablishOpaque;
77+
typedef struct lnChannelReestablishOpaque LDKlnChannelReestablish;
78+
struct lnAnnouncementSignaturesOpaque;
79+
typedef struct lnAnnouncementSignaturesOpaque LDKlnAnnouncementSignatures;
80+
struct lnNetAddressOpaque;
81+
typedef struct lnNetAddressOpaque LDKlnNetAddress;
82+
struct lnUnsignedNodeAnnouncementOpaque;
83+
typedef struct lnUnsignedNodeAnnouncementOpaque LDKlnUnsignedNodeAnnouncement;
84+
struct lnNodeAnnouncementOpaque;
85+
typedef struct lnNodeAnnouncementOpaque LDKlnNodeAnnouncement;
86+
struct lnUnsignedChannelAnnouncementOpaque;
87+
typedef struct lnUnsignedChannelAnnouncementOpaque LDKlnUnsignedChannelAnnouncement;
88+
struct lnChannelAnnouncementOpaque;
89+
typedef struct lnChannelAnnouncementOpaque LDKlnChannelAnnouncement;
90+
struct lnChannelUpdateOpaque;
91+
typedef struct lnChannelUpdateOpaque LDKlnChannelUpdate;
92+
struct lnLightningErrorOpaque;
93+
typedef struct lnLightningErrorOpaque LDKlnLightningError;
94+
struct lnCommitmentUpdateOpaque;
95+
typedef struct lnCommitmentUpdateOpaque LDKlnCommitmentUpdate;
96+
struct lnHTLCFailChannelUpdateOpaque;
97+
typedef struct lnHTLCFailChannelUpdateOpaque LDKlnHTLCFailChannelUpdate;
98+
struct lnMessageHandlerOpaque;
99+
typedef struct lnMessageHandlerOpaque LDKlnMessageHandler;
100+
struct lnPeerHandleErrorOpaque;
101+
typedef struct lnPeerHandleErrorOpaque LDKlnPeerHandleError;
102+
struct lnPeerManagerOpaque;
103+
typedef struct lnPeerManagerOpaque LDKlnPeerManager;
104+
struct lnTxCreationKeysOpaque;
105+
typedef struct lnTxCreationKeysOpaque LDKlnTxCreationKeys;
106+
struct lnChannelPublicKeysOpaque;
107+
typedef struct lnChannelPublicKeysOpaque LDKlnChannelPublicKeys;
108+
struct lnHTLCOutputInCommitmentOpaque;
109+
typedef struct lnHTLCOutputInCommitmentOpaque LDKlnHTLCOutputInCommitment;
110+
struct lnInitFeaturesOpaque;
111+
typedef struct lnInitFeaturesOpaque LDKlnInitFeatures;
112+
struct lnNodeFeaturesOpaque;
113+
typedef struct lnNodeFeaturesOpaque LDKlnNodeFeatures;
114+
struct lnChannelFeaturesOpaque;
115+
typedef struct lnChannelFeaturesOpaque LDKlnChannelFeatures;
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
//! " Traits and utility impls which allow other parts of rust-lightning to interact with the"
2+
//! " blockchain."
3+
//! ""
4+
//! " Includes traits for monitoring and receiving notifications of new blocks and block"
5+
//! " disconnections, transaction broadcasting, and feerate information requests."
6+
7+
use std::ffi::c_void;
8+
use bitcoin::hashes::Hash;
9+
10+
use bitcoin::blockdata::block::Block as lnBlock;
11+
use bitcoin::blockdata::block::BlockHeader as lnBlockHeader;
12+
use bitcoin::blockdata::transaction::Transaction as lnTransaction;
13+
use bitcoin::blockdata::script::Script as lnScript;
14+
use bitcoin::blockdata::constants::genesis_block as lngenesis_block;
15+
use bitcoin::util::hash::BitcoinHash as lnBitcoinHash;
16+
use bitcoin::network::constants::Network as lnNetwork;
17+
use bitcoin::hash_types::Txid as lnTxid;
18+
use bitcoin::hash_types::BlockHash as lnBlockHash;
19+
/// " Used to give chain error details upstream"
20+
#[repr(C)]
21+
pub enum ChainError {
22+
/// " Client doesn't support UTXO lookup (but the chain hash matches our genesis block hash)"
23+
NotSupported,
24+
/// " Chain isn't the one watched"
25+
NotWatched,
26+
/// " Tx doesn't exist or is unconfirmed"
27+
UnknownTx,
28+
}
29+
use lightning::chain::chaininterface::ChainError as lnChainError;
30+
impl ChainError {
31+
#[allow(unused)]
32+
pub(crate) fn to_ln(&self) -> lnChainError {
33+
match self {
34+
ChainError::NotSupported => lnChainError::NotSupported,
35+
ChainError::NotWatched => lnChainError::NotWatched,
36+
ChainError::UnknownTx => lnChainError::UnknownTx,
37+
}
38+
}
39+
#[allow(unused)]
40+
pub(crate) fn from_ln(lnt: lnChainError) -> Self {
41+
match lnt {
42+
lnChainError::NotSupported => ChainError::NotSupported,
43+
lnChainError::NotWatched => ChainError::NotWatched,
44+
lnChainError::UnknownTx => ChainError::UnknownTx,
45+
}
46+
}
47+
}
48+
/// " An interface to send a transaction to the Bitcoin network."
49+
#[repr(C)]
50+
pub struct BroadcasterInterface {
51+
pub this_arg: *mut c_void,
52+
/// " Sends a transaction out to (hopefully) be mined."
53+
pub broadcast_transaction: extern "C" fn (this_arg: *const c_void, tx: crate::c_types::Transaction),
54+
}
55+
unsafe impl Sync for BroadcasterInterface {}
56+
unsafe impl Send for BroadcasterInterface {}
57+
58+
use lightning::chain::chaininterface::BroadcasterInterface as lnBroadcasterInterface;
59+
impl lnBroadcasterInterface for BroadcasterInterface {
60+
fn broadcast_transaction(&self, tx: &bitcoin::blockdata::transaction::Transaction) {
61+
let c_tx = ::bitcoin::consensus::encode::serialize(tx);
62+
(self.broadcast_transaction)(self.this_arg, crate::c_types::Transaction::from_slice(&c_tx))
63+
}
64+
}
65+
66+
// We're essentially a pointer already, or at least a set of pointers, so allow us to be used
67+
// directly as a Deref trait in higher-level structs:
68+
impl std::ops::Deref for BroadcasterInterface {
69+
type Target = Self;
70+
fn deref(&self) -> &Self {
71+
self
72+
}
73+
}
74+
/// " An enum that represents the speed at which we want a transaction to confirm used for feerate"
75+
/// " estimation."
76+
#[repr(C)]
77+
pub enum ConfirmationTarget {
78+
/// " We are happy with this transaction confirming slowly when feerate drops some."
79+
Background,
80+
/// " We'd like this transaction to confirm without major delay, but 12-18 blocks is fine."
81+
Normal,
82+
/// " We'd like this transaction to confirm in the next few blocks."
83+
HighPriority,
84+
}
85+
use lightning::chain::chaininterface::ConfirmationTarget as lnConfirmationTarget;
86+
impl ConfirmationTarget {
87+
#[allow(unused)]
88+
pub(crate) fn to_ln(&self) -> lnConfirmationTarget {
89+
match self {
90+
ConfirmationTarget::Background => lnConfirmationTarget::Background,
91+
ConfirmationTarget::Normal => lnConfirmationTarget::Normal,
92+
ConfirmationTarget::HighPriority => lnConfirmationTarget::HighPriority,
93+
}
94+
}
95+
#[allow(unused)]
96+
pub(crate) fn from_ln(lnt: lnConfirmationTarget) -> Self {
97+
match lnt {
98+
lnConfirmationTarget::Background => ConfirmationTarget::Background,
99+
lnConfirmationTarget::Normal => ConfirmationTarget::Normal,
100+
lnConfirmationTarget::HighPriority => ConfirmationTarget::HighPriority,
101+
}
102+
}
103+
}
104+
/// " A trait which should be implemented to provide feerate information on a number of time"
105+
/// " horizons."
106+
/// ""
107+
/// " Note that all of the functions implemented here *must* be reentrant-safe (obviously - they're"
108+
/// " called from inside the library in response to ChainListener events, P2P events, or timer"
109+
/// " events)."
110+
#[repr(C)]
111+
pub struct FeeEstimator {
112+
pub this_arg: *mut c_void,
113+
/// " Gets estimated satoshis of fee required per 1000 Weight-Units."
114+
/// ""
115+
/// " Must be no smaller than 253 (ie 1 satoshi-per-byte rounded up to ensure later round-downs"
116+
/// " don't put us below 1 satoshi-per-byte)."
117+
/// ""
118+
/// " This translates to:"
119+
/// " * satoshis-per-byte * 250"
120+
/// " * ceil(satoshis-per-kbyte / 4)"
121+
pub get_est_sat_per_1000_weight: extern "C" fn (this_arg: *const c_void, confirmation_target: ConfirmationTarget) -> u64,
122+
}
123+
unsafe impl Sync for FeeEstimator {}
124+
unsafe impl Send for FeeEstimator {}
125+
126+
use lightning::chain::chaininterface::FeeEstimator as lnFeeEstimator;
127+
impl lnFeeEstimator for FeeEstimator {
128+
fn get_est_sat_per_1000_weight(&self, confirmation_target: lightning::chain::chaininterface::ConfirmationTarget) -> u64 {
129+
(self.get_est_sat_per_1000_weight)(self.this_arg, ConfirmationTarget::from_ln(confirmation_target))
130+
}
131+
}
132+
133+
// We're essentially a pointer already, or at least a set of pointers, so allow us to be used
134+
// directly as a Deref trait in higher-level structs:
135+
impl std::ops::Deref for FeeEstimator {
136+
type Target = Self;
137+
fn deref(&self) -> &Self {
138+
self
139+
}
140+
}

0 commit comments

Comments
 (0)