967ee60e0a68f4f339e5f9a5032bbc0d5a38b321
[ldk-java] / c_sharp / src / org / ldk / structs / Score.cs
1 using org.ldk.impl;
2 using org.ldk.enums;
3 using org.ldk.util;
4 using System;
5
6 namespace org { namespace ldk { namespace structs {
7
8 /**
9  * An interface used to score payment channels for path finding.
10  * 
11  * \tScoring is in terms of fees willing to be paid in order to avoid routing through a channel.
12  */
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;
19         }
20         ~Score() {
21                 if (ptr != 0) { bindings.Score_free(ptr); }
22         }
23
24         public interface ScoreInterface {
25                 /**
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`.
28                  * 
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.
34                  */
35                 long channel_penalty_msat(long _short_channel_id, NodeId _source, NodeId _target, ChannelUsage _usage);
36                 /**
37                  * Handles updating channel penalties after failing to route through a channel.
38                  */
39                 void payment_path_failed(RouteHop[] _path, long _short_channel_id);
40                 /**
41                  * Handles updating channel penalties after successfully routing along a path.
42                  */
43                 void payment_path_successful(RouteHop[] _path);
44                 /**
45                  * Handles updating channel penalties after a probe over the given path failed.
46                  */
47                 void probe_failed(RouteHop[] _path, long _short_channel_id);
48                 /**
49                  * Handles updating channel penalties after a probe over the given path succeeded.
50                  */
51                 void probe_successful(RouteHop[] _path);
52                 /**
53                  * Serialize the object into a byte array
54                  */
55                 byte[] write();
56         }
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);
68                                 GC.KeepAlive(arg);
69                         return ret;
70                 }
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;
79                         }
80                         arg.payment_path_failed(_path_conv_10_arr, _short_channel_id);
81                                 GC.KeepAlive(arg);
82                 }
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;
91                         }
92                         arg.payment_path_successful(_path_conv_10_arr);
93                                 GC.KeepAlive(arg);
94                 }
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;
103                         }
104                         arg.probe_failed(_path_conv_10_arr, _short_channel_id);
105                                 GC.KeepAlive(arg);
106                 }
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;
115                         }
116                         arg.probe_successful(_path_conv_10_arr);
117                                 GC.KeepAlive(arg);
118                 }
119                 public byte[] write() {
120                         byte[] ret = arg.write();
121                                 GC.KeepAlive(arg);
122                         return ret;
123                 }
124         }
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;
129         }
130         /**
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`.
133          * 
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.
139          */
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);
142                 GC.KeepAlive(this);
143                 GC.KeepAlive(short_channel_id);
144                 GC.KeepAlive(source);
145                 GC.KeepAlive(target);
146                 GC.KeepAlive(usage);
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); };
150                 return ret;
151         }
152
153         /**
154          * Handles updating channel penalties after failing to route through a channel.
155          */
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);
158                 GC.KeepAlive(this);
159                 GC.KeepAlive(path);
160                 GC.KeepAlive(short_channel_id);
161                 foreach (RouteHop path_conv_10 in path) { if (this != null) { this.ptrs_to.AddLast(path_conv_10); }; };
162         }
163
164         /**
165          * Handles updating channel penalties after successfully routing along a path.
166          */
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);
169                 GC.KeepAlive(this);
170                 GC.KeepAlive(path);
171                 foreach (RouteHop path_conv_10 in path) { if (this != null) { this.ptrs_to.AddLast(path_conv_10); }; };
172         }
173
174         /**
175          * Handles updating channel penalties after a probe over the given path failed.
176          */
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);
179                 GC.KeepAlive(this);
180                 GC.KeepAlive(path);
181                 GC.KeepAlive(short_channel_id);
182                 foreach (RouteHop path_conv_10 in path) { if (this != null) { this.ptrs_to.AddLast(path_conv_10); }; };
183         }
184
185         /**
186          * Handles updating channel penalties after a probe over the given path succeeded.
187          */
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);
190                 GC.KeepAlive(this);
191                 GC.KeepAlive(path);
192                 foreach (RouteHop path_conv_10 in path) { if (this != null) { this.ptrs_to.AddLast(path_conv_10); }; };
193         }
194
195         /**
196          * Serialize the object into a byte array
197          */
198         public byte[] write() {
199                 byte[] ret = bindings.Score_write(this.ptr);
200                 GC.KeepAlive(this);
201                 return ret;
202         }
203
204 }
205 } } }