+ std::this_thread::yield();
+ }
+ std::cout << __FILE__ << ":" << __LINE__ << " - " << "Listed usable channel!" << std::endl;
+
+ // Send another payment, this time via the retires path
+ LDK::CResult_Bolt11InvoiceSignOrCreationErrorZ invoice_res2 = create_invoice_from_channelmanager(&cm2,
+ KeysManager_as_NodeSigner(&keys2), logger1,
+ LDKCurrency_Bitcoin, COption_u64Z_some(10000),
+ LDKStr {
+ .chars = (const uint8_t *)"Invoice 2 Description",
+ .len = strlen("Invoice 2 Description"),
+ .chars_is_owned = false
+ }, 3600, COption_u16Z_none());
+ assert(invoice_res2->result_ok);
+ const LDKBolt11Invoice *invoice2 = invoice_res2->contents.result;
+ LDK::CResult_PaymentIdPaymentErrorZ invoice_pay_res = pay_invoice(invoice2, Retry_attempts(0), &cm1);
+ assert(invoice_pay_res->result_ok);
+ PeerManager_process_events(&net1);
+
+ // Check that we received the payment!
+ std::cout << __FILE__ << ":" << __LINE__ << " - " << "Awaiting PendingHTLCsForwardable event..." << std::endl;
+ while (true) {
+ EventQueue queue2;
+ LDKEventHandler handler2 = { .this_arg = &queue2, .handle_event = handle_event, .free = NULL };
+ LDK::EventsProvider ev2 = ChannelManager_as_EventsProvider(&cm2);
+ ev2.process_pending_events(handler2);
+ if (queue2.events.size() == 1) {
+ assert(queue2.events[0]->tag == LDKEvent_PendingHTLCsForwardable);
+ break;
+ }
+ std::this_thread::yield();
+ }
+ std::cout << __FILE__ << ":" << __LINE__ << " - " << "Received PendingHTLCsForwardable event!" << std::endl;
+ ChannelManager_process_pending_htlc_forwards(&cm2);
+ PeerManager_process_events(&net2);
+
+ std::cout << __FILE__ << ":" << __LINE__ << " - " << "Awaiting PaymentClaimable/PaymentClaimed event..." << std::endl;
+ while (true) {
+ EventQueue queue2;
+ LDKEventHandler handler2 = { .this_arg = &queue2, .handle_event = handle_event, .free = NULL };
+ LDK::EventsProvider ev2 = ChannelManager_as_EventsProvider(&cm2);
+ ev2.process_pending_events(handler2);
+ if (queue2.events.size() == 1) {
+ assert(queue2.events[0]->tag == LDKEvent_PaymentClaimable);
+ const struct LDKEvent_LDKPaymentClaimable_Body *event_data = &queue2.events[0]->payment_claimable;
+ assert(!memcmp(event_data->payment_hash.data, Bolt11Invoice_payment_hash(invoice2), 32));
+ assert(event_data->purpose.tag == LDKPaymentPurpose_InvoicePayment);
+ assert(!memcmp(event_data->purpose.invoice_payment.payment_secret.data,
+ Bolt11Invoice_payment_secret(invoice2), 32));
+ assert(event_data->amount_msat == 10000);
+ assert(event_data->purpose.invoice_payment.payment_preimage.tag == LDKCOption_PaymentPreimageZ_Some);
+ ChannelManager_claim_funds(&cm2, event_data->purpose.invoice_payment.payment_preimage.some);
+
+ queue2.events.clear();
+ ev2.process_pending_events(handler2);
+ assert(queue2.events.size() == 1);
+ assert(queue2.events[0]->tag == LDKEvent_PaymentClaimed);
+ assert(!memcmp(queue2.events[0]->payment_claimed.payment_hash.data, Bolt11Invoice_payment_hash(invoice2), 32));
+ assert(queue2.events[0]->payment_claimed.purpose.tag == LDKPaymentPurpose_InvoicePayment);
+
+ break;
+ }
+ std::this_thread::yield();