197e2ad7d1743e2734da7838b9940eb205b8caea
[ldk-java] / c_sharp / src / org / ldk / structs / ChannelConfig.cs
1 using org.ldk.impl;
2 using org.ldk.enums;
3 using org.ldk.util;
4 using System;
5
6 namespace org { namespace ldk { namespace structs {
7
8
9 /**
10  * Options which apply on a per-channel basis and may change at runtime or based on negotiation
11  * with our counterparty.
12  */
13 public class ChannelConfig : CommonBase {
14         internal ChannelConfig(object _dummy, long ptr) : base(ptr) { }
15         ~ChannelConfig() {
16                 if (ptr != 0) { bindings.ChannelConfig_free(ptr); }
17         }
18
19         /**
20          * Amount (in millionths of a satoshi) charged per satoshi for payments forwarded outbound
21          * over the channel.
22          * This may be allowed to change at runtime in a later update, however doing so must result in
23          * update messages sent to notify all nodes of our updated relay fee.
24          * 
25          * Default value: 0.
26          */
27         public int get_forwarding_fee_proportional_millionths() {
28                 int ret = bindings.ChannelConfig_get_forwarding_fee_proportional_millionths(this.ptr);
29                 GC.KeepAlive(this);
30                 return ret;
31         }
32
33         /**
34          * Amount (in millionths of a satoshi) charged per satoshi for payments forwarded outbound
35          * over the channel.
36          * This may be allowed to change at runtime in a later update, however doing so must result in
37          * update messages sent to notify all nodes of our updated relay fee.
38          * 
39          * Default value: 0.
40          */
41         public void set_forwarding_fee_proportional_millionths(int val) {
42                 bindings.ChannelConfig_set_forwarding_fee_proportional_millionths(this.ptr, val);
43                 GC.KeepAlive(this);
44                 GC.KeepAlive(val);
45         }
46
47         /**
48          * Amount (in milli-satoshi) charged for payments forwarded outbound over the channel, in
49          * excess of [`forwarding_fee_proportional_millionths`].
50          * This may be allowed to change at runtime in a later update, however doing so must result in
51          * update messages sent to notify all nodes of our updated relay fee.
52          * 
53          * The default value of a single satoshi roughly matches the market rate on many routing nodes
54          * as of July 2021. Adjusting it upwards or downwards may change whether nodes route through
55          * this node.
56          * 
57          * Default value: 1000.
58          * 
59          * [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
60          */
61         public int get_forwarding_fee_base_msat() {
62                 int ret = bindings.ChannelConfig_get_forwarding_fee_base_msat(this.ptr);
63                 GC.KeepAlive(this);
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                 GC.KeepAlive(this);
84                 GC.KeepAlive(val);
85         }
86
87         /**
88          * The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
89          * the channel this config applies to.
90          * 
91          * This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight
92          * HTLC balance when a channel appears on-chain whereas
93          * [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining
94          * (non-HTLC-encumbered) balance.
95          * 
96          * Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed,
97          * we (or one of our watchtowers) MUST be online to check for broadcast of the current
98          * commitment transaction at least once per this many blocks (minus some margin to allow us
99          * enough time to broadcast and confirm a transaction, possibly with time in between to RBF
100          * the spending transaction).
101          * 
102          * Default value: 72 (12 hours at an average of 6 blocks/hour).
103          * Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as
104          * [`MIN_CLTV_EXPIRY_DELTA`] instead.
105          * 
106          * [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA
107          */
108         public short get_cltv_expiry_delta() {
109                 short ret = bindings.ChannelConfig_get_cltv_expiry_delta(this.ptr);
110                 GC.KeepAlive(this);
111                 return ret;
112         }
113
114         /**
115          * The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
116          * the channel this config applies to.
117          * 
118          * This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight
119          * HTLC balance when a channel appears on-chain whereas
120          * [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining
121          * (non-HTLC-encumbered) balance.
122          * 
123          * Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed,
124          * we (or one of our watchtowers) MUST be online to check for broadcast of the current
125          * commitment transaction at least once per this many blocks (minus some margin to allow us
126          * enough time to broadcast and confirm a transaction, possibly with time in between to RBF
127          * the spending transaction).
128          * 
129          * Default value: 72 (12 hours at an average of 6 blocks/hour).
130          * Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as
131          * [`MIN_CLTV_EXPIRY_DELTA`] instead.
132          * 
133          * [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA
134          */
135         public void set_cltv_expiry_delta(short val) {
136                 bindings.ChannelConfig_set_cltv_expiry_delta(this.ptr, val);
137                 GC.KeepAlive(this);
138                 GC.KeepAlive(val);
139         }
140
141         /**
142          * Limit our total exposure to in-flight HTLCs which are burned to fees as they are too
143          * small to claim on-chain.
144          * 
145          * When an HTLC present in one of our channels is below a \"dust\" threshold, the HTLC will
146          * not be claimable on-chain, instead being turned into additional miner fees if either
147          * party force-closes the channel. Because the threshold is per-HTLC, our total exposure
148          * to such payments may be sustantial if there are many dust HTLCs present when the
149          * channel is force-closed.
150          * 
151          * The dust threshold for each HTLC is based on the `dust_limit_satoshis` for each party in a
152          * channel negotiated throughout the channel open process, along with the fees required to have
153          * a broadcastable HTLC spending transaction. When a channel supports anchor outputs
154          * (specifically the zero fee HTLC transaction variant), this threshold no longer takes into
155          * account the HTLC transaction fee as it is zero.
156          * 
157          * This limit is applied for sent, forwarded, and received HTLCs and limits the total
158          * exposure across all three types per-channel. Setting this too low may prevent the
159          * sending or receipt of low-value HTLCs on high-traffic nodes, and this limit is very
160          * important to prevent stealing of dust HTLCs by miners.
161          * 
162          * Default value: 5_000_000 msat.
163          */
164         public long get_max_dust_htlc_exposure_msat() {
165                 long ret = bindings.ChannelConfig_get_max_dust_htlc_exposure_msat(this.ptr);
166                 GC.KeepAlive(this);
167                 return ret;
168         }
169
170         /**
171          * Limit our total exposure to in-flight HTLCs which are burned to fees as they are too
172          * small to claim on-chain.
173          * 
174          * When an HTLC present in one of our channels is below a \"dust\" threshold, the HTLC will
175          * not be claimable on-chain, instead being turned into additional miner fees if either
176          * party force-closes the channel. Because the threshold is per-HTLC, our total exposure
177          * to such payments may be sustantial if there are many dust HTLCs present when the
178          * channel is force-closed.
179          * 
180          * The dust threshold for each HTLC is based on the `dust_limit_satoshis` for each party in a
181          * channel negotiated throughout the channel open process, along with the fees required to have
182          * a broadcastable HTLC spending transaction. When a channel supports anchor outputs
183          * (specifically the zero fee HTLC transaction variant), this threshold no longer takes into
184          * account the HTLC transaction fee as it is zero.
185          * 
186          * This limit is applied for sent, forwarded, and received HTLCs and limits the total
187          * exposure across all three types per-channel. Setting this too low may prevent the
188          * sending or receipt of low-value HTLCs on high-traffic nodes, and this limit is very
189          * important to prevent stealing of dust HTLCs by miners.
190          * 
191          * Default value: 5_000_000 msat.
192          */
193         public void set_max_dust_htlc_exposure_msat(long val) {
194                 bindings.ChannelConfig_set_max_dust_htlc_exposure_msat(this.ptr, val);
195                 GC.KeepAlive(this);
196                 GC.KeepAlive(val);
197         }
198
199         /**
200          * The additional fee we're willing to pay to avoid waiting for the counterparty's
201          * `to_self_delay` to reclaim funds.
202          * 
203          * When we close a channel cooperatively with our counterparty, we negotiate a fee for the
204          * closing transaction which both sides find acceptable, ultimately paid by the channel
205          * funder/initiator.
206          * 
207          * When we are the funder, because we have to pay the channel closing fee, we bound the
208          * acceptable fee by our [`Background`] and [`Normal`] fees, with the upper bound increased by
209          * this value. Because the on-chain fee we'd pay to force-close the channel is kept near our
210          * [`Normal`] feerate during normal operation, this value represents the additional fee we're
211          * willing to pay in order to avoid waiting for our counterparty's to_self_delay to reclaim our
212          * funds.
213          * 
214          * When we are not the funder, we require the closing transaction fee pay at least our
215          * [`Background`] fee estimate, but allow our counterparty to pay as much fee as they like.
216          * Thus, this value is ignored when we are not the funder.
217          * 
218          * Default value: 1000 satoshis.
219          * 
220          * [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
221          * [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
222          */
223         public long get_force_close_avoidance_max_fee_satoshis() {
224                 long ret = bindings.ChannelConfig_get_force_close_avoidance_max_fee_satoshis(this.ptr);
225                 GC.KeepAlive(this);
226                 return ret;
227         }
228
229         /**
230          * The additional fee we're willing to pay to avoid waiting for the counterparty's
231          * `to_self_delay` to reclaim funds.
232          * 
233          * When we close a channel cooperatively with our counterparty, we negotiate a fee for the
234          * closing transaction which both sides find acceptable, ultimately paid by the channel
235          * funder/initiator.
236          * 
237          * When we are the funder, because we have to pay the channel closing fee, we bound the
238          * acceptable fee by our [`Background`] and [`Normal`] fees, with the upper bound increased by
239          * this value. Because the on-chain fee we'd pay to force-close the channel is kept near our
240          * [`Normal`] feerate during normal operation, this value represents the additional fee we're
241          * willing to pay in order to avoid waiting for our counterparty's to_self_delay to reclaim our
242          * funds.
243          * 
244          * When we are not the funder, we require the closing transaction fee pay at least our
245          * [`Background`] fee estimate, but allow our counterparty to pay as much fee as they like.
246          * Thus, this value is ignored when we are not the funder.
247          * 
248          * Default value: 1000 satoshis.
249          * 
250          * [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
251          * [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
252          */
253         public void set_force_close_avoidance_max_fee_satoshis(long val) {
254                 bindings.ChannelConfig_set_force_close_avoidance_max_fee_satoshis(this.ptr, val);
255                 GC.KeepAlive(this);
256                 GC.KeepAlive(val);
257         }
258
259         /**
260          * Constructs a new ChannelConfig given each field
261          */
262         public static ChannelConfig of(int forwarding_fee_proportional_millionths_arg, int forwarding_fee_base_msat_arg, short cltv_expiry_delta_arg, long max_dust_htlc_exposure_msat_arg, long force_close_avoidance_max_fee_satoshis_arg) {
263                 long ret = bindings.ChannelConfig_new(forwarding_fee_proportional_millionths_arg, forwarding_fee_base_msat_arg, cltv_expiry_delta_arg, max_dust_htlc_exposure_msat_arg, force_close_avoidance_max_fee_satoshis_arg);
264                 GC.KeepAlive(forwarding_fee_proportional_millionths_arg);
265                 GC.KeepAlive(forwarding_fee_base_msat_arg);
266                 GC.KeepAlive(cltv_expiry_delta_arg);
267                 GC.KeepAlive(max_dust_htlc_exposure_msat_arg);
268                 GC.KeepAlive(force_close_avoidance_max_fee_satoshis_arg);
269                 if (ret >= 0 && ret <= 4096) { return null; }
270                 org.ldk.structs.ChannelConfig ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelConfig(null, ret); }
271                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
272                 return ret_hu_conv;
273         }
274
275         internal long clone_ptr() {
276                 long ret = bindings.ChannelConfig_clone_ptr(this.ptr);
277                 GC.KeepAlive(this);
278                 return ret;
279         }
280
281         /**
282          * Creates a copy of the ChannelConfig
283          */
284         public ChannelConfig clone() {
285                 long ret = bindings.ChannelConfig_clone(this.ptr);
286                 GC.KeepAlive(this);
287                 if (ret >= 0 && ret <= 4096) { return null; }
288                 org.ldk.structs.ChannelConfig ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelConfig(null, ret); }
289                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
290                 return ret_hu_conv;
291         }
292
293         /**
294          * Checks if two ChannelConfigs contain equal inner contents.
295          * This ignores pointers and is_owned flags and looks at the values in fields.
296          * Two objects with NULL inner values will be considered "equal" here.
297          */
298         public bool eq(org.ldk.structs.ChannelConfig b) {
299                 bool ret = bindings.ChannelConfig_eq(this.ptr, b == null ? 0 : b.ptr);
300                 GC.KeepAlive(this);
301                 GC.KeepAlive(b);
302                 if (this != null) { this.ptrs_to.AddLast(b); };
303                 return ret;
304         }
305
306         public override bool Equals(object o) {
307                 if (!(o is ChannelConfig)) return false;
308                 return this.eq((ChannelConfig)o);
309         }
310         /**
311          * Creates a "default" ChannelConfig. See struct and individual field documentaiton for details on which values are used.
312          */
313         public static ChannelConfig with_default() {
314                 long ret = bindings.ChannelConfig_default();
315                 if (ret >= 0 && ret <= 4096) { return null; }
316                 org.ldk.structs.ChannelConfig ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelConfig(null, ret); }
317                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
318                 return ret_hu_conv;
319         }
320
321         /**
322          * Serialize the ChannelConfig object into a byte array which can be read by ChannelConfig_read
323          */
324         public byte[] write() {
325                 byte[] ret = bindings.ChannelConfig_write(this.ptr);
326                 GC.KeepAlive(this);
327                 return ret;
328         }
329
330         /**
331          * Read a ChannelConfig from a byte array, created by ChannelConfig_write
332          */
333         public static Result_ChannelConfigDecodeErrorZ read(byte[] ser) {
334                 long ret = bindings.ChannelConfig_read(ser);
335                 GC.KeepAlive(ser);
336                 if (ret >= 0 && ret <= 4096) { return null; }
337                 Result_ChannelConfigDecodeErrorZ ret_hu_conv = Result_ChannelConfigDecodeErrorZ.constr_from_ptr(ret);
338                 return ret_hu_conv;
339         }
340
341 }
342 } } }