[Java] Update auto-generated Java bindings
[ldk-java] / src / main / java / org / ldk / structs / SignerProvider.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 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10 /**
11  * A trait that can return signer instances for individual channels.
12  */
13 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
14 public class SignerProvider extends CommonBase {
15         final bindings.LDKSignerProvider bindings_instance;
16         SignerProvider(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
17         private SignerProvider(bindings.LDKSignerProvider arg) {
18                 super(bindings.LDKSignerProvider_new(arg));
19                 this.ptrs_to.add(arg);
20                 this.bindings_instance = arg;
21         }
22         @Override @SuppressWarnings("deprecation")
23         protected void finalize() throws Throwable {
24                 if (ptr != 0) { bindings.SignerProvider_free(ptr); } super.finalize();
25         }
26         /**
27          * Destroys the object, freeing associated resources. After this call, any access
28          * to this object may result in a SEGFAULT or worse.
29          *
30          * You should generally NEVER call this method. You should let the garbage collector
31          * do this for you when it finalizes objects. However, it may be useful for types
32          * which represent locks and should be closed immediately to avoid holding locks
33          * until the GC runs.
34          */
35         public void destroy() {
36                 if (ptr != 0) { bindings.SignerProvider_free(ptr); }
37                 ptr = 0;
38         }
39         public static interface SignerProviderInterface {
40                 /**
41                  * Generates a unique `channel_keys_id` that can be used to obtain a [`Self::Signer`] through
42                  * [`SignerProvider::derive_channel_signer`]. The `user_channel_id` is provided to allow
43                  * implementations of [`SignerProvider`] to maintain a mapping between itself and the generated
44                  * `channel_keys_id`.
45                  * 
46                  * This method must return a different value each time it is called.
47                  */
48                 byte[] generate_channel_keys_id(boolean inbound, long channel_value_satoshis, UInt128 user_channel_id);
49                 /**
50                  * Derives the private key material backing a `Signer`.
51                  * 
52                  * To derive a new `Signer`, a fresh `channel_keys_id` should be obtained through
53                  * [`SignerProvider::generate_channel_keys_id`]. Otherwise, an existing `Signer` can be
54                  * re-derived from its `channel_keys_id`, which can be obtained through its trait method
55                  * [`ChannelSigner::channel_keys_id`].
56                  */
57                 WriteableEcdsaChannelSigner derive_channel_signer(long channel_value_satoshis, byte[] channel_keys_id);
58                 /**
59                  * Reads a [`Signer`] for this [`SignerProvider`] from the given input stream.
60                  * This is only called during deserialization of other objects which contain
61                  * [`WriteableEcdsaChannelSigner`]-implementing objects (i.e., [`ChannelMonitor`]s and [`ChannelManager`]s).
62                  * The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
63                  * contain no versioning scheme. You may wish to include your own version prefix and ensure
64                  * you've read all of the provided bytes to ensure no corruption occurred.
65                  * 
66                  * This method is slowly being phased out -- it will only be called when reading objects
67                  * written by LDK versions prior to 0.0.113.
68                  * 
69                  * [`Signer`]: Self::Signer
70                  * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
71                  * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
72                  */
73                 Result_WriteableEcdsaChannelSignerDecodeErrorZ read_chan_signer(byte[] reader);
74                 /**
75                  * Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
76                  * 
77                  * This method should return a different value each time it is called, to avoid linking
78                  * on-chain funds across channels as controlled to the same user.
79                  */
80                 byte[] get_destination_script();
81                 /**
82                  * Get a script pubkey which we will send funds to when closing a channel.
83                  * 
84                  * This method should return a different value each time it is called, to avoid linking
85                  * on-chain funds across channels as controlled to the same user.
86                  */
87                 ShutdownScript get_shutdown_scriptpubkey();
88         }
89         private static class LDKSignerProviderHolder { SignerProvider held; }
90         public static SignerProvider new_impl(SignerProviderInterface arg) {
91                 final LDKSignerProviderHolder impl_holder = new LDKSignerProviderHolder();
92                 impl_holder.held = new SignerProvider(new bindings.LDKSignerProvider() {
93                         @Override public byte[] generate_channel_keys_id(boolean inbound, long channel_value_satoshis, byte[] user_channel_id) {
94                                 org.ldk.util.UInt128 user_channel_id_conv = new org.ldk.util.UInt128(user_channel_id);
95                                 byte[] ret = arg.generate_channel_keys_id(inbound, channel_value_satoshis, user_channel_id_conv);
96                                 Reference.reachabilityFence(arg);
97                                 byte[] result = InternalUtils.check_arr_len(ret, 32);
98                                 return result;
99                         }
100                         @Override public long derive_channel_signer(long channel_value_satoshis, byte[] channel_keys_id) {
101                                 WriteableEcdsaChannelSigner ret = arg.derive_channel_signer(channel_value_satoshis, channel_keys_id);
102                                 Reference.reachabilityFence(arg);
103                                 long result = ret == null ? 0 : ret.clone_ptr();
104                                 if (impl_holder.held != null) { impl_holder.held.ptrs_to.add(ret); };
105                                 return result;
106                         }
107                         @Override public long read_chan_signer(byte[] reader) {
108                                 Result_WriteableEcdsaChannelSignerDecodeErrorZ ret = arg.read_chan_signer(reader);
109                                 Reference.reachabilityFence(arg);
110                                 long result = ret == null ? 0 : ret.clone_ptr();
111                                 return result;
112                         }
113                         @Override public byte[] get_destination_script() {
114                                 byte[] ret = arg.get_destination_script();
115                                 Reference.reachabilityFence(arg);
116                                 return ret;
117                         }
118                         @Override public long get_shutdown_scriptpubkey() {
119                                 ShutdownScript ret = arg.get_shutdown_scriptpubkey();
120                                 Reference.reachabilityFence(arg);
121                                 long result = ret == null ? 0 : ret.clone_ptr();
122                                 return result;
123                         }
124                 });
125                 return impl_holder.held;
126         }
127         /**
128          * Generates a unique `channel_keys_id` that can be used to obtain a [`Self::Signer`] through
129          * [`SignerProvider::derive_channel_signer`]. The `user_channel_id` is provided to allow
130          * implementations of [`SignerProvider`] to maintain a mapping between itself and the generated
131          * `channel_keys_id`.
132          * 
133          * This method must return a different value each time it is called.
134          */
135         public byte[] generate_channel_keys_id(boolean inbound, long channel_value_satoshis, org.ldk.util.UInt128 user_channel_id) {
136                 byte[] ret = bindings.SignerProvider_generate_channel_keys_id(this.ptr, inbound, channel_value_satoshis, user_channel_id.getLEBytes());
137                 Reference.reachabilityFence(this);
138                 Reference.reachabilityFence(inbound);
139                 Reference.reachabilityFence(channel_value_satoshis);
140                 Reference.reachabilityFence(user_channel_id);
141                 return ret;
142         }
143
144         /**
145          * Derives the private key material backing a `Signer`.
146          * 
147          * To derive a new `Signer`, a fresh `channel_keys_id` should be obtained through
148          * [`SignerProvider::generate_channel_keys_id`]. Otherwise, an existing `Signer` can be
149          * re-derived from its `channel_keys_id`, which can be obtained through its trait method
150          * [`ChannelSigner::channel_keys_id`].
151          */
152         public WriteableEcdsaChannelSigner derive_channel_signer(long channel_value_satoshis, byte[] channel_keys_id) {
153                 long ret = bindings.SignerProvider_derive_channel_signer(this.ptr, channel_value_satoshis, InternalUtils.check_arr_len(channel_keys_id, 32));
154                 Reference.reachabilityFence(this);
155                 Reference.reachabilityFence(channel_value_satoshis);
156                 Reference.reachabilityFence(channel_keys_id);
157                 if (ret >= 0 && ret <= 4096) { return null; }
158                 WriteableEcdsaChannelSigner ret_hu_conv = new WriteableEcdsaChannelSigner(null, ret);
159                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
160                 return ret_hu_conv;
161         }
162
163         /**
164          * Reads a [`Signer`] for this [`SignerProvider`] from the given input stream.
165          * This is only called during deserialization of other objects which contain
166          * [`WriteableEcdsaChannelSigner`]-implementing objects (i.e., [`ChannelMonitor`]s and [`ChannelManager`]s).
167          * The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
168          * contain no versioning scheme. You may wish to include your own version prefix and ensure
169          * you've read all of the provided bytes to ensure no corruption occurred.
170          * 
171          * This method is slowly being phased out -- it will only be called when reading objects
172          * written by LDK versions prior to 0.0.113.
173          * 
174          * [`Signer`]: Self::Signer
175          * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
176          * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
177          */
178         public Result_WriteableEcdsaChannelSignerDecodeErrorZ read_chan_signer(byte[] reader) {
179                 long ret = bindings.SignerProvider_read_chan_signer(this.ptr, reader);
180                 Reference.reachabilityFence(this);
181                 Reference.reachabilityFence(reader);
182                 if (ret >= 0 && ret <= 4096) { return null; }
183                 Result_WriteableEcdsaChannelSignerDecodeErrorZ ret_hu_conv = Result_WriteableEcdsaChannelSignerDecodeErrorZ.constr_from_ptr(ret);
184                 return ret_hu_conv;
185         }
186
187         /**
188          * Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
189          * 
190          * This method should return a different value each time it is called, to avoid linking
191          * on-chain funds across channels as controlled to the same user.
192          */
193         public byte[] get_destination_script() {
194                 byte[] ret = bindings.SignerProvider_get_destination_script(this.ptr);
195                 Reference.reachabilityFence(this);
196                 return ret;
197         }
198
199         /**
200          * Get a script pubkey which we will send funds to when closing a channel.
201          * 
202          * This method should return a different value each time it is called, to avoid linking
203          * on-chain funds across channels as controlled to the same user.
204          */
205         public ShutdownScript get_shutdown_scriptpubkey() {
206                 long ret = bindings.SignerProvider_get_shutdown_scriptpubkey(this.ptr);
207                 Reference.reachabilityFence(this);
208                 if (ret >= 0 && ret <= 4096) { return null; }
209                 org.ldk.structs.ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ShutdownScript(null, ret); }
210                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
211                 return ret_hu_conv;
212         }
213
214 }