1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
11 * [`routing::Score`] implementation that provides reasonable default behavior.
13 * Used to apply a fixed penalty to each channel, thus avoiding long paths when shorter paths with
14 * slightly higher fees are available. Will further penalize channels that fail to relay payments.
16 * See [module-level documentation] for usage.
18 * [module-level documentation]: crate::routing::scorer
20 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
21 public class Scorer extends CommonBase {
22 Scorer(Object _dummy, long ptr) { super(ptr); }
23 @Override @SuppressWarnings("deprecation")
24 protected void finalize() throws Throwable {
26 if (ptr != 0) { bindings.Scorer_free(ptr); }
30 * Creates a new scorer using the given scoring parameters.
32 public static Scorer of(long params_base_penalty_msat_arg, long params_failure_penalty_msat_arg, long params_failure_penalty_half_life_arg) {
33 long ret = bindings.Scorer_new(bindings.ScoringParameters_new(params_base_penalty_msat_arg, params_failure_penalty_msat_arg, params_failure_penalty_half_life_arg));
34 if (ret >= 0 && ret <= 4096) { return null; }
35 Scorer ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new Scorer(null, ret); }
36 ret_hu_conv.ptrs_to.add(ret_hu_conv);
41 * Creates a "default" Scorer. See struct and individual field documentaiton for details on which values are used.
43 public static Scorer with_default() {
44 long ret = bindings.Scorer_default();
45 if (ret >= 0 && ret <= 4096) { return null; }
46 Scorer ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new Scorer(null, ret); }
47 ret_hu_conv.ptrs_to.add(ret_hu_conv);
52 * Constructs a new Score which calls the relevant methods on this_arg.
53 * This copies the `inner` pointer in this_arg and thus the returned Score must be freed before this_arg is
55 public Score as_Score() {
56 long ret = bindings.Scorer_as_Score(this.ptr);
57 if (ret >= 0 && ret <= 4096) { return null; }
58 Score ret_hu_conv = new Score(null, ret);
59 ret_hu_conv.ptrs_to.add(this);
64 * Serialize the Scorer object into a byte array which can be read by Scorer_read
66 public byte[] write() {
67 byte[] ret = bindings.Scorer_write(this.ptr);
72 * Read a Scorer from a byte array, created by Scorer_write
74 public static Result_ScorerDecodeErrorZ read(byte[] ser) {
75 long ret = bindings.Scorer_read(ser);
76 if (ret >= 0 && ret <= 4096) { return null; }
77 Result_ScorerDecodeErrorZ ret_hu_conv = Result_ScorerDecodeErrorZ.constr_from_ptr(ret);