Skip to content

Commit a7a9b1c

Browse files
committed
Update C/C++ demo to LDK 0.0.118 API
1 parent 5502fcc commit a7a9b1c

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

lightning-c-bindings/demo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void print_log(const void *this_arg, const LDKRecord *record) {
1313
}
1414

1515
uint32_t get_fee(const void *this_arg, LDKConfirmationTarget target) {
16-
if (target == LDKConfirmationTarget_Background) {
16+
if (target == LDKConfirmationTarget_AnchorChannelFee || target == LDKConfirmationTarget_MinAllowedAnchorChannelRemoteFee) {
1717
return 253;
1818
} else {
1919
return 507;

lightning-c-bindings/demo.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void print_log(const void *this_arg, const LDKRecord *record) {
104104
}
105105

106106
uint32_t get_fee(const void *this_arg, LDKConfirmationTarget target) {
107-
if (target == LDKConfirmationTarget_Background) {
107+
if (target == LDKConfirmationTarget_AnchorChannelFee || target == LDKConfirmationTarget_MinAllowedAnchorChannelRemoteFee) {
108108
return 253;
109109
} else {
110110
return 507;
@@ -386,7 +386,7 @@ class PeersConnection {
386386

387387
struct CustomOnionMsgQueue {
388388
std::mutex mtx;
389-
std::vector<LDK::CustomOnionMessageContents> msgs;
389+
std::vector<LDK::OnionMessageContents> msgs;
390390
};
391391

392392
uint64_t custom_onion_msg_type_id(const void *this_arg) {
@@ -400,31 +400,35 @@ LDKCVec_u8Z custom_onion_msg_bytes(const void *this_arg) {
400400
};
401401
}
402402

403-
LDKCOption_CustomOnionMessageContentsZ handle_custom_onion_message(const void* this_arg, struct LDKCustomOnionMessageContents msg) {
403+
LDKCOption_OnionMessageContentsZ handle_custom_onion_message(const void* this_arg, struct LDKOnionMessageContents msg) {
404404
CustomOnionMsgQueue* arg = (CustomOnionMsgQueue*) this_arg;
405405
std::unique_lock<std::mutex> lck(arg->mtx);
406406
arg->msgs.push_back(std::move(msg));
407-
return COption_CustomOnionMessageContentsZ_none();
407+
return COption_OnionMessageContentsZ_none();
408408
}
409409

410-
LDKCustomOnionMessageContents build_custom_onion_message() {
411-
return LDKCustomOnionMessageContents {
410+
LDKOnionMessageContents build_custom_onion_message() {
411+
return LDKOnionMessageContents {
412412
.this_arg = NULL,
413413
.tlv_type = custom_onion_msg_type_id,
414414
.write = custom_onion_msg_bytes,
415415
.free = NULL,
416416
};
417417
}
418418

419-
LDKCResult_COption_CustomOnionMessageContentsZDecodeErrorZ read_custom_onion_message(const void* this_arg, uint64_t type, LDKu8slice buf) {
419+
LDKCResult_COption_OnionMessageContentsZDecodeErrorZ read_custom_onion_message(const void* this_arg, uint64_t type, LDKu8slice buf) {
420420
assert(type == 8888);
421421
assert(buf.datalen == 1024);
422422
uint8_t cmp[1024];
423423
memset(cmp, 43, 1024);
424424
assert(!memcmp(cmp, buf.data, 1024));
425-
return CResult_COption_CustomOnionMessageContentsZDecodeErrorZ_ok(COption_CustomOnionMessageContentsZ_some(build_custom_onion_message()));
425+
return CResult_COption_OnionMessageContentsZDecodeErrorZ_ok(COption_OnionMessageContentsZ_some(build_custom_onion_message()));
426426
}
427427

428+
LDKCVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ release_no_messages(const void* this_arg) {
429+
return LDKCVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ {
430+
.data = NULL, .datalen = 0 };
431+
}
428432

429433
struct CustomMsgQueue {
430434
std::vector<LDK::Type> msgs;
@@ -991,6 +995,7 @@ int main() {
991995
.this_arg = NULL,
992996
.handle_custom_message = NULL, // We only create custom messages, not handle them
993997
.read_custom_message = NULL, // We only create custom messages, not handle them
998+
.release_pending_custom_messages = release_no_messages,
994999
.free = NULL,
9951000
};
9961001
LDK::DefaultMessageRouter mr1 = DefaultMessageRouter_new();
@@ -1018,6 +1023,7 @@ int main() {
10181023
.this_arg = &peer_2_custom_onion_messages,
10191024
.handle_custom_message = handle_custom_onion_message,
10201025
.read_custom_message = read_custom_onion_message,
1026+
.release_pending_custom_messages = release_no_messages,
10211027
.free = NULL,
10221028
};
10231029
LDK::DefaultMessageRouter mr2 = DefaultMessageRouter_new();
@@ -1178,10 +1184,8 @@ int main() {
11781184
LDKCVec_PublicKeyZ { .data = NULL, .datalen = 0, },
11791185
Destination_node(ChannelManager_get_our_node_id(&cm2))
11801186
),
1181-
LDKOnionMessageContents {
1182-
.tag = LDKOnionMessageContents_Custom,
1183-
.custom = build_custom_onion_message()
1184-
}, LDKBlindedPath { .inner = NULL, .is_owned = true })
1187+
build_custom_onion_message(),
1188+
LDKBlindedPath { .inner = NULL, .is_owned = true })
11851189
.result_ok);
11861190
PeerManager_process_events(&net1);
11871191
std::cout << __FILE__ << ":" << __LINE__ << " - " << "Awaiting onion message..." << std::endl;

0 commit comments

Comments
 (0)