0bd7418378233502327bea0984d106ee9e77682d
[ldk-java] / src / main / java / org / ldk / structs / Scorer.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  * [`Score`] implementation that provides reasonable default behavior.
13  * 
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.
16  * 
17  * See [module-level documentation] for usage.
18  * 
19  * [module-level documentation]: crate::routing::scoring
20  */
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 {
26                 super.finalize();
27                 if (ptr != 0) { bindings.Scorer_free(ptr); }
28         }
29
30         /**
31          * Creates a new scorer using the given scoring parameters.
32          */
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);
43                 return ret_hu_conv;
44         }
45
46         /**
47          * Creates a "default" Scorer. See struct and individual field documentaiton for details on which values are used.
48          */
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);
54                 return ret_hu_conv;
55         }
56
57         /**
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
60          */
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);
67                 return ret_hu_conv;
68         }
69
70         /**
71          * Serialize the Scorer object into a byte array which can be read by Scorer_read
72          */
73         public byte[] write() {
74                 byte[] ret = bindings.Scorer_write(this.ptr);
75                 Reference.reachabilityFence(this);
76                 return ret;
77         }
78
79         /**
80          * Read a Scorer from a byte array, created by Scorer_write
81          */
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);
87                 return ret_hu_conv;
88         }
89
90 }