X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fdemo.cpp;h=1412f2b11b42441b44e279c11c244a830ed62c3f;hb=fe137917d82cc7ea9db8ed03af6a095f3cf3774e;hp=06be77f3504885495f41f3429b996a8d7d2c1b7c;hpb=78bee4f7e0ea0a48dbf5bb1227ed96e6cb3a041a;p=ldk-c-bindings diff --git a/lightning-c-bindings/demo.cpp b/lightning-c-bindings/demo.cpp index 06be77f..1412f2b 100644 --- a/lightning-c-bindings/demo.cpp +++ b/lightning-c-bindings/demo.cpp @@ -308,7 +308,7 @@ public: .disconnect_socket = sock_disconnect_socket, .eq = sock_eq, .hash = sock_hash, - .clone = NULL, + .cloned = NULL, .free = NULL, }; @@ -318,7 +318,7 @@ public: .disconnect_socket = sock_disconnect_socket, .eq = sock_eq, .hash = sock_hash, - .clone = NULL, + .cloned = NULL, .free = NULL, }; @@ -481,14 +481,16 @@ int main() { LDK::CVec_ChannelDetailsZ new_channels = ChannelManager_list_channels(&cm1); assert(new_channels->datalen == 1); - LDKPublicKey chan_open_pk = ChannelDetails_get_remote_network_id(&new_channels->data[0]); + LDK::ChannelCounterparty new_channels_counterparty = ChannelDetails_get_counterparty(&new_channels->data[0]); + LDKPublicKey chan_open_pk = ChannelCounterparty_get_node_id(&new_channels_counterparty); assert(!memcmp(chan_open_pk.compressed_form, ChannelManager_get_our_node_id(&cm2).compressed_form, 33)); while (true) { LDK::CVec_ChannelDetailsZ new_channels_2 = ChannelManager_list_channels(&cm2); if (new_channels_2->datalen == 1) { // Sample getting our counterparty's init features (which used to be hard to do without a memory leak): - const LDK::InitFeatures init_feats = ChannelDetails_get_counterparty_features(&new_channels_2->data[0]); + LDK::ChannelCounterparty new_channels_2_counterparty = ChannelDetails_get_counterparty(&new_channels_2->data[0]); + const LDK::InitFeatures init_feats = ChannelCounterparty_get_features(&new_channels_2_counterparty); assert(init_feats->inner != NULL); break; } @@ -551,21 +553,30 @@ int main() { PeerManager_process_events(&net2); // Now send funds from 1 to 2! + uint64_t channel_scid; while (true) { LDK::CVec_ChannelDetailsZ outbound_channels = ChannelManager_list_usable_channels(&cm1); if (outbound_channels->datalen == 1) { const LDKChannelDetails *channel = &outbound_channels->data[0]; + LDK::ChannelCounterparty counterparty = ChannelDetails_get_counterparty(channel); // Note that the channel ID is the same as the channel txid reversed as the output index is 0 uint8_t expected_chan_id[32]; for (int i = 0; i < 32; i++) { expected_chan_id[i] = channel_open_txid[31-i]; } assert(!memcmp(ChannelDetails_get_channel_id(channel), expected_chan_id, 32)); - assert(!memcmp(ChannelDetails_get_remote_network_id(channel).compressed_form, - ChannelManager_get_our_node_id(&cm2).compressed_form, 33)); + assert(!memcmp( + ChannelCounterparty_get_node_id(&counterparty).compressed_form, + ChannelManager_get_our_node_id(&cm2).compressed_form, 33)); assert(ChannelDetails_get_channel_value_satoshis(channel) == 40000); // We opened the channel with 1000 push_msat: - assert(ChannelDetails_get_outbound_capacity_msat(channel) == 40000*1000 - 1000); - assert(ChannelDetails_get_inbound_capacity_msat(channel) == 1000); + assert(ChannelDetails_get_outbound_capacity_msat(channel) == + 40000*1000 - 1000 - 1000 * ChannelCounterparty_get_unspendable_punishment_reserve(&counterparty)); + int64_t inbound_capacity = ((int64_t)1000) - ChannelCounterparty_get_unspendable_punishment_reserve(&counterparty); + if (inbound_capacity < 0) inbound_capacity = 0; + assert(ChannelDetails_get_inbound_capacity_msat(channel) == (uint64_t)inbound_capacity); assert(ChannelDetails_get_is_usable(channel)); + LDK::COption_u64Z scid_opt = ChannelDetails_get_short_channel_id(channel); + assert(scid_opt->some); + channel_scid = scid_opt->some; break; } std::this_thread::yield(); @@ -596,6 +607,12 @@ int main() { }, &outbound_channels, Invoice_route_hints(invoice->contents.result), 5000, Invoice_min_final_cltv_expiry(invoice->contents.result), logger1); assert(route->result_ok); + LDK::CVec_CVec_RouteHopZZ paths = Route_get_paths(route->contents.result); + assert(paths->datalen == 1); + assert(paths->data[0].datalen == 1); + assert(!memcmp(RouteHop_get_pubkey(&paths->data[0].data[0]).compressed_form, + ChannelManager_get_our_node_id(&cm2).compressed_form, 33)); + assert(RouteHop_get_short_channel_id(&paths->data[0].data[0]) == channel_scid); LDK::CResult_NonePaymentSendFailureZ send_res = ChannelManager_send_payment(&cm1, route->contents.result, payment_hash, Invoice_payment_secret(invoice->contents.result)); assert(send_res->result_ok); } @@ -630,9 +647,11 @@ int main() { assert(queue.events.size() == 1); assert(queue.events[0]->tag == LDKEvent_PaymentReceived); assert(!memcmp(queue.events[0]->payment_received.payment_hash.data, payment_hash.data, 32)); - assert(!memcmp(queue.events[0]->payment_received.payment_secret.data, Invoice_payment_secret(invoice->contents.result).data, 32)); + assert(queue.events[0]->payment_received.purpose.tag == LDKPaymentPurpose_InvoicePayment); + assert(!memcmp(queue.events[0]->payment_received.purpose.invoice_payment.payment_secret.data, + Invoice_payment_secret(invoice->contents.result).data, 32)); assert(queue.events[0]->payment_received.amt == 5000); - memcpy(payment_preimage.data, queue.events[0]->payment_received.payment_preimage.data, 32); + memcpy(payment_preimage.data, queue.events[0]->payment_received.purpose.invoice_payment.payment_preimage.data, 32); assert(ChannelManager_claim_funds(&cm2, payment_preimage)); } PeerManager_process_events(&net2);