6 namespace org { namespace ldk { namespace structs {
9 * An interface used to score payment channels for path finding.
11 * \tScoring is in terms of fees willing to be paid in order to avoid routing through a channel.
13 public class Score : CommonBase {
14 internal readonly bindings.LDKScore bindings_instance;
15 internal Score(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
16 private Score(bindings.LDKScore arg) : base(bindings.LDKScore_new(arg)) {
17 this.ptrs_to.AddLast(arg);
18 this.bindings_instance = arg;
21 if (ptr != 0) { bindings.Score_free(ptr); }
24 public interface ScoreInterface {
26 * Returns the fee in msats willing to be paid to avoid routing `send_amt_msat` through the
27 * given channel in the direction from `source` to `target`.
29 * The channel's capacity (less any other MPP parts that are also being considered for use in
30 * the same payment) is given by `capacity_msat`. It may be determined from various sources
31 * such as a chain data, network gossip, or invoice hints. For invoice hints, a capacity near
32 * [`u64::max_value`] is given to indicate sufficient capacity for the invoice's full amount.
33 * Thus, implementations should be overflow-safe.
35 long channel_penalty_msat(long _short_channel_id, NodeId _source, NodeId _target, ChannelUsage _usage, ProbabilisticScoringFeeParameters _score_params);
37 * Handles updating channel penalties after failing to route through a channel.
39 void payment_path_failed(Path _path, long _short_channel_id);
41 * Handles updating channel penalties after successfully routing along a path.
43 void payment_path_successful(Path _path);
45 * Handles updating channel penalties after a probe over the given path failed.
47 void probe_failed(Path _path, long _short_channel_id);
49 * Handles updating channel penalties after a probe over the given path succeeded.
51 void probe_successful(Path _path);
53 * Serialize the object into a byte array
57 private class LDKScoreHolder { internal Score held; }
58 private class LDKScoreImpl : bindings.LDKScore {
59 internal LDKScoreImpl(ScoreInterface arg, LDKScoreHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
60 private ScoreInterface arg;
61 private LDKScoreHolder impl_holder;
62 public long channel_penalty_msat(long _short_channel_id, long _source, long _target, long _usage, long _score_params) {
63 org.ldk.structs.NodeId _source_hu_conv = null; if (_source < 0 || _source > 4096) { _source_hu_conv = new org.ldk.structs.NodeId(null, _source); }
64 org.ldk.structs.NodeId _target_hu_conv = null; if (_target < 0 || _target > 4096) { _target_hu_conv = new org.ldk.structs.NodeId(null, _target); }
65 org.ldk.structs.ChannelUsage _usage_hu_conv = null; if (_usage < 0 || _usage > 4096) { _usage_hu_conv = new org.ldk.structs.ChannelUsage(null, _usage); }
66 if (_usage_hu_conv != null) { _usage_hu_conv.ptrs_to.AddLast(this); };
67 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); }
68 long ret = arg.channel_penalty_msat(_short_channel_id, _source_hu_conv, _target_hu_conv, _usage_hu_conv, _score_params_hu_conv);
72 public void payment_path_failed(long _path, long _short_channel_id) {
73 org.ldk.structs.Path _path_hu_conv = null; if (_path < 0 || _path > 4096) { _path_hu_conv = new org.ldk.structs.Path(null, _path); }
74 arg.payment_path_failed(_path_hu_conv, _short_channel_id);
77 public void payment_path_successful(long _path) {
78 org.ldk.structs.Path _path_hu_conv = null; if (_path < 0 || _path > 4096) { _path_hu_conv = new org.ldk.structs.Path(null, _path); }
79 arg.payment_path_successful(_path_hu_conv);
82 public void probe_failed(long _path, long _short_channel_id) {
83 org.ldk.structs.Path _path_hu_conv = null; if (_path < 0 || _path > 4096) { _path_hu_conv = new org.ldk.structs.Path(null, _path); }
84 arg.probe_failed(_path_hu_conv, _short_channel_id);
87 public void probe_successful(long _path) {
88 org.ldk.structs.Path _path_hu_conv = null; if (_path < 0 || _path > 4096) { _path_hu_conv = new org.ldk.structs.Path(null, _path); }
89 arg.probe_successful(_path_hu_conv);
92 public byte[] write() {
93 byte[] ret = arg.write();
98 public static Score new_impl(ScoreInterface arg) {
99 LDKScoreHolder impl_holder = new LDKScoreHolder();
100 impl_holder.held = new Score(new LDKScoreImpl(arg, impl_holder));
101 return impl_holder.held;
104 * Returns the fee in msats willing to be paid to avoid routing `send_amt_msat` through the
105 * given channel in the direction from `source` to `target`.
107 * The channel's capacity (less any other MPP parts that are also being considered for use in
108 * the same payment) is given by `capacity_msat`. It may be determined from various sources
109 * such as a chain data, network gossip, or invoice hints. For invoice hints, a capacity near
110 * [`u64::max_value`] is given to indicate sufficient capacity for the invoice's full amount.
111 * Thus, implementations should be overflow-safe.
113 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) {
114 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);
116 GC.KeepAlive(short_channel_id);
117 GC.KeepAlive(source);
118 GC.KeepAlive(target);
120 GC.KeepAlive(score_params);
121 if (this != null) { this.ptrs_to.AddLast(source); };
122 if (this != null) { this.ptrs_to.AddLast(target); };
123 if (this != null) { this.ptrs_to.AddLast(usage); };
124 if (this != null) { this.ptrs_to.AddLast(score_params); };
129 * Handles updating channel penalties after failing to route through a channel.
131 public void payment_path_failed(org.ldk.structs.Path path, long short_channel_id) {
132 bindings.Score_payment_path_failed(this.ptr, path == null ? 0 : path.ptr, short_channel_id);
135 GC.KeepAlive(short_channel_id);
136 if (this != null) { this.ptrs_to.AddLast(path); };
140 * Handles updating channel penalties after successfully routing along a path.
142 public void payment_path_successful(org.ldk.structs.Path path) {
143 bindings.Score_payment_path_successful(this.ptr, path == null ? 0 : path.ptr);
146 if (this != null) { this.ptrs_to.AddLast(path); };
150 * Handles updating channel penalties after a probe over the given path failed.
152 public void probe_failed(org.ldk.structs.Path path, long short_channel_id) {
153 bindings.Score_probe_failed(this.ptr, path == null ? 0 : path.ptr, short_channel_id);
156 GC.KeepAlive(short_channel_id);
157 if (this != null) { this.ptrs_to.AddLast(path); };
161 * Handles updating channel penalties after a probe over the given path succeeded.
163 public void probe_successful(org.ldk.structs.Path path) {
164 bindings.Score_probe_successful(this.ptr, path == null ? 0 : path.ptr);
167 if (this != null) { this.ptrs_to.AddLast(path); };
171 * Serialize the object into a byte array
173 public byte[] write() {
174 byte[] ret = bindings.Score_write(this.ptr);