1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
11 * An interface used to score payment channels for path finding.
13 * `ScoreLookUp` is used to determine the penalty for a given channel.
15 * Scoring is in terms of fees willing to be paid in order to avoid routing through a channel.
17 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
18 public class ScoreLookUp extends CommonBase {
19 final bindings.LDKScoreLookUp bindings_instance;
20 ScoreLookUp(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
21 private ScoreLookUp(bindings.LDKScoreLookUp arg) {
22 super(bindings.LDKScoreLookUp_new(arg));
23 this.ptrs_to.add(arg);
24 this.bindings_instance = arg;
26 @Override @SuppressWarnings("deprecation")
27 protected void finalize() throws Throwable {
28 if (ptr != 0) { bindings.ScoreLookUp_free(ptr); } super.finalize();
31 * Destroys the object, freeing associated resources. After this call, any access
32 * to this object may result in a SEGFAULT or worse.
34 * You should generally NEVER call this method. You should let the garbage collector
35 * do this for you when it finalizes objects. However, it may be useful for types
36 * which represent locks and should be closed immediately to avoid holding locks
39 public void destroy() {
40 if (ptr != 0) { bindings.ScoreLookUp_free(ptr); }
43 public static interface ScoreLookUpInterface {
45 * Returns the fee in msats willing to be paid to avoid routing `send_amt_msat` through the
46 * given channel in the direction from `source` to `target`.
48 * The channel's capacity (less any other MPP parts that are also being considered for use in
49 * the same payment) is given by `capacity_msat`. It may be determined from various sources
50 * such as a chain data, network gossip, or invoice hints. For invoice hints, a capacity near
51 * [`u64::max_value`] is given to indicate sufficient capacity for the invoice's full amount.
52 * Thus, implementations should be overflow-safe.
54 long channel_penalty_msat(CandidateRouteHop candidate, ChannelUsage usage, ProbabilisticScoringFeeParameters score_params);
56 private static class LDKScoreLookUpHolder { ScoreLookUp held; }
57 public static ScoreLookUp new_impl(ScoreLookUpInterface arg) {
58 final LDKScoreLookUpHolder impl_holder = new LDKScoreLookUpHolder();
59 impl_holder.held = new ScoreLookUp(new bindings.LDKScoreLookUp() {
60 @Override public long channel_penalty_msat(long candidate, long usage, long score_params) {
61 CandidateRouteHop candidate_hu_conv = CandidateRouteHop.constr_from_ptr(candidate);
62 org.ldk.structs.ChannelUsage usage_hu_conv = null; if (usage < 0 || usage > 4096) { usage_hu_conv = new org.ldk.structs.ChannelUsage(null, usage); }
63 if (usage_hu_conv != null) { usage_hu_conv.ptrs_to.add(this); };
64 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); }
65 long ret = arg.channel_penalty_msat(candidate_hu_conv, usage_hu_conv, score_params_hu_conv);
66 Reference.reachabilityFence(arg);
70 return impl_holder.held;
73 * Returns the fee in msats willing to be paid to avoid routing `send_amt_msat` through the
74 * given channel in the direction from `source` to `target`.
76 * The channel's capacity (less any other MPP parts that are also being considered for use in
77 * the same payment) is given by `capacity_msat`. It may be determined from various sources
78 * such as a chain data, network gossip, or invoice hints. For invoice hints, a capacity near
79 * [`u64::max_value`] is given to indicate sufficient capacity for the invoice's full amount.
80 * Thus, implementations should be overflow-safe.
82 public long channel_penalty_msat(org.ldk.structs.CandidateRouteHop candidate, org.ldk.structs.ChannelUsage usage, org.ldk.structs.ProbabilisticScoringFeeParameters score_params) {
83 long ret = bindings.ScoreLookUp_channel_penalty_msat(this.ptr, candidate == null ? 0 : candidate.ptr, usage == null ? 0 : usage.ptr, score_params == null ? 0 : score_params.ptr);
84 Reference.reachabilityFence(this);
85 Reference.reachabilityFence(candidate);
86 Reference.reachabilityFence(usage);
87 Reference.reachabilityFence(score_params);
88 if (this != null) { this.ptrs_to.add(usage); };
89 if (this != null) { this.ptrs_to.add(score_params); };