[Java] Update auto-generated bindings
[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) {
49                 long ret = bindings.ProbabilisticScorer_new(params == null ? 0 : params.ptr & ~1, network_graph == null ? 0 : network_graph.ptr & ~1);
50                 Reference.reachabilityFence(params);
51                 Reference.reachabilityFence(network_graph);
52                 if (ret >= 0 && ret <= 4096) { return null; }
53                 ProbabilisticScorer ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ProbabilisticScorer(null, ret); }
54                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
55                 ret_hu_conv.ptrs_to.add(network_graph);
56                 return ret_hu_conv;
57         }
58
59         /**
60          * Constructs a new Score which calls the relevant methods on this_arg.
61          * This copies the `inner` pointer in this_arg and thus the returned Score must be freed before this_arg is
62          */
63         public Score as_Score() {
64                 long ret = bindings.ProbabilisticScorer_as_Score(this.ptr);
65                 Reference.reachabilityFence(this);
66                 if (ret >= 0 && ret <= 4096) { return null; }
67                 Score ret_hu_conv = new Score(null, ret);
68                 ret_hu_conv.ptrs_to.add(this);
69                 return ret_hu_conv;
70         }
71
72         /**
73          * Serialize the ProbabilisticScorer object into a byte array which can be read by ProbabilisticScorer_read
74          */
75         public byte[] write() {
76                 byte[] ret = bindings.ProbabilisticScorer_write(this.ptr);
77                 Reference.reachabilityFence(this);
78                 return ret;
79         }
80
81         /**
82          * Read a ProbabilisticScorer from a byte array, created by ProbabilisticScorer_write
83          */
84         public static Result_ProbabilisticScorerDecodeErrorZ read(byte[] ser, ProbabilisticScoringParameters arg_a, NetworkGraph arg_b) {
85                 long ret = bindings.ProbabilisticScorer_read(ser, arg_a == null ? 0 : arg_a.ptr & ~1, arg_b == null ? 0 : arg_b.ptr & ~1);
86                 Reference.reachabilityFence(ser);
87                 Reference.reachabilityFence(arg_a);
88                 Reference.reachabilityFence(arg_b);
89                 if (ret >= 0 && ret <= 4096) { return null; }
90                 Result_ProbabilisticScorerDecodeErrorZ ret_hu_conv = Result_ProbabilisticScorerDecodeErrorZ.constr_from_ptr(ret);
91                 ret_hu_conv.ptrs_to.add(arg_b);
92                 return ret_hu_conv;
93         }
94
95 }