[Java] Update auto-generated bindings to 0.0.117
[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                  * If this function returns an error, this will result in a channel failing to open.
78                  * 
79                  * This method should return a different value each time it is called, to avoid linking
80                  * on-chain funds across channels as controlled to the same user.
81                  */
82                 Result_CVec_u8ZNoneZ get_destination_script();
83                 /**
84                  * Get a script pubkey which we will send funds to when closing a channel.
85                  * 
86                  * If this function returns an error, this will result in a channel failing to open or close.
87                  * In the event of a failure when the counterparty is initiating a close, this can result in a
88                  * channel force close.
89                  * 
90                  * This method should return a different value each time it is called, to avoid linking
91                  * on-chain funds across channels as controlled to the same user.
92                  */
93                 Result_ShutdownScriptNoneZ get_shutdown_scriptpubkey();
94         }
95         private static class LDKSignerProviderHolder { SignerProvider held; }
96         public static SignerProvider new_impl(SignerProviderInterface arg) {
97                 final LDKSignerProviderHolder impl_holder = new LDKSignerProviderHolder();
98                 impl_holder.held = new SignerProvider(new bindings.LDKSignerProvider() {
99                         @Override public byte[] generate_channel_keys_id(boolean inbound, long channel_value_satoshis, byte[] user_channel_id) {
100                                 org.ldk.util.UInt128 user_channel_id_conv = new org.ldk.util.UInt128(user_channel_id);
101                                 byte[] ret = arg.generate_channel_keys_id(inbound, channel_value_satoshis, user_channel_id_conv);
102                                 Reference.reachabilityFence(arg);
103                                 byte[] result = InternalUtils.check_arr_len(ret, 32);
104                                 return result;
105                         }
106                         @Override public long derive_channel_signer(long channel_value_satoshis, byte[] channel_keys_id) {
107                                 WriteableEcdsaChannelSigner ret = arg.derive_channel_signer(channel_value_satoshis, channel_keys_id);
108                                 Reference.reachabilityFence(arg);
109                                 long result = ret.clone_ptr();
110                                 if (impl_holder.held != null) { impl_holder.held.ptrs_to.add(ret); };
111                                 return result;
112                         }
113                         @Override public long read_chan_signer(byte[] reader) {
114                                 Result_WriteableEcdsaChannelSignerDecodeErrorZ ret = arg.read_chan_signer(reader);
115                                 Reference.reachabilityFence(arg);
116                                 long result = ret == null ? 0 : ret.clone_ptr();
117                                 return result;
118                         }
119                         @Override public long get_destination_script() {
120                                 Result_CVec_u8ZNoneZ ret = arg.get_destination_script();
121                                 Reference.reachabilityFence(arg);
122                                 long result = ret == null ? 0 : ret.clone_ptr();
123                                 return result;
124                         }
125                         @Override public long get_shutdown_scriptpubkey() {
126                                 Result_ShutdownScriptNoneZ ret = arg.get_shutdown_scriptpubkey();
127                                 Reference.reachabilityFence(arg);
128                                 long result = ret == null ? 0 : ret.clone_ptr();
129                                 return result;
130                         }
131                 });
132                 return impl_holder.held;
133         }
134         /**
135          * Generates a unique `channel_keys_id` that can be used to obtain a [`Self::Signer`] through
136          * [`SignerProvider::derive_channel_signer`]. The `user_channel_id` is provided to allow
137          * implementations of [`SignerProvider`] to maintain a mapping between itself and the generated
138          * `channel_keys_id`.
139          * 
140          * This method must return a different value each time it is called.
141          */
142         public byte[] generate_channel_keys_id(boolean inbound, long channel_value_satoshis, org.ldk.util.UInt128 user_channel_id) {
143                 byte[] ret = bindings.SignerProvider_generate_channel_keys_id(this.ptr, inbound, channel_value_satoshis, user_channel_id.getLEBytes());
144                 Reference.reachabilityFence(this);
145                 Reference.reachabilityFence(inbound);
146                 Reference.reachabilityFence(channel_value_satoshis);
147                 Reference.reachabilityFence(user_channel_id);
148                 return ret;
149         }
150
151         /**
152          * Derives the private key material backing a `Signer`.
153          * 
154          * To derive a new `Signer`, a fresh `channel_keys_id` should be obtained through
155          * [`SignerProvider::generate_channel_keys_id`]. Otherwise, an existing `Signer` can be
156          * re-derived from its `channel_keys_id`, which can be obtained through its trait method
157          * [`ChannelSigner::channel_keys_id`].
158          */
159         public WriteableEcdsaChannelSigner derive_channel_signer(long channel_value_satoshis, byte[] channel_keys_id) {
160                 long ret = bindings.SignerProvider_derive_channel_signer(this.ptr, channel_value_satoshis, InternalUtils.check_arr_len(channel_keys_id, 32));
161                 Reference.reachabilityFence(this);
162                 Reference.reachabilityFence(channel_value_satoshis);
163                 Reference.reachabilityFence(channel_keys_id);
164                 if (ret >= 0 && ret <= 4096) { return null; }
165                 WriteableEcdsaChannelSigner ret_hu_conv = new WriteableEcdsaChannelSigner(null, ret);
166                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
167                 return ret_hu_conv;
168         }
169
170         /**
171          * Reads a [`Signer`] for this [`SignerProvider`] from the given input stream.
172          * This is only called during deserialization of other objects which contain
173          * [`WriteableEcdsaChannelSigner`]-implementing objects (i.e., [`ChannelMonitor`]s and [`ChannelManager`]s).
174          * The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
175          * contain no versioning scheme. You may wish to include your own version prefix and ensure
176          * you've read all of the provided bytes to ensure no corruption occurred.
177          * 
178          * This method is slowly being phased out -- it will only be called when reading objects
179          * written by LDK versions prior to 0.0.113.
180          * 
181          * [`Signer`]: Self::Signer
182          * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
183          * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
184          */
185         public Result_WriteableEcdsaChannelSignerDecodeErrorZ read_chan_signer(byte[] reader) {
186                 long ret = bindings.SignerProvider_read_chan_signer(this.ptr, reader);
187                 Reference.reachabilityFence(this);
188                 Reference.reachabilityFence(reader);
189                 if (ret >= 0 && ret <= 4096) { return null; }
190                 Result_WriteableEcdsaChannelSignerDecodeErrorZ ret_hu_conv = Result_WriteableEcdsaChannelSignerDecodeErrorZ.constr_from_ptr(ret);
191                 return ret_hu_conv;
192         }
193
194         /**
195          * Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
196          * 
197          * If this function returns an error, this will result in a channel failing to open.
198          * 
199          * This method should return a different value each time it is called, to avoid linking
200          * on-chain funds across channels as controlled to the same user.
201          */
202         public Result_CVec_u8ZNoneZ get_destination_script() {
203                 long ret = bindings.SignerProvider_get_destination_script(this.ptr);
204                 Reference.reachabilityFence(this);
205                 if (ret >= 0 && ret <= 4096) { return null; }
206                 Result_CVec_u8ZNoneZ ret_hu_conv = Result_CVec_u8ZNoneZ.constr_from_ptr(ret);
207                 return ret_hu_conv;
208         }
209
210         /**
211          * Get a script pubkey which we will send funds to when closing a channel.
212          * 
213          * If this function returns an error, this will result in a channel failing to open or close.
214          * In the event of a failure when the counterparty is initiating a close, this can result in a
215          * channel force close.
216          * 
217          * This method should return a different value each time it is called, to avoid linking
218          * on-chain funds across channels as controlled to the same user.
219          */
220         public Result_ShutdownScriptNoneZ get_shutdown_scriptpubkey() {
221                 long ret = bindings.SignerProvider_get_shutdown_scriptpubkey(this.ptr);
222                 Reference.reachabilityFence(this);
223                 if (ret >= 0 && ret <= 4096) { return null; }
224                 Result_ShutdownScriptNoneZ ret_hu_conv = Result_ShutdownScriptNoneZ.constr_from_ptr(ret);
225                 return ret_hu_conv;
226         }
227
228 }