[Java] Update auto-generated Java bindings for 0.0.116
[ldk-java] / src / main / java / org / ldk / structs / Score.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  * An interface used to score payment channels for path finding.
12  * 
13  * \tScoring is in terms of fees willing to be paid in order to avoid routing through a channel.
14  */
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class Score extends CommonBase {
17         final bindings.LDKScore bindings_instance;
18         Score(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
19         private Score(bindings.LDKScore arg) {
20                 super(bindings.LDKScore_new(arg));
21                 this.ptrs_to.add(arg);
22                 this.bindings_instance = arg;
23         }
24         @Override @SuppressWarnings("deprecation")
25         protected void finalize() throws Throwable {
26                 if (ptr != 0) { bindings.Score_free(ptr); } super.finalize();
27         }
28         /**
29          * Destroys the object, freeing associated resources. After this call, any access
30          * to this object may result in a SEGFAULT or worse.
31          *
32          * You should generally NEVER call this method. You should let the garbage collector
33          * do this for you when it finalizes objects. However, it may be useful for types
34          * which represent locks and should be closed immediately to avoid holding locks
35          * until the GC runs.
36          */
37         public void destroy() {
38                 if (ptr != 0) { bindings.Score_free(ptr); }
39                 ptr = 0;
40         }
41         public static interface ScoreInterface {
42                 /**
43                  * Returns the fee in msats willing to be paid to avoid routing `send_amt_msat` through the
44                  * given channel in the direction from `source` to `target`.
45                  * 
46                  * The channel's capacity (less any other MPP parts that are also being considered for use in
47                  * the same payment) is given by `capacity_msat`. It may be determined from various sources
48                  * such as a chain data, network gossip, or invoice hints. For invoice hints, a capacity near
49                  * [`u64::max_value`] is given to indicate sufficient capacity for the invoice's full amount.
50                  * Thus, implementations should be overflow-safe.
51                  */
52                 long channel_penalty_msat(long short_channel_id, NodeId source, NodeId target, ChannelUsage usage, ProbabilisticScoringFeeParameters score_params);
53                 /**
54                  * Handles updating channel penalties after failing to route through a channel.
55                  */
56                 void payment_path_failed(Path path, long short_channel_id);
57                 /**
58                  * Handles updating channel penalties after successfully routing along a path.
59                  */
60                 void payment_path_successful(Path path);
61                 /**
62                  * Handles updating channel penalties after a probe over the given path failed.
63                  */
64                 void probe_failed(Path path, long short_channel_id);
65                 /**
66                  * Handles updating channel penalties after a probe over the given path succeeded.
67                  */
68                 void probe_successful(Path path);
69                 /**
70                  * Serialize the object into a byte array
71                  */
72                 byte[] write();
73         }
74         private static class LDKScoreHolder { Score held; }
75         public static Score new_impl(ScoreInterface arg) {
76                 final LDKScoreHolder impl_holder = new LDKScoreHolder();
77                 impl_holder.held = new Score(new bindings.LDKScore() {
78                         @Override public long channel_penalty_msat(long short_channel_id, long source, long target, long usage, long score_params) {
79                                 org.ldk.structs.NodeId source_hu_conv = null; if (source < 0 || source > 4096) { source_hu_conv = new org.ldk.structs.NodeId(null, source); }
80                                 org.ldk.structs.NodeId target_hu_conv = null; if (target < 0 || target > 4096) { target_hu_conv = new org.ldk.structs.NodeId(null, target); }
81                                 org.ldk.structs.ChannelUsage usage_hu_conv = null; if (usage < 0 || usage > 4096) { usage_hu_conv = new org.ldk.structs.ChannelUsage(null, usage); }
82                                 if (usage_hu_conv != null) { usage_hu_conv.ptrs_to.add(this); };
83                                 org.ldk.structs.ProbabilisticScoringFeeParameters score_params_hu_conv = null; if (score_params < 0 || score_params > 4096) { score_params_hu_conv = new org.ldk.structs.ProbabilisticScoringFeeParameters(null, score_params); }
84                                 long ret = arg.channel_penalty_msat(short_channel_id, source_hu_conv, target_hu_conv, usage_hu_conv, score_params_hu_conv);
85                                 Reference.reachabilityFence(arg);
86                                 return ret;
87                         }
88                         @Override public void payment_path_failed(long path, long short_channel_id) {
89                                 org.ldk.structs.Path path_hu_conv = null; if (path < 0 || path > 4096) { path_hu_conv = new org.ldk.structs.Path(null, path); }
90                                 arg.payment_path_failed(path_hu_conv, short_channel_id);
91                                 Reference.reachabilityFence(arg);
92                         }
93                         @Override public void payment_path_successful(long path) {
94                                 org.ldk.structs.Path path_hu_conv = null; if (path < 0 || path > 4096) { path_hu_conv = new org.ldk.structs.Path(null, path); }
95                                 arg.payment_path_successful(path_hu_conv);
96                                 Reference.reachabilityFence(arg);
97                         }
98                         @Override public void probe_failed(long path, long short_channel_id) {
99                                 org.ldk.structs.Path path_hu_conv = null; if (path < 0 || path > 4096) { path_hu_conv = new org.ldk.structs.Path(null, path); }
100                                 arg.probe_failed(path_hu_conv, short_channel_id);
101                                 Reference.reachabilityFence(arg);
102                         }
103                         @Override public void probe_successful(long path) {
104                                 org.ldk.structs.Path path_hu_conv = null; if (path < 0 || path > 4096) { path_hu_conv = new org.ldk.structs.Path(null, path); }
105                                 arg.probe_successful(path_hu_conv);
106                                 Reference.reachabilityFence(arg);
107                         }
108                         @Override public byte[] write() {
109                                 byte[] ret = arg.write();
110                                 Reference.reachabilityFence(arg);
111                                 return ret;
112                         }
113                 });
114                 return impl_holder.held;
115         }
116         /**
117          * Returns the fee in msats willing to be paid to avoid routing `send_amt_msat` through the
118          * given channel in the direction from `source` to `target`.
119          * 
120          * The channel's capacity (less any other MPP parts that are also being considered for use in
121          * the same payment) is given by `capacity_msat`. It may be determined from various sources
122          * such as a chain data, network gossip, or invoice hints. For invoice hints, a capacity near
123          * [`u64::max_value`] is given to indicate sufficient capacity for the invoice's full amount.
124          * Thus, implementations should be overflow-safe.
125          */
126         public long channel_penalty_msat(long short_channel_id, org.ldk.structs.NodeId source, org.ldk.structs.NodeId target, org.ldk.structs.ChannelUsage usage, org.ldk.structs.ProbabilisticScoringFeeParameters score_params) {
127                 long ret = bindings.Score_channel_penalty_msat(this.ptr, short_channel_id, source == null ? 0 : source.ptr, target == null ? 0 : target.ptr, usage == null ? 0 : usage.ptr, score_params == null ? 0 : score_params.ptr);
128                 Reference.reachabilityFence(this);
129                 Reference.reachabilityFence(short_channel_id);
130                 Reference.reachabilityFence(source);
131                 Reference.reachabilityFence(target);
132                 Reference.reachabilityFence(usage);
133                 Reference.reachabilityFence(score_params);
134                 if (this != null) { this.ptrs_to.add(source); };
135                 if (this != null) { this.ptrs_to.add(target); };
136                 if (this != null) { this.ptrs_to.add(usage); };
137                 if (this != null) { this.ptrs_to.add(score_params); };
138                 return ret;
139         }
140
141         /**
142          * Handles updating channel penalties after failing to route through a channel.
143          */
144         public void payment_path_failed(org.ldk.structs.Path path, long short_channel_id) {
145                 bindings.Score_payment_path_failed(this.ptr, path == null ? 0 : path.ptr, short_channel_id);
146                 Reference.reachabilityFence(this);
147                 Reference.reachabilityFence(path);
148                 Reference.reachabilityFence(short_channel_id);
149                 if (this != null) { this.ptrs_to.add(path); };
150         }
151
152         /**
153          * Handles updating channel penalties after successfully routing along a path.
154          */
155         public void payment_path_successful(org.ldk.structs.Path path) {
156                 bindings.Score_payment_path_successful(this.ptr, path == null ? 0 : path.ptr);
157                 Reference.reachabilityFence(this);
158                 Reference.reachabilityFence(path);
159                 if (this != null) { this.ptrs_to.add(path); };
160         }
161
162         /**
163          * Handles updating channel penalties after a probe over the given path failed.
164          */
165         public void probe_failed(org.ldk.structs.Path path, long short_channel_id) {
166                 bindings.Score_probe_failed(this.ptr, path == null ? 0 : path.ptr, short_channel_id);
167                 Reference.reachabilityFence(this);
168                 Reference.reachabilityFence(path);
169                 Reference.reachabilityFence(short_channel_id);
170                 if (this != null) { this.ptrs_to.add(path); };
171         }
172
173         /**
174          * Handles updating channel penalties after a probe over the given path succeeded.
175          */
176         public void probe_successful(org.ldk.structs.Path path) {
177                 bindings.Score_probe_successful(this.ptr, path == null ? 0 : path.ptr);
178                 Reference.reachabilityFence(this);
179                 Reference.reachabilityFence(path);
180                 if (this != null) { this.ptrs_to.add(path); };
181         }
182
183         /**
184          * Serialize the object into a byte array
185          */
186         public byte[] write() {
187                 byte[] ret = bindings.Score_write(this.ptr);
188                 Reference.reachabilityFence(this);
189                 return ret;
190         }
191
192 }