Skip to content

Commit fee27c4

Browse files
authored
Merge pull request lightningdevkit#46 from TheBlueMatt/main
0.0.102 Bindings Updates
2 parents fea3e0c + 5eec18a commit fee27c4

File tree

18 files changed

+3078
-1000
lines changed

18 files changed

+3078
-1000
lines changed

c-bindings-gen/src/types.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -867,10 +867,6 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
867867
return Some(full_path);
868868
}
869869
match full_path {
870-
"Result" => Some("crate::c_types::derived::CResult"),
871-
"Vec" if !is_ref => Some("crate::c_types::derived::CVec"),
872-
"Option" => Some(""),
873-
874870
// Note that no !is_ref types can map to an array because Rust and C's call semantics
875871
// for arrays are different (https://github.com/eqrion/cbindgen/issues/528)
876872

@@ -906,7 +902,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
906902
"bitcoin::blockdata::script::Script" if is_ref => Some("crate::c_types::u8slice"),
907903
"bitcoin::blockdata::script::Script" if !is_ref => Some("crate::c_types::derived::CVec_u8Z"),
908904
"bitcoin::blockdata::transaction::OutPoint" => Some("crate::lightning::chain::transaction::OutPoint"),
909-
"bitcoin::blockdata::transaction::Transaction" => Some("crate::c_types::Transaction"),
905+
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" => Some("crate::c_types::Transaction"),
910906
"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some("crate::c_types::TxOut"),
911907
"bitcoin::network::constants::Network" => Some("crate::bitcoin::network::Network"),
912908
"bitcoin::blockdata::block::BlockHeader" if is_ref => Some("*const [u8; 80]"),
@@ -989,8 +985,8 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
989985
if !is_ref => Some(""),
990986
"bitcoin::blockdata::script::Script" if is_ref => Some("&::bitcoin::blockdata::script::Script::from(Vec::from("),
991987
"bitcoin::blockdata::script::Script" if !is_ref => Some("::bitcoin::blockdata::script::Script::from("),
992-
"bitcoin::blockdata::transaction::Transaction" if is_ref => Some("&"),
993-
"bitcoin::blockdata::transaction::Transaction" => Some(""),
988+
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" if is_ref => Some("&"),
989+
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" => Some(""),
994990
"bitcoin::blockdata::transaction::OutPoint" => Some("crate::c_types::C_to_bitcoin_outpoint("),
995991
"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some(""),
996992
"bitcoin::network::constants::Network" => Some(""),
@@ -1066,7 +1062,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
10661062
if is_ref => Some("}[..]).unwrap()"),
10671063
"bitcoin::blockdata::script::Script" if is_ref => Some(".to_slice()))"),
10681064
"bitcoin::blockdata::script::Script" if !is_ref => Some(".into_rust())"),
1069-
"bitcoin::blockdata::transaction::Transaction" => Some(".into_bitcoin()"),
1065+
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" => Some(".into_bitcoin()"),
10701066
"bitcoin::blockdata::transaction::OutPoint" => Some(")"),
10711067
"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some(".into_rust()"),
10721068
"bitcoin::network::constants::Network" => Some(".into_bitcoin()"),
@@ -1157,8 +1153,8 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
11571153
if !is_ref => Some("crate::c_types::Secp256k1Error::from_rust("),
11581154
"bitcoin::blockdata::script::Script" if is_ref => Some("crate::c_types::u8slice::from_slice(&"),
11591155
"bitcoin::blockdata::script::Script" if !is_ref => Some(""),
1160-
"bitcoin::blockdata::transaction::Transaction" if is_ref => Some("crate::c_types::Transaction::from_bitcoin("),
1161-
"bitcoin::blockdata::transaction::Transaction" => Some("crate::c_types::Transaction::from_bitcoin(&"),
1156+
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" if is_ref => Some("crate::c_types::Transaction::from_bitcoin("),
1157+
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" => Some("crate::c_types::Transaction::from_bitcoin(&"),
11621158
"bitcoin::blockdata::transaction::OutPoint" => Some("crate::c_types::bitcoin_to_C_outpoint("),
11631159
"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some("crate::c_types::TxOut::from_rust("),
11641160
"bitcoin::network::constants::Network" => Some("crate::bitcoin::network::Network::from_bitcoin("),
@@ -1231,7 +1227,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
12311227
if !is_ref => Some(")"),
12321228
"bitcoin::blockdata::script::Script" if is_ref => Some("[..])"),
12331229
"bitcoin::blockdata::script::Script" if !is_ref => Some(".into_bytes().into()"),
1234-
"bitcoin::blockdata::transaction::Transaction" => Some(")"),
1230+
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" => Some(")"),
12351231
"bitcoin::blockdata::transaction::OutPoint" => Some(")"),
12361232
"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some(")"),
12371233
"bitcoin::network::constants::Network" => Some(")"),
@@ -1378,10 +1374,10 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
13781374
], " }", ContainerPrefixLocation::OutsideConv));
13791375
}
13801376
} else if self.is_primitive(&inner_path) || self.c_type_from_path(&inner_path, false, false).is_none() {
1381-
let inner_name = inner_path.rsplit("::").next().unwrap();
1377+
let inner_name = self.get_c_mangled_container_type(vec![single_contained.unwrap()], generics, "Option").unwrap();
13821378
return Some(("if ", vec![
1383-
(format!(".is_none() {{ {}::COption_{}Z::None }} else {{ {}::COption_{}Z::Some(",
1384-
Self::generated_container_path(), inner_name, Self::generated_container_path(), inner_name),
1379+
(format!(".is_none() {{ {}::None }} else {{ {}::Some(",
1380+
inner_name, inner_name),
13851381
format!("{}.unwrap()", var_access))
13861382
], ") }", ContainerPrefixLocation::PerConv));
13871383
} else {

ldk-net/ldk_net.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,9 @@ static uintptr_t sock_send_data(void* desc, struct LDKu8slice data, bool resume_
111111
for (int i = 0; i < descriptor->handler->sockcount; i++) {
112112
if (descriptor->handler->pollfds[i].fd == descriptor->fd) {
113113
if (pause_read) {
114-
descriptor->handler->pollfds[i].events &= POLLIN;
115-
descriptor->handler->pollfds[i].events |= POLLOUT;
114+
descriptor->handler->pollfds[i].events = POLLOUT;
116115
} else {
117-
descriptor->handler->pollfds[i].events |= POLLIN;
116+
descriptor->handler->pollfds[i].events = POLLIN;
118117
}
119118
break;
120119
}
@@ -243,8 +242,7 @@ static void *sock_thread_fn(void* arg) {
243242
lockres = pthread_mutex_lock(&handler->sockets_mutex);
244243
assert(lockres == 0);
245244
assert(handler->pollfds[i - 1].fd == pollfds[i].fd); // Only we change fd order!
246-
handler->pollfds[i - 1].events &= POLLIN;
247-
handler->pollfds[i - 1].events |= POLLOUT;
245+
handler->pollfds[i - 1].events = POLLOUT;
248246
lockres = pthread_mutex_unlock(&handler->sockets_mutex);
249247
assert(lockres == 0);
250248
}

lightning-c-bindings/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ crate-type = ["staticlib"
1818
bitcoin = "0.27"
1919
secp256k1 = { version = "0.20.3", features = ["global-context-less-secure"] }
2020
# Note that the following line is matched by genbindings to update the path
21-
lightning = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "ad819ea70572b4775691e3fc386a788ff9438975", features = ["allow_wallclock_use"] }
22-
lightning-persister = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "ad819ea70572b4775691e3fc386a788ff9438975" }
23-
lightning-invoice = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "ad819ea70572b4775691e3fc386a788ff9438975" }
24-
lightning-background-processor = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "ad819ea70572b4775691e3fc386a788ff9438975" }
21+
lightning = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "001bc7113a92a586e7e7ac4557bbae7a1a402550", features = ["allow_wallclock_use"] }
22+
lightning-persister = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "001bc7113a92a586e7e7ac4557bbae7a1a402550" }
23+
lightning-invoice = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "001bc7113a92a586e7e7ac4557bbae7a1a402550" }
24+
lightning-background-processor = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "001bc7113a92a586e7e7ac4557bbae7a1a402550" }
2525

2626
# Always force panic=abort, further options are set in the genbindings.sh build script
2727
[profile.dev]

lightning-c-bindings/demo.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@ LDKCVec_C2Tuple_PublicKeyTypeZZ create_custom_msg(const void* this_arg) {
419419
return ret;
420420
}
421421

422+
uint64_t get_chan_score(const void *this_arg, uint64_t scid) { return 42; }
423+
422424
int main() {
423425
uint8_t channel_open_header[80];
424426
uint8_t header_1[80];
@@ -546,7 +548,7 @@ int main() {
546548
PeersConnection conn(cm1, cm2, net1, net2);
547549

548550
// Note that we have to bind the result to a C++ class to make sure it gets free'd
549-
LDK::CResult_NoneAPIErrorZ res = ChannelManager_create_channel(&cm1, ChannelManager_get_our_node_id(&cm2), 40000, 1000, 42, UserConfig_default());
551+
LDK::CResult__u832APIErrorZ res = ChannelManager_create_channel(&cm1, ChannelManager_get_our_node_id(&cm2), 40000, 1000, 42, UserConfig_default());
550552
assert(res->result_ok);
551553
PeerManager_process_events(&net1);
552554

@@ -672,18 +674,21 @@ int main() {
672674
{
673675
LDK::CVec_ChannelDetailsZ outbound_channels = ChannelManager_list_usable_channels(&cm1);
674676
LDK::NetworkGraph graph_2_ref = NetGraphMsgHandler_get_network_graph(&net_graph2);
677+
LDK::Score chan_scorer = LDKScore {
678+
.this_arg = NULL, .channel_penalty_msat = get_chan_score, .free = NULL
679+
};
675680
LDK::CResult_RouteLightningErrorZ route = get_route(ChannelManager_get_our_node_id(&cm1), &graph_2_ref, ChannelManager_get_our_node_id(&cm2), LDKInvoiceFeatures {
676681
.inner = NULL, .is_owned = false
677682
}, &outbound_channels, Invoice_route_hints(invoice->contents.result),
678-
5000, Invoice_min_final_cltv_expiry(invoice->contents.result), logger1);
683+
5000, Invoice_min_final_cltv_expiry(invoice->contents.result), logger1, &chan_scorer);
679684
assert(route->result_ok);
680685
LDK::CVec_CVec_RouteHopZZ paths = Route_get_paths(route->contents.result);
681686
assert(paths->datalen == 1);
682687
assert(paths->data[0].datalen == 1);
683688
assert(!memcmp(RouteHop_get_pubkey(&paths->data[0].data[0]).compressed_form,
684689
ChannelManager_get_our_node_id(&cm2).compressed_form, 33));
685690
assert(RouteHop_get_short_channel_id(&paths->data[0].data[0]) == channel_scid);
686-
LDK::CResult_NonePaymentSendFailureZ send_res = ChannelManager_send_payment(&cm1, route->contents.result, payment_hash, Invoice_payment_secret(invoice->contents.result));
691+
LDK::CResult_PaymentIdPaymentSendFailureZ send_res = ChannelManager_send_payment(&cm1, route->contents.result, payment_hash, Invoice_payment_secret(invoice->contents.result));
687692
assert(send_res->result_ok);
688693
}
689694

lightning-c-bindings/include/ldk_rust_types.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ struct nativeChannelFeaturesOpaque;
6060
typedef struct nativeChannelFeaturesOpaque LDKnativeChannelFeatures;
6161
struct nativeInvoiceFeaturesOpaque;
6262
typedef struct nativeInvoiceFeaturesOpaque LDKnativeInvoiceFeatures;
63+
struct nativeScorerOpaque;
64+
typedef struct nativeScorerOpaque LDKnativeScorer;
6365
struct nativeDelayedPaymentOutputDescriptorOpaque;
6466
typedef struct nativeDelayedPaymentOutputDescriptorOpaque LDKnativeDelayedPaymentOutputDescriptor;
6567
struct nativeStaticPaymentOutputDescriptorOpaque;
@@ -71,6 +73,8 @@ struct nativeKeysManagerOpaque;
7173
typedef struct nativeKeysManagerOpaque LDKnativeKeysManager;
7274
struct nativeFilesystemPersisterOpaque;
7375
typedef struct nativeFilesystemPersisterOpaque LDKnativeFilesystemPersister;
76+
struct nativePaymentIdOpaque;
77+
typedef struct nativePaymentIdOpaque LDKnativePaymentId;
7478
struct nativeChannelManagerOpaque;
7579
typedef struct nativeChannelManagerOpaque LDKnativeChannelManager;
7680
struct nativeChainParametersOpaque;
@@ -135,6 +139,8 @@ struct nativePeerHandleErrorOpaque;
135139
typedef struct nativePeerHandleErrorOpaque LDKnativePeerHandleError;
136140
struct nativePeerManagerOpaque;
137141
typedef struct nativePeerManagerOpaque LDKnativePeerManager;
142+
struct nativeNodeIdOpaque;
143+
typedef struct nativeNodeIdOpaque LDKnativeNodeId;
138144
struct nativeNetworkGraphOpaque;
139145
typedef struct nativeNetworkGraphOpaque LDKnativeNetworkGraph;
140146
struct nativeReadOnlyNetworkGraphOpaque;
@@ -223,5 +229,7 @@ struct nativeLightningErrorOpaque;
223229
typedef struct nativeLightningErrorOpaque LDKnativeLightningError;
224230
struct nativeCommitmentUpdateOpaque;
225231
typedef struct nativeCommitmentUpdateOpaque LDKnativeCommitmentUpdate;
232+
struct nativeLockedChannelMonitorOpaque;
233+
typedef struct nativeLockedChannelMonitorOpaque LDKnativeLockedChannelMonitor;
226234
struct nativeChainMonitorOpaque;
227235
typedef struct nativeChainMonitorOpaque LDKnativeChainMonitor;

0 commit comments

Comments
 (0)