Fix returning traits in trait calls, move towards clone on return
[ldk-java] / src / main / java / org / ldk / structs / KeysInterface.java
index 665c143a6c2677a1a9f178ce080b78c1c030e040..cc934aef83befc9bbb7c865b9a4ef1e68af21a6e 100644 (file)
@@ -1,39 +1,84 @@
 package org.ldk.structs;
 
 import org.ldk.impl.bindings;
-
 import org.ldk.enums.*;
+import org.ldk.util.*;
+import java.util.Arrays;
 
+@SuppressWarnings("unchecked") // We correctly assign various generic arrays
 public class KeysInterface extends CommonBase {
-       KeysInterface(Object _dummy, long ptr) { super(ptr); }
-       public KeysInterface(bindings.LDKKeysInterface arg) {
+       final bindings.LDKKeysInterface bindings_instance;
+       KeysInterface(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
+       private KeysInterface(bindings.LDKKeysInterface arg) {
                super(bindings.LDKKeysInterface_new(arg));
                this.ptrs_to.add(arg);
+               this.bindings_instance = arg;
        }
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
-               bindings.KeysInterface_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.KeysInterface_free(ptr); } super.finalize();
        }
 
-       public byte[] call_get_node_secret() {
-               byte[] ret = bindings.KeysInterface_call_get_node_secret(this.ptr);
+       public static interface KeysInterfaceInterface {
+               byte[] get_node_secret();
+               byte[] get_destination_script();
+               byte[] get_shutdown_pubkey();
+               ChannelKeys get_channel_keys(boolean inbound, long channel_value_satoshis);
+               byte[] get_secure_random_bytes();
+       }
+       private static class LDKKeysInterfaceHolder { KeysInterface held; }
+       public static KeysInterface new_impl(KeysInterfaceInterface arg) {
+               final LDKKeysInterfaceHolder impl_holder = new LDKKeysInterfaceHolder();
+               impl_holder.held = new KeysInterface(new bindings.LDKKeysInterface() {
+                       @Override public byte[] get_node_secret() {
+                               byte[] ret = arg.get_node_secret();
+                               return ret;
+                       }
+                       @Override public byte[] get_destination_script() {
+                               byte[] ret = arg.get_destination_script();
+                               return ret;
+                       }
+                       @Override public byte[] get_shutdown_pubkey() {
+                               byte[] ret = arg.get_shutdown_pubkey();
+                               return ret;
+                       }
+                       @Override public long get_channel_keys(boolean inbound, long channel_value_satoshis) {
+                               ChannelKeys ret = arg.get_channel_keys(inbound, channel_value_satoshis);
+                               long result = ret == null ? 0 : ret.ptr;
+                               impl_holder.held.ptrs_to.add(ret);
+                               return result;
+                       }
+                       @Override public byte[] get_secure_random_bytes() {
+                               byte[] ret = arg.get_secure_random_bytes();
+                               return ret;
+                       }
+               });
+               return impl_holder.held;
+       }
+       public byte[] get_node_secret() {
+               byte[] ret = bindings.KeysInterface_get_node_secret(this.ptr);
                return ret;
        }
 
-       // Skipped KeysInterface_call_get_destination_script
-       public byte[] call_get_shutdown_pubkey() {
-               byte[] ret = bindings.KeysInterface_call_get_shutdown_pubkey(this.ptr);
+       public byte[] get_destination_script() {
+               byte[] ret = bindings.KeysInterface_get_destination_script(this.ptr);
                return ret;
        }
 
-       public ChannelKeys call_get_channel_keys(boolean inbound, long channel_value_satoshis) {
-               ChannelKeys ret = new ChannelKeys(null, bindings.KeysInterface_call_get_channel_keys(this.ptr, inbound, channel_value_satoshis));
-               ret.ptrs_to.add(this);
+       public byte[] get_shutdown_pubkey() {
+               byte[] ret = bindings.KeysInterface_get_shutdown_pubkey(this.ptr);
                return ret;
        }
 
-       public byte[] call_get_secure_random_bytes() {
-               byte[] ret = bindings.KeysInterface_call_get_secure_random_bytes(this.ptr);
+       public ChannelKeys get_channel_keys(boolean inbound, long channel_value_satoshis) {
+               long ret = bindings.KeysInterface_get_channel_keys(this.ptr, inbound, channel_value_satoshis);
+               ChannelKeys ret_hu_conv = new ChannelKeys(null, ret);
+               ret_hu_conv.ptrs_to.add(this);
+               return ret_hu_conv;
+       }
+
+       public byte[] get_secure_random_bytes() {
+               byte[] ret = bindings.KeysInterface_get_secure_random_bytes(this.ptr);
                return ret;
        }