7 void print_log(const void *this_arg, const LDKRecord record) {
8 LDKStr mod = Record_get_module_path(&record);
9 LDKStr str = Record_get_args(&record);
10 printf("%.*s:%d - %.*s\n", (int)mod.len, mod.chars, Record_get_line(&record), (int)str.len, str.chars);
16 uint32_t get_fee(const void *this_arg, LDKConfirmationTarget target) {
17 if (target == LDKConfirmationTarget_AnchorChannelFee || target == LDKConfirmationTarget_MinAllowedAnchorChannelRemoteFee) {
24 void broadcast_txn(const void *this_arg, LDKCVec_TransactionZ txn) {
26 CVec_TransactionZ_free(txn);
29 LDKCResult_ChannelMonitorUpdateStatusNoneZ add_channel_monitor(const void *this_arg, LDKOutPoint funding_txo, LDKChannelMonitor monitor) {
30 return CResult_ChannelMonitorUpdateStatusNoneZ_ok(ChannelMonitorUpdateStatus_completed());
32 LDKChannelMonitorUpdateStatus update_channel_monitor(const void *this_arg, LDKOutPoint funding_txo, const LDKChannelMonitorUpdate *monitor) {
33 return ChannelMonitorUpdateStatus_completed();
35 LDKCVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ monitors_pending_monitor_events(const void *this_arg) {
36 LDKCVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ empty_htlc_vec = {
40 return empty_htlc_vec;
43 void never_handle_event(const void *this_arg, const struct LDKEvent event) {
44 // Note that we never actually generate any events to handle in the code below.
48 LDKCResult_RouteLightningErrorZ do_find_route(const void *this_arg, LDKPublicKey payer, const LDKRouteParameters *route_params, LDKCVec_ChannelDetailsZ *first_hops, const LDKInFlightHtlcs inflight_htlcs) {
49 LDKStr reason = { .chars = (const unsigned char*)"", .len = 0, .chars_is_owned = false };
50 return CResult_RouteLightningErrorZ_err(LightningError_new(reason, ErrorAction_ignore_error()));
53 LDKCResult_RouteLightningErrorZ do_find_route_with_id(const void *this_arg, LDKPublicKey payer, const LDKRouteParameters *route_params, LDKCVec_ChannelDetailsZ *first_hops, const LDKInFlightHtlcs inflight_htlcs, struct LDKThirtyTwoBytes payment_hash, struct LDKThirtyTwoBytes payment_id) {
54 LDKStr reason = { .chars = (const unsigned char*)"", .len = 0, .chars_is_owned = false };
55 return CResult_RouteLightningErrorZ_err(LightningError_new(reason, ErrorAction_ignore_error()));
59 uint8_t node_seed[32];
60 memset(node_seed, 0, 32);
62 LDKNetwork net = LDKNetwork_Bitcoin;
70 LDKFeeEstimator fee_est = {
72 .get_est_sat_per_1000_weight = get_fee,
78 .watch_channel = add_channel_monitor,
79 .update_channel = update_channel_monitor,
80 .release_pending_monitor_events = monitors_pending_monitor_events,
84 LDKBroadcasterInterface broadcast = {
86 .broadcast_transactions = broadcast_txn,
92 .find_route = do_find_route,
93 .find_route_with_id = do_find_route_with_id,
97 LDKKeysManager keys = KeysManager_new(&node_seed, 0, 0);
98 LDKEntropySource entropy_source = KeysManager_as_EntropySource(&keys);
99 LDKNodeSigner node_signer = KeysManager_as_NodeSigner(&keys);
100 LDKSignerProvider signer_provider = KeysManager_as_SignerProvider(&keys);
102 LDKUserConfig config = UserConfig_default();
103 LDKThirtyTwoBytes chain_tip;
104 memset(&chain_tip, 0, 32);
105 LDKChainParameters chain = ChainParameters_new(net, BestBlock_new(chain_tip, 0));
106 LDKChannelManager cm = ChannelManager_new(fee_est, mon, broadcast, router, logger, entropy_source, node_signer, signer_provider, config, chain, 42);
108 LDKCVec_ChannelDetailsZ channels = ChannelManager_list_channels(&cm);
109 assert((unsigned long)channels.data < 4096); // There's an offset, but it should still be an offset against null in the 0 page
110 assert(channels.datalen == 0);
111 CVec_ChannelDetailsZ_free(channels);
113 LDKEventsProvider prov = ChannelManager_as_EventsProvider(&cm);
114 // Check that no events were generated by asserting if any events are passed to never_handle_event.
115 LDKEventHandler handler = { .handle_event = never_handle_event, .free = NULL };
116 (prov.process_pending_events)(prov.this_arg, handler);
118 ChannelManager_free(cm);
119 KeysManager_free(keys);
121 // Check that passing empty vecs to rust doesn't blow it up:
122 LDKCVec_MonitorEventZ empty_htlc_vec = {
126 CVec_MonitorEventZ_free(empty_htlc_vec);