82b995792a6aad588ff985b57ef25f57265ffc32
[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 javax.annotation.Nullable;
8
9
10 /**
11  * [`routing::Score`] implementation that provides reasonable default behavior.
12  * 
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.
15  * 
16  * See [module-level documentation] for usage.
17  * 
18  * [module-level documentation]: crate::routing::scorer
19  */
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 {
25                 super.finalize();
26                 if (ptr != 0) { bindings.Scorer_free(ptr); }
27         }
28
29         /**
30          * Creates a new scorer using the given scoring parameters.
31          */
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);
37                 return ret_hu_conv;
38         }
39
40         /**
41          * Creates a "default" Scorer. See struct and individual field documentaiton for details on which values are used.
42          */
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);
48                 return ret_hu_conv;
49         }
50
51         /**
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
54          */
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);
60                 return ret_hu_conv;
61         }
62
63         /**
64          * Serialize the Scorer object into a byte array which can be read by Scorer_read
65          */
66         public byte[] write() {
67                 byte[] ret = bindings.Scorer_write(this.ptr);
68                 return ret;
69         }
70
71         /**
72          * Read a Scorer from a byte array, created by Scorer_write
73          */
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);
78                 return ret_hu_conv;
79         }
80
81 }