d0360a5b981b0f49bf22142dabbdf6fd4df1bf91
[ldk-java] / src / main / java / org / ldk / structs / ScoringParameters.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  * Parameters for configuring [`Scorer`].
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class ScoringParameters extends CommonBase {
16         ScoringParameters(Object _dummy, long ptr) { super(ptr); }
17         @Override @SuppressWarnings("deprecation")
18         protected void finalize() throws Throwable {
19                 super.finalize();
20                 if (ptr != 0) { bindings.ScoringParameters_free(ptr); }
21         }
22
23         /**
24          * A fixed penalty in msats to apply to each channel.
25          * 
26          * Default value: 500 msat
27          */
28         public long get_base_penalty_msat() {
29                 long ret = bindings.ScoringParameters_get_base_penalty_msat(this.ptr);
30                 Reference.reachabilityFence(this);
31                 return ret;
32         }
33
34         /**
35          * A fixed penalty in msats to apply to each channel.
36          * 
37          * Default value: 500 msat
38          */
39         public void set_base_penalty_msat(long val) {
40                 bindings.ScoringParameters_set_base_penalty_msat(this.ptr, val);
41                 Reference.reachabilityFence(this);
42                 Reference.reachabilityFence(val);
43         }
44
45         /**
46          * A penalty in msats to apply to a channel upon failing to relay a payment.
47          * 
48          * This accumulates for each failure but may be reduced over time based on
49          * [`failure_penalty_half_life`] or when successfully routing through a channel.
50          * 
51          * Default value: 1,024,000 msat
52          * 
53          * [`failure_penalty_half_life`]: Self::failure_penalty_half_life
54          */
55         public long get_failure_penalty_msat() {
56                 long ret = bindings.ScoringParameters_get_failure_penalty_msat(this.ptr);
57                 Reference.reachabilityFence(this);
58                 return ret;
59         }
60
61         /**
62          * A penalty in msats to apply to a channel upon failing to relay a payment.
63          * 
64          * This accumulates for each failure but may be reduced over time based on
65          * [`failure_penalty_half_life`] or when successfully routing through a channel.
66          * 
67          * Default value: 1,024,000 msat
68          * 
69          * [`failure_penalty_half_life`]: Self::failure_penalty_half_life
70          */
71         public void set_failure_penalty_msat(long val) {
72                 bindings.ScoringParameters_set_failure_penalty_msat(this.ptr, val);
73                 Reference.reachabilityFence(this);
74                 Reference.reachabilityFence(val);
75         }
76
77         /**
78          * When the amount being sent over a channel is this many 1024ths of the total channel
79          * capacity, we begin applying [`overuse_penalty_msat_per_1024th`].
80          * 
81          * Default value: 128 1024ths (i.e. begin penalizing when an HTLC uses 1/8th of a channel)
82          * 
83          * [`overuse_penalty_msat_per_1024th`]: Self::overuse_penalty_msat_per_1024th
84          */
85         public short get_overuse_penalty_start_1024th() {
86                 short ret = bindings.ScoringParameters_get_overuse_penalty_start_1024th(this.ptr);
87                 Reference.reachabilityFence(this);
88                 return ret;
89         }
90
91         /**
92          * When the amount being sent over a channel is this many 1024ths of the total channel
93          * capacity, we begin applying [`overuse_penalty_msat_per_1024th`].
94          * 
95          * Default value: 128 1024ths (i.e. begin penalizing when an HTLC uses 1/8th of a channel)
96          * 
97          * [`overuse_penalty_msat_per_1024th`]: Self::overuse_penalty_msat_per_1024th
98          */
99         public void set_overuse_penalty_start_1024th(short val) {
100                 bindings.ScoringParameters_set_overuse_penalty_start_1024th(this.ptr, val);
101                 Reference.reachabilityFence(this);
102                 Reference.reachabilityFence(val);
103         }
104
105         /**
106          * A penalty applied, per whole 1024ths of the channel capacity which the amount being sent
107          * over the channel exceeds [`overuse_penalty_start_1024th`] by.
108          * 
109          * Default value: 20 msat (i.e. 2560 msat penalty to use 1/4th of a channel, 7680 msat penalty
110          * to use half a channel, and 12,560 msat penalty to use 3/4ths of a channel)
111          * 
112          * [`overuse_penalty_start_1024th`]: Self::overuse_penalty_start_1024th
113          */
114         public long get_overuse_penalty_msat_per_1024th() {
115                 long ret = bindings.ScoringParameters_get_overuse_penalty_msat_per_1024th(this.ptr);
116                 Reference.reachabilityFence(this);
117                 return ret;
118         }
119
120         /**
121          * A penalty applied, per whole 1024ths of the channel capacity which the amount being sent
122          * over the channel exceeds [`overuse_penalty_start_1024th`] by.
123          * 
124          * Default value: 20 msat (i.e. 2560 msat penalty to use 1/4th of a channel, 7680 msat penalty
125          * to use half a channel, and 12,560 msat penalty to use 3/4ths of a channel)
126          * 
127          * [`overuse_penalty_start_1024th`]: Self::overuse_penalty_start_1024th
128          */
129         public void set_overuse_penalty_msat_per_1024th(long val) {
130                 bindings.ScoringParameters_set_overuse_penalty_msat_per_1024th(this.ptr, val);
131                 Reference.reachabilityFence(this);
132                 Reference.reachabilityFence(val);
133         }
134
135         /**
136          * The time required to elapse before any accumulated [`failure_penalty_msat`] penalties are
137          * cut in half.
138          * 
139          * Successfully routing through a channel will immediately cut the penalty in half as well.
140          * 
141          * # Note
142          * 
143          * When built with the `no-std` feature, time will never elapse. Therefore, this penalty will
144          * never decay.
145          * 
146          * [`failure_penalty_msat`]: Self::failure_penalty_msat
147          */
148         public long get_failure_penalty_half_life() {
149                 long ret = bindings.ScoringParameters_get_failure_penalty_half_life(this.ptr);
150                 Reference.reachabilityFence(this);
151                 return ret;
152         }
153
154         /**
155          * The time required to elapse before any accumulated [`failure_penalty_msat`] penalties are
156          * cut in half.
157          * 
158          * Successfully routing through a channel will immediately cut the penalty in half as well.
159          * 
160          * # Note
161          * 
162          * When built with the `no-std` feature, time will never elapse. Therefore, this penalty will
163          * never decay.
164          * 
165          * [`failure_penalty_msat`]: Self::failure_penalty_msat
166          */
167         public void set_failure_penalty_half_life(long val) {
168                 bindings.ScoringParameters_set_failure_penalty_half_life(this.ptr, val);
169                 Reference.reachabilityFence(this);
170                 Reference.reachabilityFence(val);
171         }
172
173         /**
174          * Constructs a new ScoringParameters given each field
175          */
176         public static ScoringParameters of(long base_penalty_msat_arg, long failure_penalty_msat_arg, short overuse_penalty_start_1024th_arg, long overuse_penalty_msat_per_1024th_arg, long failure_penalty_half_life_arg) {
177                 long ret = bindings.ScoringParameters_new(base_penalty_msat_arg, failure_penalty_msat_arg, overuse_penalty_start_1024th_arg, overuse_penalty_msat_per_1024th_arg, failure_penalty_half_life_arg);
178                 Reference.reachabilityFence(base_penalty_msat_arg);
179                 Reference.reachabilityFence(failure_penalty_msat_arg);
180                 Reference.reachabilityFence(overuse_penalty_start_1024th_arg);
181                 Reference.reachabilityFence(overuse_penalty_msat_per_1024th_arg);
182                 Reference.reachabilityFence(failure_penalty_half_life_arg);
183                 if (ret >= 0 && ret <= 4096) { return null; }
184                 ScoringParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ScoringParameters(null, ret); }
185                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
186                 return ret_hu_conv;
187         }
188
189         /**
190          * Serialize the ScoringParameters object into a byte array which can be read by ScoringParameters_read
191          */
192         public byte[] write() {
193                 byte[] ret = bindings.ScoringParameters_write(this.ptr);
194                 Reference.reachabilityFence(this);
195                 return ret;
196         }
197
198         /**
199          * Read a ScoringParameters from a byte array, created by ScoringParameters_write
200          */
201         public static Result_ScoringParametersDecodeErrorZ read(byte[] ser) {
202                 long ret = bindings.ScoringParameters_read(ser);
203                 Reference.reachabilityFence(ser);
204                 if (ret >= 0 && ret <= 4096) { return null; }
205                 Result_ScoringParametersDecodeErrorZ ret_hu_conv = Result_ScoringParametersDecodeErrorZ.constr_from_ptr(ret);
206                 return ret_hu_conv;
207         }
208
209         /**
210          * Creates a "default" ScoringParameters. See struct and individual field documentaiton for details on which values are used.
211          */
212         public static ScoringParameters with_default() {
213                 long ret = bindings.ScoringParameters_default();
214                 if (ret >= 0 && ret <= 4096) { return null; }
215                 ScoringParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ScoringParameters(null, ret); }
216                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
217                 return ret_hu_conv;
218         }
219
220 }