X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-c-bindings;a=blobdiff_plain;f=lightning-c-bindings%2Fdemo.cpp;h=cee3054f4a90555a2ec7aba50e221fb5961df3bc;hp=230e33436848b6e2a603ba81194d1e686ae92243;hb=99d22ba053fc347d8116572f20ef1431fc05dee9;hpb=4d85902c5191f9139c2d0be26c040ada0f19117f diff --git a/lightning-c-bindings/demo.cpp b/lightning-c-bindings/demo.cpp index 230e334..cee3054 100644 --- a/lightning-c-bindings/demo.cpp +++ b/lightning-c-bindings/demo.cpp @@ -137,7 +137,7 @@ struct NodeMonitors { void ConnectBlock(const uint8_t (*header)[80], uint32_t height, LDKCVec_C2Tuple_usizeTransactionZZ tx_data, LDKBroadcasterInterface broadcast, LDKFeeEstimator fee_est) { std::unique_lock l(mut); for (auto& mon : mons) { - LDK::CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ res = ChannelMonitor_block_connected(&mon.second, header, tx_data, height, broadcast, fee_est, *logger); + LDK::CVec_TransactionOutputsZ res = ChannelMonitor_block_connected(&mon.second, header, tx_data, height, broadcast, fee_est, *logger); } } }; @@ -361,7 +361,7 @@ int main() { LDK::KeysInterface keys_source1 = KeysManager_as_KeysInterface(&keys1); node_secret1 = keys_source1->get_node_secret(keys_source1->this_arg); - LDK::ChannelManager cm1 = ChannelManager_new(fee_est, mon1, broadcast, logger1, KeysManager_as_KeysInterface(&keys1), UserConfig_default(), ChainParameters_new(network, chain_tip, 0)); + LDK::ChannelManager cm1 = ChannelManager_new(fee_est, mon1, broadcast, logger1, KeysManager_as_KeysInterface(&keys1), UserConfig_default(), ChainParameters_new(network, BestBlock_new(chain_tip, 0))); LDK::CVec_ChannelDetailsZ channels = ChannelManager_list_channels(&cm1); assert(channels->datalen == 0); @@ -373,8 +373,8 @@ int main() { // Demo getting a channel key and check that its returning real pubkeys: LDK::Sign chan_signer1 = keys_source1->get_channel_signer(keys_source1->this_arg, false, 42); - chan_signer1->set_pubkeys(&chan_signer1); // Make sure pubkeys is defined - LDKPublicKey payment_point = ChannelPublicKeys_get_payment_point(&chan_signer1->pubkeys); + chan_signer1->BaseSign.set_pubkeys(&chan_signer1->BaseSign); // Make sure pubkeys is defined + LDKPublicKey payment_point = ChannelPublicKeys_get_payment_point(&chan_signer1->BaseSign.pubkeys); assert(memcmp(&payment_point, &null_pk, sizeof(null_pk))); // Instantiate classes for node 2: @@ -388,7 +388,7 @@ int main() { LDK::UserConfig config2 = UserConfig_default(); UserConfig_set_own_channel_config(&config2, std::move(handshake_config2)); - LDK::ChannelManager cm2 = ChannelManager_new(fee_est, mon2, broadcast, logger2, KeysManager_as_KeysInterface(&keys2), std::move(config2), ChainParameters_new(network, chain_tip, 0)); + LDK::ChannelManager cm2 = ChannelManager_new(fee_est, mon2, broadcast, logger2, KeysManager_as_KeysInterface(&keys2), std::move(config2), ChainParameters_new(network, BestBlock_new(chain_tip, 0))); LDK::CVec_ChannelDetailsZ channels2 = ChannelManager_list_channels(&cm2); assert(channels2->datalen == 0); @@ -437,10 +437,10 @@ int main() { assert(events->data[0].funding_generation_ready.channel_value_satoshis == 40000); assert(events->data[0].funding_generation_ready.output_script.datalen == 34); assert(!memcmp(events->data[0].funding_generation_ready.output_script.data, channel_open_block + 58 + 81, 34)); - LDKThirtyTwoBytes txid; - for (int i = 0; i < 32; i++) { txid.data[i] = channel_open_txid[31-i]; } - LDK::OutPoint outp = OutPoint_new(txid, 0); - ChannelManager_funding_transaction_generated(&cm1, &events->data[0].funding_generation_ready.temporary_channel_id.data, std::move(outp)); + LDKTransaction funding_transaction { .data = const_cast(channel_open_block + 81), .datalen = sizeof(channel_open_block) - 81, .data_is_owned = false }; + + LDK::CResult_NoneAPIErrorZ fund_res = ChannelManager_funding_transaction_generated(&cm1, &events->data[0].funding_generation_ready.temporary_channel_id.data, funding_transaction); + assert(fund_res->result_ok); break; } std::this_thread::yield(); @@ -448,14 +448,9 @@ int main() { // We observe when the funding signed messages have been exchanged by // waiting for two monitors to be registered. + assert(num_txs_broadcasted == 0); PeerManager_process_events(&net1); - while (true) { - LDK::CVec_EventZ events = ev1.get_and_clear_pending_events(ev1.this_arg); - if (events->datalen == 1) { - assert(events->data[0].tag == LDKEvent_FundingBroadcastSafe); - assert(events->data[0].funding_broadcast_safe.user_channel_id == 42); - break; - } + while (num_txs_broadcasted != 1) { std::this_thread::yield(); } @@ -515,7 +510,7 @@ int main() { LDK::NetworkGraph graph_2_ref = LockedNetworkGraph_graph(&graph_2_locked); LDK::CResult_RouteLightningErrorZ route = get_route(ChannelManager_get_our_node_id(&cm1), &graph_2_ref, ChannelManager_get_our_node_id(&cm2), LDKInvoiceFeatures { .inner = NULL, .is_owned = false - }, &outbound_channels, LDKCVec_RouteHintZ { + }, &outbound_channels, LDKCVec_RouteHintHopZ { .data = NULL, .datalen = 0 }, 5000, 10, logger1); assert(route->result_ok);