1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
8 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
9 public class RoutingMessageHandler extends CommonBase {
10 final bindings.LDKRoutingMessageHandler bindings_instance;
11 RoutingMessageHandler(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
12 private RoutingMessageHandler(bindings.LDKRoutingMessageHandler arg) {
13 super(bindings.LDKRoutingMessageHandler_new(arg));
14 this.ptrs_to.add(arg);
15 this.bindings_instance = arg;
17 @Override @SuppressWarnings("deprecation")
18 protected void finalize() throws Throwable {
19 if (ptr != 0) { bindings.RoutingMessageHandler_free(ptr); } super.finalize();
22 public static interface RoutingMessageHandlerInterface {
23 Result_boolLightningErrorZ handle_node_announcement(NodeAnnouncement msg);
24 Result_boolLightningErrorZ handle_channel_announcement(ChannelAnnouncement msg);
25 Result_boolLightningErrorZ handle_channel_update(ChannelUpdate msg);
26 void handle_htlc_fail_channel_update(HTLCFailChannelUpdate update);
27 ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>[] get_next_channel_announcements(long starting_point, byte batch_amount);
28 NodeAnnouncement[] get_next_node_announcements(byte[] starting_point, byte batch_amount);
29 boolean should_request_full_sync(byte[] node_id);
31 private static class LDKRoutingMessageHandlerHolder { RoutingMessageHandler held; }
32 public static RoutingMessageHandler new_impl(RoutingMessageHandlerInterface arg) {
33 final LDKRoutingMessageHandlerHolder impl_holder = new LDKRoutingMessageHandlerHolder();
34 impl_holder.held = new RoutingMessageHandler(new bindings.LDKRoutingMessageHandler() {
35 @Override public long handle_node_announcement(long msg) {
36 NodeAnnouncement msg_hu_conv = new NodeAnnouncement(null, msg);
37 Result_boolLightningErrorZ ret = arg.handle_node_announcement(msg_hu_conv);
38 long result = ret != null ? ret.ptr : 0;
42 @Override public long handle_channel_announcement(long msg) {
43 ChannelAnnouncement msg_hu_conv = new ChannelAnnouncement(null, msg);
44 Result_boolLightningErrorZ ret = arg.handle_channel_announcement(msg_hu_conv);
45 long result = ret != null ? ret.ptr : 0;
49 @Override public long handle_channel_update(long msg) {
50 ChannelUpdate msg_hu_conv = new ChannelUpdate(null, msg);
51 Result_boolLightningErrorZ ret = arg.handle_channel_update(msg_hu_conv);
52 long result = ret != null ? ret.ptr : 0;
56 @Override public void handle_htlc_fail_channel_update(long update) {
57 HTLCFailChannelUpdate update_hu_conv = HTLCFailChannelUpdate.constr_from_ptr(update);
58 arg.handle_htlc_fail_channel_update(update_hu_conv);
60 @Override public long[] get_next_channel_announcements(long starting_point, byte batch_amount) {
61 ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>[] ret = arg.get_next_channel_announcements(starting_point, batch_amount);
62 long[] result = Arrays.stream(ret).mapToLong(arr_conv_63 -> bindings.C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_new(arr_conv_63.a == null ? 0 : arr_conv_63.a.ptr & ~1/*XXX: this.ptrs_to.add(arr_conv_63_a)*/, arr_conv_63.b == null ? 0 : arr_conv_63.b.ptr & ~1/*XXX: this.ptrs_to.add(arr_conv_63_b)*/, arr_conv_63.c == null ? 0 : arr_conv_63.c.ptr & ~1/*XXX: this.ptrs_to.add(arr_conv_63_c)*/)).toArray();
63 /* TODO 2 ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate> */;
66 @Override public long[] get_next_node_announcements(byte[] starting_point, byte batch_amount) {
67 NodeAnnouncement[] ret = arg.get_next_node_announcements(starting_point, batch_amount);
68 long[] result = Arrays.stream(ret).mapToLong(arr_conv_18 -> arr_conv_18 == null ? 0 : arr_conv_18.ptr & ~1).toArray();
69 /* TODO 2 NodeAnnouncement */;
72 @Override public boolean should_request_full_sync(byte[] node_id) {
73 boolean ret = arg.should_request_full_sync(node_id);
77 return impl_holder.held;
79 public Result_boolLightningErrorZ handle_node_announcement(NodeAnnouncement msg) {
80 long ret = bindings.RoutingMessageHandler_handle_node_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1);
81 Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret);
82 ret_hu_conv.ptrs_to.add(this);
83 this.ptrs_to.add(msg);
87 public Result_boolLightningErrorZ handle_channel_announcement(ChannelAnnouncement msg) {
88 long ret = bindings.RoutingMessageHandler_handle_channel_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1);
89 Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret);
90 ret_hu_conv.ptrs_to.add(this);
91 this.ptrs_to.add(msg);
95 public Result_boolLightningErrorZ handle_channel_update(ChannelUpdate msg) {
96 long ret = bindings.RoutingMessageHandler_handle_channel_update(this.ptr, msg == null ? 0 : msg.ptr & ~1);
97 Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret);
98 ret_hu_conv.ptrs_to.add(this);
99 this.ptrs_to.add(msg);
103 public void handle_htlc_fail_channel_update(HTLCFailChannelUpdate update) {
104 bindings.RoutingMessageHandler_handle_htlc_fail_channel_update(this.ptr, update == null ? 0 : update.ptr & ~1);
105 this.ptrs_to.add(update);
108 public ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>[] get_next_channel_announcements(long starting_point, byte batch_amount) {
109 long[] ret = bindings.RoutingMessageHandler_get_next_channel_announcements(this.ptr, starting_point, batch_amount);
110 ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>[] arr_conv_63_arr = new ThreeTuple[ret.length];
111 for (int l = 0; l < ret.length; l++) {
112 long arr_conv_63 = ret[l];
113 long arr_conv_63_a = bindings.LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_get_a(arr_conv_63);
114 ChannelAnnouncement arr_conv_63_a_hu_conv = new ChannelAnnouncement(null, arr_conv_63_a);;
115 long arr_conv_63_b = bindings.LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_get_b(arr_conv_63);
116 ChannelUpdate arr_conv_63_b_hu_conv = new ChannelUpdate(null, arr_conv_63_b);;
117 long arr_conv_63_c = bindings.LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_get_c(arr_conv_63);
118 ChannelUpdate arr_conv_63_c_hu_conv = new ChannelUpdate(null, arr_conv_63_c);;
119 ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate> arr_conv_63_conv = new ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>(arr_conv_63_a_hu_conv, arr_conv_63_b_hu_conv, arr_conv_63_c_hu_conv);
120 arr_conv_63_arr[l] = arr_conv_63_conv;
122 return arr_conv_63_arr;
125 public NodeAnnouncement[] get_next_node_announcements(byte[] starting_point, byte batch_amount) {
126 long[] ret = bindings.RoutingMessageHandler_get_next_node_announcements(this.ptr, starting_point, batch_amount);
127 NodeAnnouncement[] arr_conv_18_arr = new NodeAnnouncement[ret.length];
128 for (int s = 0; s < ret.length; s++) {
129 long arr_conv_18 = ret[s];
130 NodeAnnouncement arr_conv_18_hu_conv = new NodeAnnouncement(null, arr_conv_18);
131 arr_conv_18_arr[s] = arr_conv_18_hu_conv;
133 return arr_conv_18_arr;
136 public boolean should_request_full_sync(byte[] node_id) {
137 boolean ret = bindings.RoutingMessageHandler_should_request_full_sync(this.ptr, node_id);