Properly handle java refs in traits returning traits
[ldk-java] / src / main / java / org / ldk / structs / KeysInterface.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7
8 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
9 public class KeysInterface extends CommonBase {
10         final bindings.LDKKeysInterface bindings_instance;
11         KeysInterface(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
12         private KeysInterface(bindings.LDKKeysInterface arg) {
13                 super(bindings.LDKKeysInterface_new(arg));
14                 this.ptrs_to.add(arg);
15                 this.bindings_instance = arg;
16         }
17         @Override @SuppressWarnings("deprecation")
18         protected void finalize() throws Throwable {
19                 if (ptr != 0) { bindings.KeysInterface_free(ptr); } super.finalize();
20         }
21
22         public static interface KeysInterfaceInterface {
23                 byte[] get_node_secret();
24                 byte[] get_destination_script();
25                 byte[] get_shutdown_pubkey();
26                 ChannelKeys get_channel_keys(boolean inbound, long channel_value_satoshis);
27                 byte[] get_secure_random_bytes();
28         }
29         private static class LDKKeysInterfaceHolder { KeysInterface held; }
30         public static KeysInterface new_impl(KeysInterfaceInterface arg) {
31                 final LDKKeysInterfaceHolder impl_holder = new LDKKeysInterfaceHolder();
32                 impl_holder.held = new KeysInterface(new bindings.LDKKeysInterface() {
33                         @Override public byte[] get_node_secret() {
34                                 byte[] ret = arg.get_node_secret();
35                                 return ret;
36                         }
37                         @Override public byte[] get_destination_script() {
38                                 byte[] ret = arg.get_destination_script();
39                                 return ret;
40                         }
41                         @Override public byte[] get_shutdown_pubkey() {
42                                 byte[] ret = arg.get_shutdown_pubkey();
43                                 return ret;
44                         }
45                         @Override public long get_channel_keys(boolean inbound, long channel_value_satoshis) {
46                                 ChannelKeys ret = arg.get_channel_keys(inbound, channel_value_satoshis);
47                                 long result = ret == null ? 0 : ret.ptr;
48                                 impl_holder.held.ptrs_to.add(ret);
49                                 ret.ptr = 0;
50                                 return result;
51                         }
52                         @Override public byte[] get_secure_random_bytes() {
53                                 byte[] ret = arg.get_secure_random_bytes();
54                                 return ret;
55                         }
56                 });
57                 return impl_holder.held;
58         }
59         public byte[] get_node_secret() {
60                 byte[] ret = bindings.KeysInterface_get_node_secret(this.ptr);
61                 return ret;
62         }
63
64         public byte[] get_destination_script() {
65                 byte[] ret = bindings.KeysInterface_get_destination_script(this.ptr);
66                 return ret;
67         }
68
69         public byte[] get_shutdown_pubkey() {
70                 byte[] ret = bindings.KeysInterface_get_shutdown_pubkey(this.ptr);
71                 return ret;
72         }
73
74         public ChannelKeys get_channel_keys(boolean inbound, long channel_value_satoshis) {
75                 long ret = bindings.KeysInterface_get_channel_keys(this.ptr, inbound, channel_value_satoshis);
76                 ChannelKeys ret_hu_conv = new ChannelKeys(null, ret);
77                 ret_hu_conv.ptrs_to.add(this);
78                 return ret_hu_conv;
79         }
80
81         public byte[] get_secure_random_bytes() {
82                 byte[] ret = bindings.KeysInterface_get_secure_random_bytes(this.ptr);
83                 return ret;
84         }
85
86 }