0x00, // transaction count
};
-void print_log(const void *this_arg, const LDKRecord *record) {
- LDK::Str mod = Record_get_module_path(record);
- LDK::Str str = Record_get_args(record);
- printf("%p - %.*s:%d - %.*s\n", this_arg, (int)mod->len, mod->chars, Record_get_line(record), (int)str->len, str->chars);
+void print_log(const void *this_arg, LDKRecord record_arg) {
+ LDK::Record record(std::move(record_arg));
+ LDK::Str mod = Record_get_module_path(&record);
+ LDK::Str str = Record_get_args(&record);
+ printf("%p - %.*s:%d - %.*s\n", this_arg, (int)mod->len, mod->chars, Record_get_line(&record), (int)str->len, str->chars);
}
uint32_t get_fee(const void *this_arg, LDKConfirmationTarget target) {
- if (target == LDKConfirmationTarget_Background) {
+ if (target == LDKConfirmationTarget_AnchorChannelFee || target == LDKConfirmationTarget_MinAllowedAnchorChannelRemoteFee) {
return 253;
} else {
return 507;
void ConnectBlock(const uint8_t (*header)[80], uint32_t height, LDKCVec_C2Tuple_usizeTransactionZZ tx_data, LDKBroadcasterInterface broadcast, LDKFeeEstimator fee_est) {
std::unique_lock<std::mutex> l(mut);
for (auto& mon : mons) {
- LDK::CVec_TransactionOutputsZ 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);
}
}
};
// Then disconnect the "main" connection, while another connection is being made.
PeerManager_disconnect_by_node_id(&net1, ChannelManager_get_our_node_id(&cm2));
+ PeerManager_disconnect_by_node_id(&net2, ChannelManager_get_our_node_id(&cm1));
assert(!socket_connect(node1_handler, ChannelManager_get_our_node_id(&cm2), (sockaddr*)&listen_addr, sizeof(listen_addr)));
std::cout << __FILE__ << ":" << __LINE__ << " - " << "Awaiting new connection handshake..." << std::endl;
struct CustomOnionMsgQueue {
std::mutex mtx;
- std::vector<LDK::CustomOnionMessageContents> msgs;
+ std::vector<LDK::OnionMessageContents> msgs;
};
uint64_t custom_onion_msg_type_id(const void *this_arg) {
.data = bytes, .datalen = 1024
};
}
+LDKStr custom_onion_msg_str(const void *this_arg) {
+ return LDKStr {
+ .chars = (const uint8_t*)"Custom Onion Message",
+ .len = 20, .chars_is_owned = false
+ };
+}
-LDKCOption_CustomOnionMessageContentsZ handle_custom_onion_message(const void* this_arg, struct LDKCustomOnionMessageContents msg) {
+LDKCOption_OnionMessageContentsZ handle_custom_onion_message(const void* this_arg, struct LDKOnionMessageContents msg) {
CustomOnionMsgQueue* arg = (CustomOnionMsgQueue*) this_arg;
std::unique_lock<std::mutex> lck(arg->mtx);
arg->msgs.push_back(std::move(msg));
- return COption_CustomOnionMessageContentsZ_none();
+ return COption_OnionMessageContentsZ_none();
}
-LDKCustomOnionMessageContents build_custom_onion_message() {
- return LDKCustomOnionMessageContents {
+LDKOnionMessageContents build_custom_onion_message() {
+ return LDKOnionMessageContents {
.this_arg = NULL,
.tlv_type = custom_onion_msg_type_id,
.write = custom_onion_msg_bytes,
+ .debug_str = custom_onion_msg_str,
+ .cloned = NULL,
.free = NULL,
};
}
-LDKCResult_COption_CustomOnionMessageContentsZDecodeErrorZ read_custom_onion_message(const void* this_arg, uint64_t type, LDKu8slice buf) {
+LDKCResult_COption_OnionMessageContentsZDecodeErrorZ read_custom_onion_message(const void* this_arg, uint64_t type, LDKu8slice buf) {
assert(type == 8888);
assert(buf.datalen == 1024);
uint8_t cmp[1024];
memset(cmp, 43, 1024);
assert(!memcmp(cmp, buf.data, 1024));
- return CResult_COption_CustomOnionMessageContentsZDecodeErrorZ_ok(COption_CustomOnionMessageContentsZ_some(build_custom_onion_message()));
+ return CResult_COption_OnionMessageContentsZDecodeErrorZ_ok(COption_OnionMessageContentsZ_some(build_custom_onion_message()));
}
+LDKCVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ release_no_messages(const void* this_arg) {
+ return LDKCVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ {
+ .data = NULL, .datalen = 0 };
+}
struct CustomMsgQueue {
std::vector<LDK::Type> msgs;
return InitFeatures_empty();
}
-uint64_t get_chan_score(const void *this_arg, uint64_t scid, const LDKNodeId *src, const LDKNodeId *dst, LDKChannelUsage usage_in, const LDKProbabilisticScoringFeeParameters *params) {
+uint64_t get_chan_score(const void *this_arg, const LDKCandidateRouteHop *hop, LDKChannelUsage usage_in, const LDKProbabilisticScoringFeeParameters *params) {
LDK::ChannelUsage usage(std::move(usage_in));
return 42;
}
LDK::IgnoringMessageHandler ignoring_handler1 = IgnoringMessageHandler_new();
LDK::CustomMessageHandler custom_msg_handler1 = IgnoringMessageHandler_as_CustomMessageHandler(&ignoring_handler1);
LDK::CustomOnionMessageHandler custom_onion_msg_handler1 = IgnoringMessageHandler_as_CustomOnionMessageHandler(&ignoring_handler1);
- LDK::DefaultMessageRouter mr1 = DefaultMessageRouter_new();
+ LDK::DefaultMessageRouter mr1 = DefaultMessageRouter_new(&net_graph1, KeysManager_as_EntropySource(&keys1));
LDK::OnionMessenger om1 = OnionMessenger_new(KeysManager_as_EntropySource(&keys1), KeysManager_as_NodeSigner(&keys1), logger1, DefaultMessageRouter_as_MessageRouter(&mr1), IgnoringMessageHandler_as_OffersMessageHandler(&ignoring_handler1), std::move(custom_onion_msg_handler1));
LDK::CVec_ChannelDetailsZ channels = ChannelManager_list_channels(&cm1);
LDK::IgnoringMessageHandler ignoring_handler2 = IgnoringMessageHandler_new();
LDK::CustomMessageHandler custom_msg_handler2 = IgnoringMessageHandler_as_CustomMessageHandler(&ignoring_handler2);
LDK::CustomOnionMessageHandler custom_onion_msg_handler2 = IgnoringMessageHandler_as_CustomOnionMessageHandler(&ignoring_handler2);
- LDK::DefaultMessageRouter mr2 = DefaultMessageRouter_new();
+ LDK::DefaultMessageRouter mr2 = DefaultMessageRouter_new(&net_graph2, KeysManager_as_EntropySource(&keys2));
LDK::OnionMessenger om2 = OnionMessenger_new(KeysManager_as_EntropySource(&keys2), KeysManager_as_NodeSigner(&keys2), logger2, DefaultMessageRouter_as_MessageRouter(&mr2), IgnoringMessageHandler_as_OffersMessageHandler(&ignoring_handler2), std::move(custom_onion_msg_handler2));
LDK::CVec_ChannelDetailsZ channels2 = ChannelManager_list_channels(&cm2);
PeersConnection conn(cm1, cm2, net1, net2);
// Note that we have to bind the result to a C++ class to make sure it gets free'd
- LDK::CResult_ThirtyTwoBytesAPIErrorZ res = ChannelManager_create_channel(&cm1, ChannelManager_get_our_node_id(&cm2), 40000, 1000, U128_new(user_id_1), UserConfig_default());
+ LDK::CResult_ThirtyTwoBytesAPIErrorZ res = ChannelManager_create_channel(&cm1, ChannelManager_get_our_node_id(&cm2), 40000, 1000, U128_new(user_id_1), COption_ThirtyTwoBytesZ_none(), UserConfig_default());
assert(res->result_ok);
PeerManager_process_events(&net1);
}, Bolt11Invoice_min_final_cltv_expiry_delta(invoice->contents.result));
LDK::RouteParameters route_params = RouteParameters_from_payment_params_and_value(
PaymentParameters_new(std::move(payee), COption_u64Z_none(), 0xffffffff, 1, 2,
- LDKCVec_u64Z { .data = NULL, .datalen = 0 }),
+ LDKCVec_u64Z { .data = NULL, .datalen = 0 }, LDKCVec_u64Z { .data = NULL, .datalen = 0 }),
5000);
random_bytes = entropy_source1.get_secure_random_bytes();
LDK::ProbabilisticScoringFeeParameters params = ProbabilisticScoringFeeParameters_default();
LDK::MultiThreadedLockableScore scorer_mtx1 = MultiThreadedLockableScore_new(std::move(scorer_trait1));
LDK::LockableScore scorer_mtx_trait1 = MultiThreadedLockableScore_as_LockableScore(&scorer_mtx1);
LDK::ProbabilisticScoringFeeParameters params = ProbabilisticScoringFeeParameters_default();
- const LDK::DefaultRouter default_router_1 = DefaultRouter_new(&net_graph1, logger1, entropy_source1.get_secure_random_bytes(), std::move(scorer_mtx_trait1), std::move(params));
+ const LDK::DefaultRouter default_router_1 = DefaultRouter_new(&net_graph1, logger1, KeysManager_as_EntropySource(&keys1), std::move(scorer_mtx_trait1), std::move(params));
LDKRouter router1 = {
.this_arg = (void*)&default_router_1,
.find_route = NULL, // LDK currently doesn't use this, its just a default-impl
.this_arg = NULL,
.handle_custom_message = NULL, // We only create custom messages, not handle them
.read_custom_message = NULL, // We only create custom messages, not handle them
+ .release_pending_custom_messages = release_no_messages,
.free = NULL,
};
- LDK::DefaultMessageRouter mr1 = DefaultMessageRouter_new();
+ LDK::DefaultMessageRouter mr1 = DefaultMessageRouter_new(&net_graph1, KeysManager_as_EntropySource(&keys1));
LDK::IgnoringMessageHandler ignorer_1 = IgnoringMessageHandler_new();
LDK::OnionMessenger om1 = OnionMessenger_new(KeysManager_as_EntropySource(&keys1), KeysManager_as_NodeSigner(&keys1), logger1, DefaultMessageRouter_as_MessageRouter(&mr1), IgnoringMessageHandler_as_OffersMessageHandler(&ignorer_1), std::move(custom_onion_msg_handler1));
.this_arg = &peer_2_custom_onion_messages,
.handle_custom_message = handle_custom_onion_message,
.read_custom_message = read_custom_onion_message,
+ .release_pending_custom_messages = release_no_messages,
.free = NULL,
};
- LDK::DefaultMessageRouter mr2 = DefaultMessageRouter_new();
+ LDK::DefaultMessageRouter mr2 = DefaultMessageRouter_new(&net_graph2, KeysManager_as_EntropySource(&keys2));
LDK::IgnoringMessageHandler ignorer_2 = IgnoringMessageHandler_new();
LDK::OnionMessenger om2 = OnionMessenger_new(KeysManager_as_EntropySource(&keys2), KeysManager_as_NodeSigner(&keys2), logger2, DefaultMessageRouter_as_MessageRouter(&mr2), IgnoringMessageHandler_as_OffersMessageHandler(&ignorer_2), custom_onion_msg_handler2);
}, 3600, COption_u16Z_none());
assert(invoice_res2->result_ok);
const LDKBolt11Invoice *invoice2 = invoice_res2->contents.result;
- LDK::CResult_ThirtyTwoBytesPaymentErrorZ invoice_pay_res = pay_invoice(invoice2, Retry_attempts(0), &cm1);
+ LDK::CResult_C3Tuple_ThirtyTwoBytesRecipientOnionFieldsRouteParametersZNoneZ pay_params =
+ payment_parameters_from_invoice(invoice2);
+ LDK::RecipientOnionFields invoice2_recipient(std::move(pay_params->contents.result->b));
+ LDK::RouteParameters invoice2_params(std::move(pay_params->contents.result->c));
+ assert(pay_params->result_ok);
+ LDKThirtyTwoBytes payment_id { .data = 0 };
+ LDK::CResult_NoneRetryableSendFailureZ invoice_pay_res = ChannelManager_send_payment(
+ &cm1, std::move(pay_params->contents.result->a), std::move(invoice2_recipient),
+ std::move(payment_id), std::move(invoice2_params), Retry_attempts(0)
+ );
assert(invoice_pay_res->result_ok);
PeerManager_process_events(&net1);
LDK::CVec_ChannelDetailsZ chans_after_close2 = ChannelManager_list_channels(&cm2);
assert(chans_after_close2->datalen == 0);
- assert(OnionMessenger_send_onion_message(&om1,
- OnionMessagePath_new(
- LDKCVec_PublicKeyZ { .data = NULL, .datalen = 0, },
- Destination_node(ChannelManager_get_our_node_id(&cm2))
- ),
- LDKOnionMessageContents {
- .tag = LDKOnionMessageContents_Custom,
- .custom = build_custom_onion_message()
- }, LDKBlindedPath { .inner = NULL, .is_owned = true })
- .result_ok);
+ LDK::CResult_SendSuccessSendErrorZ om_send_res =
+ OnionMessenger_send_onion_message(&om1,
+ build_custom_onion_message(),
+ Destination_node(ChannelManager_get_our_node_id(&cm2)),
+ LDKBlindedPath { .inner = NULL, .is_owned = true });
+ assert(om_send_res->result_ok);
PeerManager_process_events(&net1);
std::cout << __FILE__ << ":" << __LINE__ << " - " << "Awaiting onion message..." << std::endl;
while (true) {