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);
15 uint32_t get_fee(const void *this_arg, LDKConfirmationTarget target) {
16 if (target == LDKConfirmationTarget_AnchorChannelFee || target == LDKConfirmationTarget_MinAllowedAnchorChannelRemoteFee) {
23 void broadcast_txn(const void *this_arg, LDKCVec_TransactionZ txn) {
25 CVec_TransactionZ_free(txn);
28 LDKCResult_ChannelMonitorUpdateStatusNoneZ add_channel_monitor(const void *this_arg, LDKOutPoint funding_txo, LDKChannelMonitor monitor) {
29 return CResult_ChannelMonitorUpdateStatusNoneZ_ok(ChannelMonitorUpdateStatus_completed());
31 LDKChannelMonitorUpdateStatus update_channel_monitor(const void *this_arg, LDKOutPoint funding_txo, const LDKChannelMonitorUpdate *monitor) {
32 return ChannelMonitorUpdateStatus_completed();
34 LDKCVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ monitors_pending_monitor_events(const void *this_arg) {
35 LDKCVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ empty_htlc_vec = {
39 return empty_htlc_vec;
42 void never_handle_event(const void *this_arg, const struct LDKEvent event) {
43 // Note that we never actually generate any events to handle in the code below.
47 LDKCResult_RouteLightningErrorZ do_find_route(const void *this_arg, LDKPublicKey payer, const LDKRouteParameters *route_params, LDKCVec_ChannelDetailsZ *first_hops, const LDKInFlightHtlcs inflight_htlcs) {
48 LDKStr reason = { .chars = (const unsigned char*)"", .len = 0, .chars_is_owned = false };
49 return CResult_RouteLightningErrorZ_err(LightningError_new(reason, ErrorAction_ignore_error()));
52 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) {
53 LDKStr reason = { .chars = (const unsigned char*)"", .len = 0, .chars_is_owned = false };
54 return CResult_RouteLightningErrorZ_err(LightningError_new(reason, ErrorAction_ignore_error()));
58 uint8_t node_seed[32];
59 memset(node_seed, 0, 32);
61 LDKNetwork net = LDKNetwork_Bitcoin;
69 LDKFeeEstimator fee_est = {
71 .get_est_sat_per_1000_weight = get_fee,
77 .watch_channel = add_channel_monitor,
78 .update_channel = update_channel_monitor,
79 .release_pending_monitor_events = monitors_pending_monitor_events,
83 LDKBroadcasterInterface broadcast = {
85 .broadcast_transactions = broadcast_txn,
91 .find_route = do_find_route,
92 .find_route_with_id = do_find_route_with_id,
96 LDKKeysManager keys = KeysManager_new(&node_seed, 0, 0);
97 LDKEntropySource entropy_source = KeysManager_as_EntropySource(&keys);
98 LDKNodeSigner node_signer = KeysManager_as_NodeSigner(&keys);
99 LDKSignerProvider signer_provider = KeysManager_as_SignerProvider(&keys);
101 LDKUserConfig config = UserConfig_default();
102 LDKThirtyTwoBytes chain_tip;
103 memset(&chain_tip, 0, 32);
104 LDKChainParameters chain = ChainParameters_new(net, BestBlock_new(chain_tip, 0));
105 LDKChannelManager cm = ChannelManager_new(fee_est, mon, broadcast, router, logger, entropy_source, node_signer, signer_provider, config, chain, 42);
107 LDKCVec_ChannelDetailsZ channels = ChannelManager_list_channels(&cm);
108 assert((unsigned long)channels.data < 4096); // There's an offset, but it should still be an offset against null in the 0 page
109 assert(channels.datalen == 0);
110 CVec_ChannelDetailsZ_free(channels);
112 LDKEventsProvider prov = ChannelManager_as_EventsProvider(&cm);
113 // Check that no events were generated by asserting if any events are passed to never_handle_event.
114 LDKEventHandler handler = { .handle_event = never_handle_event, .free = NULL };
115 (prov.process_pending_events)(prov.this_arg, handler);
117 ChannelManager_free(cm);
118 KeysManager_free(keys);
120 // Check that passing empty vecs to rust doesn't blow it up:
121 LDKCVec_MonitorEventZ empty_htlc_vec = {
125 CVec_MonitorEventZ_free(empty_htlc_vec);