Skip to content

Commit 730426d

Browse files
committed
Update C++ demo application to LDK 0.0.115
1 parent e1dd5fa commit 730426d

File tree

1 file changed

+40
-13
lines changed

1 file changed

+40
-13
lines changed

lightning-c-bindings/demo.cpp

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,35 @@ int main() {
686686
std::this_thread::yield();
687687
}
688688

689+
// Note that the channel ID is the same as the channel txid reversed as the output index is 0
690+
uint8_t expected_chan_id[32];
691+
for (int i = 0; i < 32; i++) { expected_chan_id[i] = channel_open_txid[31-i]; }
692+
693+
while (true) {
694+
EventQueue queue;
695+
LDKEventHandler handler = { .this_arg = &queue, .handle_event = handle_event, .free = NULL };
696+
ev1.process_pending_events(handler);
697+
if (queue.events.size() == 1) {
698+
assert(queue.events[0]->tag == LDKEvent_ChannelPending);
699+
assert(!memcmp(queue.events[0]->channel_pending.channel_id.data, expected_chan_id, 32));
700+
break;
701+
}
702+
std::this_thread::yield();
703+
}
704+
705+
LDK::EventsProvider ev2 = ChannelManager_as_EventsProvider(&cm2);
706+
while (true) {
707+
EventQueue queue;
708+
LDKEventHandler handler = { .this_arg = &queue, .handle_event = handle_event, .free = NULL };
709+
ev2.process_pending_events(handler);
710+
if (queue.events.size() == 1) {
711+
assert(queue.events[0]->tag == LDKEvent_ChannelPending);
712+
assert(!memcmp(queue.events[0]->channel_pending.channel_id.data, expected_chan_id, 32));
713+
break;
714+
}
715+
std::this_thread::yield();
716+
}
717+
689718
LDK::Listen listener1 = ChannelManager_as_Listen(&cm1);
690719
listener1->block_connected(listener1->this_arg, LDKu8slice { .data = channel_open_block, .datalen = sizeof(channel_open_block) }, 1);
691720

@@ -713,11 +742,6 @@ int main() {
713742
PeerManager_process_events(&net1);
714743
PeerManager_process_events(&net2);
715744

716-
// Note that the channel ID is the same as the channel txid reversed as the output index is 0
717-
uint8_t expected_chan_id[32];
718-
for (int i = 0; i < 32; i++) { expected_chan_id[i] = channel_open_txid[31-i]; }
719-
720-
LDK::EventsProvider ev2 = ChannelManager_as_EventsProvider(&cm2);
721745
while (true) {
722746
EventQueue queue;
723747
LDKEventHandler handler = { .this_arg = &queue, .handle_event = handle_event, .free = NULL };
@@ -794,24 +818,26 @@ int main() {
794818
LDK::RouteParameters route_params = RouteParameters_new(PaymentParameters_new(
795819
ChannelManager_get_our_node_id(&cm2), LDKInvoiceFeatures {
796820
.inner = NULL, .is_owned = false
797-
}, Invoice_route_hints(invoice->contents.result), COption_u64Z_none(), 0xffffffff,
798-
1, 2, LDKCVec_u64Z { .data = NULL, .datalen = 0 },
821+
}, Hints_clear(Invoice_route_hints(invoice->contents.result)), COption_u64Z_none(),
822+
0xffffffff, 1, 2, LDKCVec_u64Z { .data = NULL, .datalen = 0 },
799823
Invoice_min_final_cltv_expiry_delta(invoice->contents.result)),
800824
5000);
801825
random_bytes = entropy_source1.get_secure_random_bytes();
802826

803827
LDK::CResult_RouteLightningErrorZ route = find_route(ChannelManager_get_our_node_id(&cm1), &route_params, &net_graph2, &outbound_channels, logger1, &chan_scorer, &random_bytes.data);
804828

805829
assert(route->result_ok);
806-
LDK::CVec_CVec_RouteHopZZ paths = Route_get_paths(route->contents.result);
830+
LDK::CVec_PathZ paths = Route_get_paths(route->contents.result);
807831
assert(paths->datalen == 1);
808-
assert(paths->data[0].datalen == 1);
809-
assert(!memcmp(RouteHop_get_pubkey(&paths->data[0].data[0]).compressed_form,
832+
LDK::CVec_RouteHopZ hops = Path_get_hops(&paths->data[0]);
833+
assert(hops->datalen == 1);
834+
assert(!memcmp(RouteHop_get_pubkey(&hops->data[0]).compressed_form,
810835
ChannelManager_get_our_node_id(&cm2).compressed_form, 33));
811-
assert(RouteHop_get_short_channel_id(&paths->data[0].data[0]) == channel_scid);
836+
assert(RouteHop_get_short_channel_id(&hops->data[0]) == channel_scid);
812837
LDKThirtyTwoBytes payment_secret;
813838
memcpy(payment_secret.data, Invoice_payment_secret(invoice->contents.result), 32);
814-
LDK::CResult_NonePaymentSendFailureZ send_res = ChannelManager_send_payment(&cm1, route->contents.result, payment_hash, payment_secret, payment_hash);
839+
LDK::CResult_NonePaymentSendFailureZ send_res = ChannelManager_send_payment_with_route(&cm1,
840+
route->contents.result, payment_hash, RecipientOnionFields_secret_only(payment_secret), payment_hash);
815841
assert(send_res->result_ok);
816842
}
817843

@@ -991,6 +1017,7 @@ int main() {
9911017
if (outbound_channels->datalen == 1) {
9921018
break;
9931019
}
1020+
std::this_thread::yield();
9941021
}
9951022

9961023
// Send another payment, this time via the retires path
@@ -1103,5 +1130,5 @@ int main() {
11031130
memset(&sk, 42, 32);
11041131
LDKThirtyTwoBytes kdiv_params;
11051132
memset(&kdiv_params, 43, 32);
1106-
LDK::InMemorySigner signer = InMemorySigner_new(sk, sk, sk, sk, sk, random_bytes, 42, kdiv_params);
1133+
LDK::InMemorySigner signer = InMemorySigner_new(sk, sk, sk, sk, sk, random_bytes, 42, kdiv_params, kdiv_params);
11071134
}

0 commit comments

Comments
 (0)