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);
37 * Handles updating channel penalties after failing to route through a channel.
39 void payment_path_failed(RouteHop[] _path, long _short_channel_id);
41 * Handles updating channel penalties after successfully routing along a path.
43 void payment_path_successful(RouteHop[] _path);
45 * Handles updating channel penalties after a probe over the given path failed.
47 void probe_failed(RouteHop[] _path, long _short_channel_id);
49 * Handles updating channel penalties after a probe over the given path succeeded.
51 void probe_successful(RouteHop[] _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) {
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 long ret = arg.channel_penalty_msat(_short_channel_id, _source_hu_conv, _target_hu_conv, _usage_hu_conv);
71 public void payment_path_failed(long[] _path, long _short_channel_id) {
72 int _path_conv_10_len = _path.Length;
73 RouteHop[] _path_conv_10_arr = new RouteHop[_path_conv_10_len];
74 for (int k = 0; k < _path_conv_10_len; k++) {
75 long _path_conv_10 = _path[k];
76 org.ldk.structs.RouteHop _path_conv_10_hu_conv = null; if (_path_conv_10 < 0 || _path_conv_10 > 4096) { _path_conv_10_hu_conv = new org.ldk.structs.RouteHop(null, _path_conv_10); }
77 if (_path_conv_10_hu_conv != null) { _path_conv_10_hu_conv.ptrs_to.AddLast(this); };
78 _path_conv_10_arr[k] = _path_conv_10_hu_conv;
80 arg.payment_path_failed(_path_conv_10_arr, _short_channel_id);
83 public void payment_path_successful(long[] _path) {
84 int _path_conv_10_len = _path.Length;
85 RouteHop[] _path_conv_10_arr = new RouteHop[_path_conv_10_len];
86 for (int k = 0; k < _path_conv_10_len; k++) {
87 long _path_conv_10 = _path[k];
88 org.ldk.structs.RouteHop _path_conv_10_hu_conv = null; if (_path_conv_10 < 0 || _path_conv_10 > 4096) { _path_conv_10_hu_conv = new org.ldk.structs.RouteHop(null, _path_conv_10); }
89 if (_path_conv_10_hu_conv != null) { _path_conv_10_hu_conv.ptrs_to.AddLast(this); };
90 _path_conv_10_arr[k] = _path_conv_10_hu_conv;
92 arg.payment_path_successful(_path_conv_10_arr);
95 public void probe_failed(long[] _path, long _short_channel_id) {
96 int _path_conv_10_len = _path.Length;
97 RouteHop[] _path_conv_10_arr = new RouteHop[_path_conv_10_len];
98 for (int k = 0; k < _path_conv_10_len; k++) {
99 long _path_conv_10 = _path[k];
100 org.ldk.structs.RouteHop _path_conv_10_hu_conv = null; if (_path_conv_10 < 0 || _path_conv_10 > 4096) { _path_conv_10_hu_conv = new org.ldk.structs.RouteHop(null, _path_conv_10); }
101 if (_path_conv_10_hu_conv != null) { _path_conv_10_hu_conv.ptrs_to.AddLast(this); };
102 _path_conv_10_arr[k] = _path_conv_10_hu_conv;
104 arg.probe_failed(_path_conv_10_arr, _short_channel_id);
107 public void probe_successful(long[] _path) {
108 int _path_conv_10_len = _path.Length;
109 RouteHop[] _path_conv_10_arr = new RouteHop[_path_conv_10_len];
110 for (int k = 0; k < _path_conv_10_len; k++) {
111 long _path_conv_10 = _path[k];
112 org.ldk.structs.RouteHop _path_conv_10_hu_conv = null; if (_path_conv_10 < 0 || _path_conv_10 > 4096) { _path_conv_10_hu_conv = new org.ldk.structs.RouteHop(null, _path_conv_10); }
113 if (_path_conv_10_hu_conv != null) { _path_conv_10_hu_conv.ptrs_to.AddLast(this); };
114 _path_conv_10_arr[k] = _path_conv_10_hu_conv;
116 arg.probe_successful(_path_conv_10_arr);
119 public byte[] write() {
120 byte[] ret = arg.write();
125 public static Score new_impl(ScoreInterface arg) {
126 LDKScoreHolder impl_holder = new LDKScoreHolder();
127 impl_holder.held = new Score(new LDKScoreImpl(arg, impl_holder));
128 return impl_holder.held;
131 * Returns the fee in msats willing to be paid to avoid routing `send_amt_msat` through the
132 * given channel in the direction from `source` to `target`.
134 * The channel's capacity (less any other MPP parts that are also being considered for use in
135 * the same payment) is given by `capacity_msat`. It may be determined from various sources
136 * such as a chain data, network gossip, or invoice hints. For invoice hints, a capacity near
137 * [`u64::max_value`] is given to indicate sufficient capacity for the invoice's full amount.
138 * Thus, implementations should be overflow-safe.
140 public long channel_penalty_msat(long short_channel_id, org.ldk.structs.NodeId source, org.ldk.structs.NodeId target, org.ldk.structs.ChannelUsage usage) {
141 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);
143 GC.KeepAlive(short_channel_id);
144 GC.KeepAlive(source);
145 GC.KeepAlive(target);
147 if (this != null) { this.ptrs_to.AddLast(source); };
148 if (this != null) { this.ptrs_to.AddLast(target); };
149 if (this != null) { this.ptrs_to.AddLast(usage); };
154 * Handles updating channel penalties after failing to route through a channel.
156 public void payment_path_failed(RouteHop[] path, long short_channel_id) {
157 bindings.Score_payment_path_failed(this.ptr, path != null ? InternalUtils.mapArray(path, path_conv_10 => path_conv_10 == null ? 0 : path_conv_10.ptr) : null, short_channel_id);
160 GC.KeepAlive(short_channel_id);
161 foreach (RouteHop path_conv_10 in path) { if (this != null) { this.ptrs_to.AddLast(path_conv_10); }; };
165 * Handles updating channel penalties after successfully routing along a path.
167 public void payment_path_successful(RouteHop[] path) {
168 bindings.Score_payment_path_successful(this.ptr, path != null ? InternalUtils.mapArray(path, path_conv_10 => path_conv_10 == null ? 0 : path_conv_10.ptr) : null);
171 foreach (RouteHop path_conv_10 in path) { if (this != null) { this.ptrs_to.AddLast(path_conv_10); }; };
175 * Handles updating channel penalties after a probe over the given path failed.
177 public void probe_failed(RouteHop[] path, long short_channel_id) {
178 bindings.Score_probe_failed(this.ptr, path != null ? InternalUtils.mapArray(path, path_conv_10 => path_conv_10 == null ? 0 : path_conv_10.ptr) : null, short_channel_id);
181 GC.KeepAlive(short_channel_id);
182 foreach (RouteHop path_conv_10 in path) { if (this != null) { this.ptrs_to.AddLast(path_conv_10); }; };
186 * Handles updating channel penalties after a probe over the given path succeeded.
188 public void probe_successful(RouteHop[] path) {
189 bindings.Score_probe_successful(this.ptr, path != null ? InternalUtils.mapArray(path, path_conv_10 => path_conv_10 == null ? 0 : path_conv_10.ptr) : null);
192 foreach (RouteHop path_conv_10 in path) { if (this != null) { this.ptrs_to.AddLast(path_conv_10); }; };
196 * Serialize the object into a byte array
198 public byte[] write() {
199 byte[] ret = bindings.Score_write(this.ptr);