[Java] Update auto-generated Java bindings for 0.0.108
[ldk-java] / src / main / java / org / ldk / structs / ProbabilisticScorer.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 using channel success probability distributions.
13  * 
14  * Based on *Optimally Reliable & Cheap Payment Flows on the Lightning Network* by Rene Pickhardt
15  * and Stefan Richter [[1]]. Given the uncertainty of channel liquidity balances, probability
16  * distributions are defined based on knowledge learned from successful and unsuccessful attempts.
17  * Then the negative `log10` of the success probability is used to determine the cost of routing a
18  * specific HTLC amount through a channel.
19  * 
20  * Knowledge about channel liquidity balances takes the form of upper and lower bounds on the
21  * possible liquidity. Certainty of the bounds is decreased over time using a decay function. See
22  * [`ProbabilisticScoringParameters`] for details.
23  * 
24  * Since the scorer aims to learn the current channel liquidity balances, it works best for nodes
25  * with high payment volume or that actively probe the [`NetworkGraph`]. Nodes with low payment
26  * volume are more likely to experience failed payment paths, which would need to be retried.
27  * 
28  * # Note
29  * 
30  * Mixing the `no-std` feature between serialization and deserialization results in undefined
31  * behavior.
32  * 
33  * [1]: https://arxiv.org/abs/2107.05322
34  */
35 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
36 public class ProbabilisticScorer extends CommonBase {
37         ProbabilisticScorer(Object _dummy, long ptr) { super(ptr); }
38         @Override @SuppressWarnings("deprecation")
39         protected void finalize() throws Throwable {
40                 super.finalize();
41                 if (ptr != 0) { bindings.ProbabilisticScorer_free(ptr); }
42         }
43
44         /**
45          * Creates a new scorer using the given scoring parameters for sending payments from a node
46          * through a network graph.
47          */
48         public static ProbabilisticScorer of(ProbabilisticScoringParameters params, NetworkGraph network_graph, Logger logger) {
49                 long ret = bindings.ProbabilisticScorer_new(params == null ? 0 : params.ptr & ~1, network_graph == null ? 0 : network_graph.ptr & ~1, logger == null ? 0 : logger.ptr);
50                 Reference.reachabilityFence(params);
51                 Reference.reachabilityFence(network_graph);
52                 Reference.reachabilityFence(logger);
53                 if (ret >= 0 && ret <= 4096) { return null; }
54                 org.ldk.structs.ProbabilisticScorer ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ProbabilisticScorer(null, ret); }
55                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
56                 ret_hu_conv.ptrs_to.add(network_graph);
57                 ret_hu_conv.ptrs_to.add(logger);
58                 return ret_hu_conv;
59         }
60
61         /**
62          * Dump the contents of this scorer into the configured logger.
63          * 
64          * Note that this writes roughly one line per channel for which we have a liquidity estimate,
65          * which may be a substantial amount of log output.
66          */
67         public void debug_log_liquidity_stats() {
68                 bindings.ProbabilisticScorer_debug_log_liquidity_stats(this.ptr);
69                 Reference.reachabilityFence(this);
70         }
71
72         /**
73          * Constructs a new Score which calls the relevant methods on this_arg.
74          * This copies the `inner` pointer in this_arg and thus the returned Score must be freed before this_arg is
75          */
76         public Score as_Score() {
77                 long ret = bindings.ProbabilisticScorer_as_Score(this.ptr);
78                 Reference.reachabilityFence(this);
79                 if (ret >= 0 && ret <= 4096) { return null; }
80                 Score ret_hu_conv = new Score(null, ret);
81                 ret_hu_conv.ptrs_to.add(this);
82                 return ret_hu_conv;
83         }
84
85         /**
86          * Serialize the ProbabilisticScorer object into a byte array which can be read by ProbabilisticScorer_read
87          */
88         public byte[] write() {
89                 byte[] ret = bindings.ProbabilisticScorer_write(this.ptr);
90                 Reference.reachabilityFence(this);
91                 return ret;
92         }
93
94         /**
95          * Read a ProbabilisticScorer from a byte array, created by ProbabilisticScorer_write
96          */
97         public static Result_ProbabilisticScorerDecodeErrorZ read(byte[] ser, ProbabilisticScoringParameters arg_a, NetworkGraph arg_b, Logger arg_c) {
98                 long ret = bindings.ProbabilisticScorer_read(ser, arg_a == null ? 0 : arg_a.ptr & ~1, arg_b == null ? 0 : arg_b.ptr & ~1, arg_c == null ? 0 : arg_c.ptr);
99                 Reference.reachabilityFence(ser);
100                 Reference.reachabilityFence(arg_a);
101                 Reference.reachabilityFence(arg_b);
102                 Reference.reachabilityFence(arg_c);
103                 if (ret >= 0 && ret <= 4096) { return null; }
104                 Result_ProbabilisticScorerDecodeErrorZ ret_hu_conv = Result_ProbabilisticScorerDecodeErrorZ.constr_from_ptr(ret);
105                 ret_hu_conv.ptrs_to.add(arg_b);
106                 ret_hu_conv.ptrs_to.add(arg_c);
107                 return ret_hu_conv;
108         }
109
110 }