Merge pull request #33 from TheBlueMatt/main
[ldk-java] / src / main / java / org / ldk / structs / ChannelConfig.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  * Options which apply on a per-channel basis and may change at runtime or based on negotiation
12  * with our counterparty.
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class ChannelConfig extends CommonBase {
16         ChannelConfig(Object _dummy, long ptr) { super(ptr); }
17         @Override @SuppressWarnings("deprecation")
18         protected void finalize() throws Throwable {
19                 super.finalize();
20                 if (ptr != 0) { bindings.ChannelConfig_free(ptr); }
21         }
22
23         /**
24          * Amount (in millionths of a satoshi) charged per satoshi for payments forwarded outbound
25          * over the channel.
26          * This may be allowed to change at runtime in a later update, however doing so must result in
27          * update messages sent to notify all nodes of our updated relay fee.
28          * 
29          * Default value: 0.
30          */
31         public int get_forwarding_fee_proportional_millionths() {
32                 int ret = bindings.ChannelConfig_get_forwarding_fee_proportional_millionths(this.ptr);
33                 return ret;
34         }
35
36         /**
37          * Amount (in millionths of a satoshi) charged per satoshi for payments forwarded outbound
38          * over the channel.
39          * This may be allowed to change at runtime in a later update, however doing so must result in
40          * update messages sent to notify all nodes of our updated relay fee.
41          * 
42          * Default value: 0.
43          */
44         public void set_forwarding_fee_proportional_millionths(int val) {
45                 bindings.ChannelConfig_set_forwarding_fee_proportional_millionths(this.ptr, val);
46         }
47
48         /**
49          * Amount (in milli-satoshi) charged for payments forwarded outbound over the channel, in
50          * excess of [`forwarding_fee_proportional_millionths`].
51          * This may be allowed to change at runtime in a later update, however doing so must result in
52          * update messages sent to notify all nodes of our updated relay fee.
53          * 
54          * The default value of a single satoshi roughly matches the market rate on many routing nodes
55          * as of July 2021. Adjusting it upwards or downwards may change whether nodes route through
56          * this node.
57          * 
58          * Default value: 1000.
59          * 
60          * [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
61          */
62         public int get_forwarding_fee_base_msat() {
63                 int ret = bindings.ChannelConfig_get_forwarding_fee_base_msat(this.ptr);
64                 return ret;
65         }
66
67         /**
68          * Amount (in milli-satoshi) charged for payments forwarded outbound over the channel, in
69          * excess of [`forwarding_fee_proportional_millionths`].
70          * This may be allowed to change at runtime in a later update, however doing so must result in
71          * update messages sent to notify all nodes of our updated relay fee.
72          * 
73          * The default value of a single satoshi roughly matches the market rate on many routing nodes
74          * as of July 2021. Adjusting it upwards or downwards may change whether nodes route through
75          * this node.
76          * 
77          * Default value: 1000.
78          * 
79          * [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
80          */
81         public void set_forwarding_fee_base_msat(int val) {
82                 bindings.ChannelConfig_set_forwarding_fee_base_msat(this.ptr, val);
83         }
84
85         /**
86          * The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
87          * the channel this config applies to.
88          * 
89          * This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight
90          * HTLC balance when a channel appears on-chain whereas
91          * [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining
92          * (non-HTLC-encumbered) balance.
93          * 
94          * Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed,
95          * we (or one of our watchtowers) MUST be online to check for broadcast of the current
96          * commitment transaction at least once per this many blocks (minus some margin to allow us
97          * enough time to broadcast and confirm a transaction, possibly with time in between to RBF
98          * the spending transaction).
99          * 
100          * Default value: 72 (12 hours at an average of 6 blocks/hour).
101          * Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as
102          * [`MIN_CLTV_EXPIRY_DELTA`] instead.
103          * 
104          * [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA
105          */
106         public short get_cltv_expiry_delta() {
107                 short ret = bindings.ChannelConfig_get_cltv_expiry_delta(this.ptr);
108                 return ret;
109         }
110
111         /**
112          * The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
113          * the channel this config applies to.
114          * 
115          * This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight
116          * HTLC balance when a channel appears on-chain whereas
117          * [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining
118          * (non-HTLC-encumbered) balance.
119          * 
120          * Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed,
121          * we (or one of our watchtowers) MUST be online to check for broadcast of the current
122          * commitment transaction at least once per this many blocks (minus some margin to allow us
123          * enough time to broadcast and confirm a transaction, possibly with time in between to RBF
124          * the spending transaction).
125          * 
126          * Default value: 72 (12 hours at an average of 6 blocks/hour).
127          * Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as
128          * [`MIN_CLTV_EXPIRY_DELTA`] instead.
129          * 
130          * [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA
131          */
132         public void set_cltv_expiry_delta(short val) {
133                 bindings.ChannelConfig_set_cltv_expiry_delta(this.ptr, val);
134         }
135
136         /**
137          * Set to announce the channel publicly and notify all nodes that they can route via this
138          * channel.
139          * 
140          * This should only be set to true for nodes which expect to be online reliably.
141          * 
142          * As the node which funds a channel picks this value this will only apply for new outbound
143          * channels unless [`ChannelHandshakeLimits::force_announced_channel_preference`] is set.
144          * 
145          * This cannot be changed after the initial channel handshake.
146          * 
147          * Default value: false.
148          */
149         public boolean get_announced_channel() {
150                 boolean ret = bindings.ChannelConfig_get_announced_channel(this.ptr);
151                 return ret;
152         }
153
154         /**
155          * Set to announce the channel publicly and notify all nodes that they can route via this
156          * channel.
157          * 
158          * This should only be set to true for nodes which expect to be online reliably.
159          * 
160          * As the node which funds a channel picks this value this will only apply for new outbound
161          * channels unless [`ChannelHandshakeLimits::force_announced_channel_preference`] is set.
162          * 
163          * This cannot be changed after the initial channel handshake.
164          * 
165          * Default value: false.
166          */
167         public void set_announced_channel(boolean val) {
168                 bindings.ChannelConfig_set_announced_channel(this.ptr, val);
169         }
170
171         /**
172          * When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
173          * supports it, they will then enforce the mutual-close output to us matches what we provided
174          * at intialization, preventing us from closing to an alternate pubkey.
175          * 
176          * This is set to true by default to provide a slight increase in security, though ultimately
177          * any attacker who is able to take control of a channel can just as easily send the funds via
178          * lightning payments, so we never require that our counterparties support this option.
179          * 
180          * This cannot be changed after a channel has been initialized.
181          * 
182          * Default value: true.
183          */
184         public boolean get_commit_upfront_shutdown_pubkey() {
185                 boolean ret = bindings.ChannelConfig_get_commit_upfront_shutdown_pubkey(this.ptr);
186                 return ret;
187         }
188
189         /**
190          * When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
191          * supports it, they will then enforce the mutual-close output to us matches what we provided
192          * at intialization, preventing us from closing to an alternate pubkey.
193          * 
194          * This is set to true by default to provide a slight increase in security, though ultimately
195          * any attacker who is able to take control of a channel can just as easily send the funds via
196          * lightning payments, so we never require that our counterparties support this option.
197          * 
198          * This cannot be changed after a channel has been initialized.
199          * 
200          * Default value: true.
201          */
202         public void set_commit_upfront_shutdown_pubkey(boolean val) {
203                 bindings.ChannelConfig_set_commit_upfront_shutdown_pubkey(this.ptr, val);
204         }
205
206         /**
207          * Constructs a new ChannelConfig given each field
208          */
209         public static ChannelConfig of(int forwarding_fee_proportional_millionths_arg, int forwarding_fee_base_msat_arg, short cltv_expiry_delta_arg, boolean announced_channel_arg, boolean commit_upfront_shutdown_pubkey_arg) {
210                 long ret = bindings.ChannelConfig_new(forwarding_fee_proportional_millionths_arg, forwarding_fee_base_msat_arg, cltv_expiry_delta_arg, announced_channel_arg, commit_upfront_shutdown_pubkey_arg);
211                 if (ret < 1024) { return null; }
212                 ChannelConfig ret_hu_conv = new ChannelConfig(null, ret);
213                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
214                 return ret_hu_conv;
215         }
216
217         /**
218          * Creates a copy of the ChannelConfig
219          */
220         public ChannelConfig clone() {
221                 long ret = bindings.ChannelConfig_clone(this.ptr);
222                 if (ret < 1024) { return null; }
223                 ChannelConfig ret_hu_conv = new ChannelConfig(null, ret);
224                 ret_hu_conv.ptrs_to.add(this);
225                 return ret_hu_conv;
226         }
227
228         /**
229          * Creates a "default" ChannelConfig. See struct and individual field documentaiton for details on which values are used.
230          */
231         public static ChannelConfig with_default() {
232                 long ret = bindings.ChannelConfig_default();
233                 if (ret < 1024) { return null; }
234                 ChannelConfig ret_hu_conv = new ChannelConfig(null, ret);
235                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
236                 return ret_hu_conv;
237         }
238
239         /**
240          * Serialize the ChannelConfig object into a byte array which can be read by ChannelConfig_read
241          */
242         public byte[] write() {
243                 byte[] ret = bindings.ChannelConfig_write(this.ptr);
244                 return ret;
245         }
246
247         /**
248          * Read a ChannelConfig from a byte array, created by ChannelConfig_write
249          */
250         public static Result_ChannelConfigDecodeErrorZ read(byte[] ser) {
251                 long ret = bindings.ChannelConfig_read(ser);
252                 if (ret < 1024) { return null; }
253                 Result_ChannelConfigDecodeErrorZ ret_hu_conv = Result_ChannelConfigDecodeErrorZ.constr_from_ptr(ret);
254                 return ret_hu_conv;
255         }
256
257 }