Update auto-generated bindings to 0.0.101
[ldk-java] / src / main / java / org / ldk / structs / CustomMessageHandler.java
diff --git a/src/main/java/org/ldk/structs/CustomMessageHandler.java b/src/main/java/org/ldk/structs/CustomMessageHandler.java
new file mode 100644 (file)
index 0000000..fe1a2bb
--- /dev/null
@@ -0,0 +1,107 @@
+package org.ldk.structs;
+
+import org.ldk.impl.bindings;
+import org.ldk.enums.*;
+import org.ldk.util.*;
+import java.util.Arrays;
+import javax.annotation.Nullable;
+
+/**
+ * Handler for BOLT1-compliant messages.
+ */
+@SuppressWarnings("unchecked") // We correctly assign various generic arrays
+public class CustomMessageHandler extends CommonBase {
+       final bindings.LDKCustomMessageHandler bindings_instance;
+       CustomMessageHandler(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
+       private CustomMessageHandler(bindings.LDKCustomMessageHandler arg, bindings.LDKCustomMessageReader CustomMessageReader) {
+               super(bindings.LDKCustomMessageHandler_new(arg, CustomMessageReader));
+               this.ptrs_to.add(arg);
+               this.ptrs_to.add(CustomMessageReader);
+               this.bindings_instance = arg;
+       }
+       @Override @SuppressWarnings("deprecation")
+       protected void finalize() throws Throwable {
+               if (ptr != 0) { bindings.CustomMessageHandler_free(ptr); } super.finalize();
+       }
+
+       public static interface CustomMessageHandlerInterface {
+               /**
+                * Called with the message type that was received and the buffer to be read.
+                * Can return a `MessageHandlingError` if the message could not be handled.
+                */
+               Result_NoneLightningErrorZ handle_custom_message(Type msg, byte[] sender_node_id);
+               /**
+                * Gets the list of pending messages which were generated by the custom message
+                * handler, clearing the list in the process. The first tuple element must
+                * correspond to the intended recipients node ids. If no connection to one of the
+                * specified node does not exist, the message is simply not sent to it.
+                */
+               TwoTuple<byte[], Type>[] get_and_clear_pending_msg();
+       }
+       private static class LDKCustomMessageHandlerHolder { CustomMessageHandler held; }
+       public static CustomMessageHandler new_impl(CustomMessageHandlerInterface arg, CustomMessageReader.CustomMessageReaderInterface CustomMessageReader_impl) {
+               final LDKCustomMessageHandlerHolder impl_holder = new LDKCustomMessageHandlerHolder();
+               impl_holder.held = new CustomMessageHandler(new bindings.LDKCustomMessageHandler() {
+                       @Override public long handle_custom_message(long msg, byte[] sender_node_id) {
+                               Type ret_hu_conv = new Type(null, msg);
+                               ret_hu_conv.ptrs_to.add(this);
+                               Result_NoneLightningErrorZ ret = arg.handle_custom_message(ret_hu_conv, sender_node_id);
+                               long result = ret != null ? ret.ptr : 0;
+                               return result;
+                       }
+                       @Override public long[] get_and_clear_pending_msg() {
+                               TwoTuple<byte[], Type>[] ret = arg.get_and_clear_pending_msg();
+                               long[] result = ret != null ? Arrays.stream(ret).mapToLong(ret_conv_24 -> bindings.C2Tuple_PublicKeyTypeZ_new(ret_conv_24.a, ret_conv_24.b == null ? 0 : ret_conv_24.b.ptr)).toArray() : null;
+                               for (TwoTuple<byte[], Type> ret_conv_24: ret) { impl_holder.held.ptrs_to.add(ret_conv_24.b); };
+                               return result;
+                       }
+               }, CustomMessageReader.new_impl(CustomMessageReader_impl).bindings_instance);
+               return impl_holder.held;
+       }
+
+       /**
+        * Gets the underlying CustomMessageReader.
+        */
+       public CustomMessageReader get_custom_message_reader() {
+               CustomMessageReader res = new CustomMessageReader(null, bindings.LDKCustomMessageHandler_get_CustomMessageReader(this.ptr));
+               this.ptrs_to.add(res);
+               return res;
+       }
+
+       /**
+        * Called with the message type that was received and the buffer to be read.
+        * Can return a `MessageHandlingError` if the message could not be handled.
+        */
+       public Result_NoneLightningErrorZ handle_custom_message(Type msg, byte[] sender_node_id) {
+               long ret = bindings.CustomMessageHandler_handle_custom_message(this.ptr, msg == null ? 0 : msg.ptr, sender_node_id);
+               if (ret < 1024) { return null; }
+               Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
+               this.ptrs_to.add(msg);
+               return ret_hu_conv;
+       }
+
+       /**
+        * Gets the list of pending messages which were generated by the custom message
+        * handler, clearing the list in the process. The first tuple element must
+        * correspond to the intended recipients node ids. If no connection to one of the
+        * specified node does not exist, the message is simply not sent to it.
+        */
+       public TwoTuple<byte[], Type>[] get_and_clear_pending_msg() {
+               long[] ret = bindings.CustomMessageHandler_get_and_clear_pending_msg(this.ptr);
+               TwoTuple<byte[], Type>[] ret_conv_24_arr = new TwoTuple[ret.length];
+               for (int y = 0; y < ret.length; y++) {
+                       long ret_conv_24 = ret[y];
+                       byte[] ret_conv_24_a = bindings.LDKC2Tuple_PublicKeyTypeZ_get_a(ret_conv_24);
+                       long ret_conv_24_b = bindings.LDKC2Tuple_PublicKeyTypeZ_get_b(ret_conv_24);
+                       Type ret_hu_conv = new Type(null, ret_conv_24_b);
+                       ret_hu_conv.ptrs_to.add(this);;
+                       TwoTuple<byte[], Type> ret_conv_24_conv = new TwoTuple<byte[], Type>(ret_conv_24_a, ret_hu_conv, () -> {
+                               bindings.C2Tuple_PublicKeyTypeZ_free(ret_conv_24);
+                       });
+                       ret_hu_conv.ptrs_to.add(ret_conv_24_conv);
+                       ret_conv_24_arr[y] = ret_conv_24_conv;
+               }
+               return ret_conv_24_arr;
+       }
+
+}