5a96eeaabba017cf4431254d514982dc3046819e
[ldk-java] / src / main / java / org / ldk / structs / UserConfig.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 /**
12  * Top-level config which holds ChannelHandshakeLimits and ChannelConfig.
13  * 
14  * Default::default() provides sane defaults for most configurations
15  * (but currently with 0 relay fees!)
16  */
17 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
18 public class UserConfig extends CommonBase {
19         UserConfig(Object _dummy, long ptr) { super(ptr); }
20         @Override @SuppressWarnings("deprecation")
21         protected void finalize() throws Throwable {
22                 super.finalize();
23                 if (ptr != 0) { bindings.UserConfig_free(ptr); }
24         }
25
26         /**
27          * Channel handshake config that we propose to our counterparty.
28          */
29         public ChannelHandshakeConfig get_channel_handshake_config() {
30                 long ret = bindings.UserConfig_get_channel_handshake_config(this.ptr);
31                 Reference.reachabilityFence(this);
32                 if (ret >= 0 && ret <= 4096) { return null; }
33                 org.ldk.structs.ChannelHandshakeConfig ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelHandshakeConfig(null, ret); }
34                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
35                 return ret_hu_conv;
36         }
37
38         /**
39          * Channel handshake config that we propose to our counterparty.
40          */
41         public void set_channel_handshake_config(org.ldk.structs.ChannelHandshakeConfig val) {
42                 bindings.UserConfig_set_channel_handshake_config(this.ptr, val == null ? 0 : val.ptr);
43                 Reference.reachabilityFence(this);
44                 Reference.reachabilityFence(val);
45                 if (this != null) { this.ptrs_to.add(val); };
46         }
47
48         /**
49          * Limits applied to our counterparty's proposed channel handshake config settings.
50          */
51         public ChannelHandshakeLimits get_channel_handshake_limits() {
52                 long ret = bindings.UserConfig_get_channel_handshake_limits(this.ptr);
53                 Reference.reachabilityFence(this);
54                 if (ret >= 0 && ret <= 4096) { return null; }
55                 org.ldk.structs.ChannelHandshakeLimits ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelHandshakeLimits(null, ret); }
56                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
57                 return ret_hu_conv;
58         }
59
60         /**
61          * Limits applied to our counterparty's proposed channel handshake config settings.
62          */
63         public void set_channel_handshake_limits(org.ldk.structs.ChannelHandshakeLimits val) {
64                 bindings.UserConfig_set_channel_handshake_limits(this.ptr, val == null ? 0 : val.ptr);
65                 Reference.reachabilityFence(this);
66                 Reference.reachabilityFence(val);
67                 if (this != null) { this.ptrs_to.add(val); };
68         }
69
70         /**
71          * Channel config which affects behavior during channel lifetime.
72          */
73         public ChannelConfig get_channel_config() {
74                 long ret = bindings.UserConfig_get_channel_config(this.ptr);
75                 Reference.reachabilityFence(this);
76                 if (ret >= 0 && ret <= 4096) { return null; }
77                 org.ldk.structs.ChannelConfig ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelConfig(null, ret); }
78                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
79                 return ret_hu_conv;
80         }
81
82         /**
83          * Channel config which affects behavior during channel lifetime.
84          */
85         public void set_channel_config(org.ldk.structs.ChannelConfig val) {
86                 bindings.UserConfig_set_channel_config(this.ptr, val == null ? 0 : val.ptr);
87                 Reference.reachabilityFence(this);
88                 Reference.reachabilityFence(val);
89                 if (this != null) { this.ptrs_to.add(val); };
90         }
91
92         /**
93          * If this is set to false, we will reject any HTLCs which were to be forwarded over private
94          * channels. This prevents us from taking on HTLC-forwarding risk when we intend to run as a
95          * node which is not online reliably.
96          * 
97          * For nodes which are not online reliably, you should set all channels to *not* be announced
98          * (using [`ChannelHandshakeConfig::announced_channel`] and
99          * [`ChannelHandshakeLimits::force_announced_channel_preference`]) and set this to false to
100          * ensure you are not exposed to any forwarding risk.
101          * 
102          * Note that because you cannot change a channel's announced state after creation, there is no
103          * way to disable forwarding on public channels retroactively. Thus, in order to change a node
104          * from a publicly-announced forwarding node to a private non-forwarding node you must close
105          * all your channels and open new ones. For privacy, you should also change your node_id
106          * (swapping all private and public key material for new ones) at that time.
107          * 
108          * Default value: false.
109          */
110         public boolean get_accept_forwards_to_priv_channels() {
111                 boolean ret = bindings.UserConfig_get_accept_forwards_to_priv_channels(this.ptr);
112                 Reference.reachabilityFence(this);
113                 return ret;
114         }
115
116         /**
117          * If this is set to false, we will reject any HTLCs which were to be forwarded over private
118          * channels. This prevents us from taking on HTLC-forwarding risk when we intend to run as a
119          * node which is not online reliably.
120          * 
121          * For nodes which are not online reliably, you should set all channels to *not* be announced
122          * (using [`ChannelHandshakeConfig::announced_channel`] and
123          * [`ChannelHandshakeLimits::force_announced_channel_preference`]) and set this to false to
124          * ensure you are not exposed to any forwarding risk.
125          * 
126          * Note that because you cannot change a channel's announced state after creation, there is no
127          * way to disable forwarding on public channels retroactively. Thus, in order to change a node
128          * from a publicly-announced forwarding node to a private non-forwarding node you must close
129          * all your channels and open new ones. For privacy, you should also change your node_id
130          * (swapping all private and public key material for new ones) at that time.
131          * 
132          * Default value: false.
133          */
134         public void set_accept_forwards_to_priv_channels(boolean val) {
135                 bindings.UserConfig_set_accept_forwards_to_priv_channels(this.ptr, val);
136                 Reference.reachabilityFence(this);
137                 Reference.reachabilityFence(val);
138         }
139
140         /**
141          * If this is set to false, we do not accept inbound requests to open a new channel.
142          * Default value: true.
143          */
144         public boolean get_accept_inbound_channels() {
145                 boolean ret = bindings.UserConfig_get_accept_inbound_channels(this.ptr);
146                 Reference.reachabilityFence(this);
147                 return ret;
148         }
149
150         /**
151          * If this is set to false, we do not accept inbound requests to open a new channel.
152          * Default value: true.
153          */
154         public void set_accept_inbound_channels(boolean val) {
155                 bindings.UserConfig_set_accept_inbound_channels(this.ptr, val);
156                 Reference.reachabilityFence(this);
157                 Reference.reachabilityFence(val);
158         }
159
160         /**
161          * If this is set to true, the user needs to manually accept inbound requests to open a new
162          * channel.
163          * 
164          * When set to true, [`Event::OpenChannelRequest`] will be triggered once a request to open a
165          * new inbound channel is received through a [`msgs::OpenChannel`] message. In that case, a
166          * [`msgs::AcceptChannel`] message will not be sent back to the counterparty node unless the
167          * user explicitly chooses to accept the request.
168          * 
169          * Default value: false.
170          * 
171          * [`Event::OpenChannelRequest`]: crate::events::Event::OpenChannelRequest
172          * [`msgs::OpenChannel`]: crate::ln::msgs::OpenChannel
173          * [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
174          */
175         public boolean get_manually_accept_inbound_channels() {
176                 boolean ret = bindings.UserConfig_get_manually_accept_inbound_channels(this.ptr);
177                 Reference.reachabilityFence(this);
178                 return ret;
179         }
180
181         /**
182          * If this is set to true, the user needs to manually accept inbound requests to open a new
183          * channel.
184          * 
185          * When set to true, [`Event::OpenChannelRequest`] will be triggered once a request to open a
186          * new inbound channel is received through a [`msgs::OpenChannel`] message. In that case, a
187          * [`msgs::AcceptChannel`] message will not be sent back to the counterparty node unless the
188          * user explicitly chooses to accept the request.
189          * 
190          * Default value: false.
191          * 
192          * [`Event::OpenChannelRequest`]: crate::events::Event::OpenChannelRequest
193          * [`msgs::OpenChannel`]: crate::ln::msgs::OpenChannel
194          * [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
195          */
196         public void set_manually_accept_inbound_channels(boolean val) {
197                 bindings.UserConfig_set_manually_accept_inbound_channels(this.ptr, val);
198                 Reference.reachabilityFence(this);
199                 Reference.reachabilityFence(val);
200         }
201
202         /**
203          * If this is set to true, LDK will intercept HTLCs that are attempting to be forwarded over
204          * fake short channel ids generated via [`ChannelManager::get_intercept_scid`]. Upon HTLC
205          * intercept, LDK will generate an [`Event::HTLCIntercepted`] which MUST be handled by the user.
206          * 
207          * Setting this to true may break backwards compatibility with LDK versions < 0.0.113.
208          * 
209          * Default value: false.
210          * 
211          * [`ChannelManager::get_intercept_scid`]: crate::ln::channelmanager::ChannelManager::get_intercept_scid
212          * [`Event::HTLCIntercepted`]: crate::events::Event::HTLCIntercepted
213          */
214         public boolean get_accept_intercept_htlcs() {
215                 boolean ret = bindings.UserConfig_get_accept_intercept_htlcs(this.ptr);
216                 Reference.reachabilityFence(this);
217                 return ret;
218         }
219
220         /**
221          * If this is set to true, LDK will intercept HTLCs that are attempting to be forwarded over
222          * fake short channel ids generated via [`ChannelManager::get_intercept_scid`]. Upon HTLC
223          * intercept, LDK will generate an [`Event::HTLCIntercepted`] which MUST be handled by the user.
224          * 
225          * Setting this to true may break backwards compatibility with LDK versions < 0.0.113.
226          * 
227          * Default value: false.
228          * 
229          * [`ChannelManager::get_intercept_scid`]: crate::ln::channelmanager::ChannelManager::get_intercept_scid
230          * [`Event::HTLCIntercepted`]: crate::events::Event::HTLCIntercepted
231          */
232         public void set_accept_intercept_htlcs(boolean val) {
233                 bindings.UserConfig_set_accept_intercept_htlcs(this.ptr, val);
234                 Reference.reachabilityFence(this);
235                 Reference.reachabilityFence(val);
236         }
237
238         /**
239          * Constructs a new UserConfig given each field
240          */
241         public static UserConfig of(org.ldk.structs.ChannelHandshakeConfig channel_handshake_config_arg, org.ldk.structs.ChannelHandshakeLimits channel_handshake_limits_arg, org.ldk.structs.ChannelConfig channel_config_arg, boolean accept_forwards_to_priv_channels_arg, boolean accept_inbound_channels_arg, boolean manually_accept_inbound_channels_arg, boolean accept_intercept_htlcs_arg) {
242                 long ret = bindings.UserConfig_new(channel_handshake_config_arg == null ? 0 : channel_handshake_config_arg.ptr, channel_handshake_limits_arg == null ? 0 : channel_handshake_limits_arg.ptr, channel_config_arg == null ? 0 : channel_config_arg.ptr, accept_forwards_to_priv_channels_arg, accept_inbound_channels_arg, manually_accept_inbound_channels_arg, accept_intercept_htlcs_arg);
243                 Reference.reachabilityFence(channel_handshake_config_arg);
244                 Reference.reachabilityFence(channel_handshake_limits_arg);
245                 Reference.reachabilityFence(channel_config_arg);
246                 Reference.reachabilityFence(accept_forwards_to_priv_channels_arg);
247                 Reference.reachabilityFence(accept_inbound_channels_arg);
248                 Reference.reachabilityFence(manually_accept_inbound_channels_arg);
249                 Reference.reachabilityFence(accept_intercept_htlcs_arg);
250                 if (ret >= 0 && ret <= 4096) { return null; }
251                 org.ldk.structs.UserConfig ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.UserConfig(null, ret); }
252                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
253                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channel_handshake_config_arg); };
254                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channel_handshake_limits_arg); };
255                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channel_config_arg); };
256                 return ret_hu_conv;
257         }
258
259         long clone_ptr() {
260                 long ret = bindings.UserConfig_clone_ptr(this.ptr);
261                 Reference.reachabilityFence(this);
262                 return ret;
263         }
264
265         /**
266          * Creates a copy of the UserConfig
267          */
268         public UserConfig clone() {
269                 long ret = bindings.UserConfig_clone(this.ptr);
270                 Reference.reachabilityFence(this);
271                 if (ret >= 0 && ret <= 4096) { return null; }
272                 org.ldk.structs.UserConfig ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.UserConfig(null, ret); }
273                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
274                 return ret_hu_conv;
275         }
276
277         /**
278          * Creates a "default" UserConfig. See struct and individual field documentaiton for details on which values are used.
279          */
280         public static UserConfig with_default() {
281                 long ret = bindings.UserConfig_default();
282                 if (ret >= 0 && ret <= 4096) { return null; }
283                 org.ldk.structs.UserConfig ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.UserConfig(null, ret); }
284                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
285                 return ret_hu_conv;
286         }
287
288 }