Merge pull request #33 from TheBlueMatt/main
[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 javax.annotation.Nullable;
8
9
10 /**
11  * Top-level config which holds ChannelHandshakeLimits and ChannelConfig.
12  * 
13  * Default::default() provides sane defaults for most configurations
14  * (but currently with 0 relay fees!)
15  */
16 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
17 public class UserConfig extends CommonBase {
18         UserConfig(Object _dummy, long ptr) { super(ptr); }
19         @Override @SuppressWarnings("deprecation")
20         protected void finalize() throws Throwable {
21                 super.finalize();
22                 if (ptr != 0) { bindings.UserConfig_free(ptr); }
23         }
24
25         /**
26          * Channel config that we propose to our counterparty.
27          */
28         public ChannelHandshakeConfig get_own_channel_config() {
29                 long ret = bindings.UserConfig_get_own_channel_config(this.ptr);
30                 if (ret < 1024) { return null; }
31                 ChannelHandshakeConfig ret_hu_conv = new ChannelHandshakeConfig(null, ret);
32                 ret_hu_conv.ptrs_to.add(this);
33                 return ret_hu_conv;
34         }
35
36         /**
37          * Channel config that we propose to our counterparty.
38          */
39         public void set_own_channel_config(ChannelHandshakeConfig val) {
40                 bindings.UserConfig_set_own_channel_config(this.ptr, val == null ? 0 : val.ptr & ~1);
41                 this.ptrs_to.add(val);
42         }
43
44         /**
45          * Limits applied to our counterparty's proposed channel config settings.
46          */
47         public ChannelHandshakeLimits get_peer_channel_config_limits() {
48                 long ret = bindings.UserConfig_get_peer_channel_config_limits(this.ptr);
49                 if (ret < 1024) { return null; }
50                 ChannelHandshakeLimits ret_hu_conv = new ChannelHandshakeLimits(null, ret);
51                 ret_hu_conv.ptrs_to.add(this);
52                 return ret_hu_conv;
53         }
54
55         /**
56          * Limits applied to our counterparty's proposed channel config settings.
57          */
58         public void set_peer_channel_config_limits(ChannelHandshakeLimits val) {
59                 bindings.UserConfig_set_peer_channel_config_limits(this.ptr, val == null ? 0 : val.ptr & ~1);
60                 this.ptrs_to.add(val);
61         }
62
63         /**
64          * Channel config which affects behavior during channel lifetime.
65          */
66         public ChannelConfig get_channel_options() {
67                 long ret = bindings.UserConfig_get_channel_options(this.ptr);
68                 if (ret < 1024) { return null; }
69                 ChannelConfig ret_hu_conv = new ChannelConfig(null, ret);
70                 ret_hu_conv.ptrs_to.add(this);
71                 return ret_hu_conv;
72         }
73
74         /**
75          * Channel config which affects behavior during channel lifetime.
76          */
77         public void set_channel_options(ChannelConfig val) {
78                 bindings.UserConfig_set_channel_options(this.ptr, val == null ? 0 : val.ptr & ~1);
79                 this.ptrs_to.add(val);
80         }
81
82         /**
83          * If this is set to false, we will reject any HTLCs which were to be forwarded over private
84          * channels. This prevents us from taking on HTLC-forwarding risk when we intend to run as a
85          * node which is not online reliably.
86          * 
87          * For nodes which are not online reliably, you should set all channels to *not* be announced
88          * (using [`ChannelConfig::announced_channel`] and
89          * [`ChannelHandshakeLimits::force_announced_channel_preference`]) and set this to false to
90          * ensure you are not exposed to any forwarding risk.
91          * 
92          * Note that because you cannot change a channel's announced state after creation, there is no
93          * way to disable forwarding on public channels retroactively. Thus, in order to change a node
94          * from a publicly-announced forwarding node to a private non-forwarding node you must close
95          * all your channels and open new ones. For privacy, you should also change your node_id
96          * (swapping all private and public key material for new ones) at that time.
97          * 
98          * Default value: false.
99          */
100         public boolean get_accept_forwards_to_priv_channels() {
101                 boolean ret = bindings.UserConfig_get_accept_forwards_to_priv_channels(this.ptr);
102                 return ret;
103         }
104
105         /**
106          * If this is set to false, we will reject any HTLCs which were to be forwarded over private
107          * channels. This prevents us from taking on HTLC-forwarding risk when we intend to run as a
108          * node which is not online reliably.
109          * 
110          * For nodes which are not online reliably, you should set all channels to *not* be announced
111          * (using [`ChannelConfig::announced_channel`] and
112          * [`ChannelHandshakeLimits::force_announced_channel_preference`]) and set this to false to
113          * ensure you are not exposed to any forwarding risk.
114          * 
115          * Note that because you cannot change a channel's announced state after creation, there is no
116          * way to disable forwarding on public channels retroactively. Thus, in order to change a node
117          * from a publicly-announced forwarding node to a private non-forwarding node you must close
118          * all your channels and open new ones. For privacy, you should also change your node_id
119          * (swapping all private and public key material for new ones) at that time.
120          * 
121          * Default value: false.
122          */
123         public void set_accept_forwards_to_priv_channels(boolean val) {
124                 bindings.UserConfig_set_accept_forwards_to_priv_channels(this.ptr, val);
125         }
126
127         /**
128          * Constructs a new UserConfig given each field
129          */
130         public static UserConfig of(ChannelHandshakeConfig own_channel_config_arg, ChannelHandshakeLimits peer_channel_config_limits_arg, ChannelConfig channel_options_arg, boolean accept_forwards_to_priv_channels_arg) {
131                 long ret = bindings.UserConfig_new(own_channel_config_arg == null ? 0 : own_channel_config_arg.ptr & ~1, peer_channel_config_limits_arg == null ? 0 : peer_channel_config_limits_arg.ptr & ~1, channel_options_arg == null ? 0 : channel_options_arg.ptr & ~1, accept_forwards_to_priv_channels_arg);
132                 if (ret < 1024) { return null; }
133                 UserConfig ret_hu_conv = new UserConfig(null, ret);
134                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
135                 ret_hu_conv.ptrs_to.add(own_channel_config_arg);
136                 ret_hu_conv.ptrs_to.add(peer_channel_config_limits_arg);
137                 ret_hu_conv.ptrs_to.add(channel_options_arg);
138                 return ret_hu_conv;
139         }
140
141         /**
142          * Creates a copy of the UserConfig
143          */
144         public UserConfig clone() {
145                 long ret = bindings.UserConfig_clone(this.ptr);
146                 if (ret < 1024) { return null; }
147                 UserConfig ret_hu_conv = new UserConfig(null, ret);
148                 ret_hu_conv.ptrs_to.add(this);
149                 return ret_hu_conv;
150         }
151
152         /**
153          * Creates a "default" UserConfig. See struct and individual field documentaiton for details on which values are used.
154          */
155         public static UserConfig with_default() {
156                 long ret = bindings.UserConfig_default();
157                 if (ret < 1024) { return null; }
158                 UserConfig ret_hu_conv = new UserConfig(null, ret);
159                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
160                 return ret_hu_conv;
161         }
162
163 }