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 and [`ScoringParameters`] for customization.
21 * Mixing the `no-std` feature between serialization and deserialization results in undefined
24 * [module-level documentation]: crate::routing::scoring
26 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
27 public class Scorer extends CommonBase {
28 Scorer(Object _dummy, long ptr) { super(ptr); }
29 @Override @SuppressWarnings("deprecation")
30 protected void finalize() throws Throwable {
32 if (ptr != 0) { bindings.Scorer_free(ptr); }
36 * Creates a new scorer using the given scoring parameters.
38 public static Scorer of(ScoringParameters params) {
39 long ret = bindings.Scorer_new(params == null ? 0 : params.ptr & ~1);
40 Reference.reachabilityFence(params);
41 if (ret >= 0 && ret <= 4096) { return null; }
42 Scorer ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new Scorer(null, ret); }
43 ret_hu_conv.ptrs_to.add(ret_hu_conv);
48 * Creates a "default" Scorer. See struct and individual field documentaiton for details on which values are used.
50 public static Scorer with_default() {
51 long ret = bindings.Scorer_default();
52 if (ret >= 0 && ret <= 4096) { return null; }
53 Scorer ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new Scorer(null, ret); }
54 ret_hu_conv.ptrs_to.add(ret_hu_conv);
59 * Constructs a new Score which calls the relevant methods on this_arg.
60 * This copies the `inner` pointer in this_arg and thus the returned Score must be freed before this_arg is
62 public Score as_Score() {
63 long ret = bindings.Scorer_as_Score(this.ptr);
64 Reference.reachabilityFence(this);
65 if (ret >= 0 && ret <= 4096) { return null; }
66 Score ret_hu_conv = new Score(null, ret);
67 ret_hu_conv.ptrs_to.add(this);
72 * Serialize the Scorer object into a byte array which can be read by Scorer_read
74 public byte[] write() {
75 byte[] ret = bindings.Scorer_write(this.ptr);
76 Reference.reachabilityFence(this);
81 * Read a Scorer from a byte array, created by Scorer_write
83 public static Result_ScorerDecodeErrorZ read(byte[] ser) {
84 long ret = bindings.Scorer_read(ser);
85 Reference.reachabilityFence(ser);
86 if (ret >= 0 && ret <= 4096) { return null; }
87 Result_ScorerDecodeErrorZ ret_hu_conv = Result_ScorerDecodeErrorZ.constr_from_ptr(ret);