1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * Parameters for configuring [`Scorer`].
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 {
20 if (ptr != 0) { bindings.ScoringParameters_free(ptr); }
24 * A fixed penalty in msats to apply to each channel.
26 * Default value: 500 msat
28 public long get_base_penalty_msat() {
29 long ret = bindings.ScoringParameters_get_base_penalty_msat(this.ptr);
30 Reference.reachabilityFence(this);
35 * A fixed penalty in msats to apply to each channel.
37 * Default value: 500 msat
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);
46 * A penalty in msats to apply to a channel upon failing to relay a payment.
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.
51 * Default value: 1,024,000 msat
53 * [`failure_penalty_half_life`]: Self::failure_penalty_half_life
55 public long get_failure_penalty_msat() {
56 long ret = bindings.ScoringParameters_get_failure_penalty_msat(this.ptr);
57 Reference.reachabilityFence(this);
62 * A penalty in msats to apply to a channel upon failing to relay a payment.
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.
67 * Default value: 1,024,000 msat
69 * [`failure_penalty_half_life`]: Self::failure_penalty_half_life
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);
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`].
81 * Default value: 128 1024ths (i.e. begin penalizing when an HTLC uses 1/8th of a channel)
83 * [`overuse_penalty_msat_per_1024th`]: Self::overuse_penalty_msat_per_1024th
85 public short get_overuse_penalty_start_1024th() {
86 short ret = bindings.ScoringParameters_get_overuse_penalty_start_1024th(this.ptr);
87 Reference.reachabilityFence(this);
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`].
95 * Default value: 128 1024ths (i.e. begin penalizing when an HTLC uses 1/8th of a channel)
97 * [`overuse_penalty_msat_per_1024th`]: Self::overuse_penalty_msat_per_1024th
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);
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.
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)
112 * [`overuse_penalty_start_1024th`]: Self::overuse_penalty_start_1024th
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);
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.
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)
127 * [`overuse_penalty_start_1024th`]: Self::overuse_penalty_start_1024th
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);
136 * The time required to elapse before any accumulated [`failure_penalty_msat`] penalties are
139 * Successfully routing through a channel will immediately cut the penalty in half as well.
141 * Default value: 1 hour
145 * When built with the `no-std` feature, time will never elapse. Therefore, this penalty will
148 * [`failure_penalty_msat`]: Self::failure_penalty_msat
150 public long get_failure_penalty_half_life() {
151 long ret = bindings.ScoringParameters_get_failure_penalty_half_life(this.ptr);
152 Reference.reachabilityFence(this);
157 * The time required to elapse before any accumulated [`failure_penalty_msat`] penalties are
160 * Successfully routing through a channel will immediately cut the penalty in half as well.
162 * Default value: 1 hour
166 * When built with the `no-std` feature, time will never elapse. Therefore, this penalty will
169 * [`failure_penalty_msat`]: Self::failure_penalty_msat
171 public void set_failure_penalty_half_life(long val) {
172 bindings.ScoringParameters_set_failure_penalty_half_life(this.ptr, val);
173 Reference.reachabilityFence(this);
174 Reference.reachabilityFence(val);
178 * Constructs a new ScoringParameters given each field
180 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) {
181 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);
182 Reference.reachabilityFence(base_penalty_msat_arg);
183 Reference.reachabilityFence(failure_penalty_msat_arg);
184 Reference.reachabilityFence(overuse_penalty_start_1024th_arg);
185 Reference.reachabilityFence(overuse_penalty_msat_per_1024th_arg);
186 Reference.reachabilityFence(failure_penalty_half_life_arg);
187 if (ret >= 0 && ret <= 4096) { return null; }
188 ScoringParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ScoringParameters(null, ret); }
189 ret_hu_conv.ptrs_to.add(ret_hu_conv);
194 long ret = bindings.ScoringParameters_clone_ptr(this.ptr);
195 Reference.reachabilityFence(this);
200 * Creates a copy of the ScoringParameters
202 public ScoringParameters clone() {
203 long ret = bindings.ScoringParameters_clone(this.ptr);
204 Reference.reachabilityFence(this);
205 if (ret >= 0 && ret <= 4096) { return null; }
206 ScoringParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ScoringParameters(null, ret); }
207 ret_hu_conv.ptrs_to.add(this);
212 * Serialize the ScoringParameters object into a byte array which can be read by ScoringParameters_read
214 public byte[] write() {
215 byte[] ret = bindings.ScoringParameters_write(this.ptr);
216 Reference.reachabilityFence(this);
221 * Read a ScoringParameters from a byte array, created by ScoringParameters_write
223 public static Result_ScoringParametersDecodeErrorZ read(byte[] ser) {
224 long ret = bindings.ScoringParameters_read(ser);
225 Reference.reachabilityFence(ser);
226 if (ret >= 0 && ret <= 4096) { return null; }
227 Result_ScoringParametersDecodeErrorZ ret_hu_conv = Result_ScoringParametersDecodeErrorZ.constr_from_ptr(ret);
232 * Creates a "default" ScoringParameters. See struct and individual field documentaiton for details on which values are used.
234 public static ScoringParameters with_default() {
235 long ret = bindings.ScoringParameters_default();
236 if (ret >= 0 && ret <= 4096) { return null; }
237 ScoringParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ScoringParameters(null, ret); }
238 ret_hu_conv.ptrs_to.add(ret_hu_conv);