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 * [`Score`] implementation that provides reasonable default behavior.
14 * Used to apply a fixed penalty to each channel, thus avoiding long paths when shorter paths with
15 * slightly higher fees are available. Will further penalize channels that fail to relay payments.
17 * See [module-level documentation] for usage.
19 * [module-level documentation]: crate::routing::scoring
21 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
22 public class Scorer extends CommonBase {
23 Scorer(Object _dummy, long ptr) { super(ptr); }
24 @Override @SuppressWarnings("deprecation")
25 protected void finalize() throws Throwable {
27 if (ptr != 0) { bindings.Scorer_free(ptr); }
31 * Creates a new scorer using the given scoring parameters.
33 public static Scorer of(long params_base_penalty_msat_arg, long params_failure_penalty_msat_arg, short params_overuse_penalty_start_1024th_arg, long params_overuse_penalty_msat_per_1024th_arg, long params_failure_penalty_half_life_arg) {
34 long ret = bindings.Scorer_new(bindings.ScoringParameters_new(params_base_penalty_msat_arg, params_failure_penalty_msat_arg, params_overuse_penalty_start_1024th_arg, params_overuse_penalty_msat_per_1024th_arg, params_failure_penalty_half_life_arg));
35 Reference.reachabilityFence(params_base_penalty_msat_arg);
36 Reference.reachabilityFence(params_failure_penalty_msat_arg);
37 Reference.reachabilityFence(params_overuse_penalty_start_1024th_arg);
38 Reference.reachabilityFence(params_overuse_penalty_msat_per_1024th_arg);
39 Reference.reachabilityFence(params_failure_penalty_half_life_arg);
40 if (ret >= 0 && ret <= 4096) { return null; }
41 Scorer ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new Scorer(null, ret); }
42 ret_hu_conv.ptrs_to.add(ret_hu_conv);
47 * Creates a "default" Scorer. See struct and individual field documentaiton for details on which values are used.
49 public static Scorer with_default() {
50 long ret = bindings.Scorer_default();
51 if (ret >= 0 && ret <= 4096) { return null; }
52 Scorer ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new Scorer(null, ret); }
53 ret_hu_conv.ptrs_to.add(ret_hu_conv);
58 * Constructs a new Score which calls the relevant methods on this_arg.
59 * This copies the `inner` pointer in this_arg and thus the returned Score must be freed before this_arg is
61 public Score as_Score() {
62 long ret = bindings.Scorer_as_Score(this.ptr);
63 Reference.reachabilityFence(this);
64 if (ret >= 0 && ret <= 4096) { return null; }
65 Score ret_hu_conv = new Score(null, ret);
66 ret_hu_conv.ptrs_to.add(this);
71 * Serialize the Scorer object into a byte array which can be read by Scorer_read
73 public byte[] write() {
74 byte[] ret = bindings.Scorer_write(this.ptr);
75 Reference.reachabilityFence(this);
80 * Read a Scorer from a byte array, created by Scorer_write
82 public static Result_ScorerDecodeErrorZ read(byte[] ser) {
83 long ret = bindings.Scorer_read(ser);
84 Reference.reachabilityFence(ser);
85 if (ret >= 0 && ret <= 4096) { return null; }
86 Result_ScorerDecodeErrorZ ret_hu_conv = Result_ScorerDecodeErrorZ.constr_from_ptr(ret);