cf87be82fb02b6a378f88f66764fd87088da1aaa
[ldk-java] / c_sharp / src / org / ldk / structs / Router.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  * A trait defining behavior for routing a payment.
10  */
11 public class Router : CommonBase {
12         internal readonly bindings.LDKRouter bindings_instance;
13         internal Router(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
14         private Router(bindings.LDKRouter arg) : base(bindings.LDKRouter_new(arg)) {
15                 this.ptrs_to.AddLast(arg);
16                 this.bindings_instance = arg;
17         }
18         ~Router() {
19                 if (ptr != 0) { bindings.Router_free(ptr); }
20         }
21
22         public interface RouterInterface {
23                 /**
24                  * Finds a [`Route`] between `payer` and `payee` for a payment with the given values.
25                  * 
26                  * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
27                  */
28                 Result_RouteLightningErrorZ find_route(byte[] _payer, RouteParameters _route_params, ChannelDetails[] _first_hops, InFlightHtlcs _inflight_htlcs);
29                 /**
30                  * Finds a [`Route`] between `payer` and `payee` for a payment with the given values. Includes
31                  * `PaymentHash` and `PaymentId` to be able to correlate the request with a specific payment.
32                  * 
33                  * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
34                  */
35                 Result_RouteLightningErrorZ find_route_with_id(byte[] _payer, RouteParameters _route_params, ChannelDetails[] _first_hops, InFlightHtlcs _inflight_htlcs, byte[] __payment_hash, byte[] __payment_id);
36                 /**
37                  * Lets the router know that payment through a specific path has failed.
38                  */
39                 void notify_payment_path_failed(RouteHop[] _path, long _short_channel_id);
40                 /**
41                  * Lets the router know that payment through a specific path was successful.
42                  */
43                 void notify_payment_path_successful(RouteHop[] _path);
44                 /**
45                  * Lets the router know that a payment probe was successful.
46                  */
47                 void notify_payment_probe_successful(RouteHop[] _path);
48                 /**
49                  * Lets the router know that a payment probe failed.
50                  */
51                 void notify_payment_probe_failed(RouteHop[] _path, long _short_channel_id);
52         }
53         private class LDKRouterHolder { internal Router held; }
54         private class LDKRouterImpl : bindings.LDKRouter {
55                 internal LDKRouterImpl(RouterInterface arg, LDKRouterHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
56                 private RouterInterface arg;
57                 private LDKRouterHolder impl_holder;
58                 public long find_route(byte[] _payer, long _route_params, long[] _first_hops, long _inflight_htlcs) {
59                         org.ldk.structs.RouteParameters _route_params_hu_conv = null; if (_route_params < 0 || _route_params > 4096) { _route_params_hu_conv = new org.ldk.structs.RouteParameters(null, _route_params); }
60                         int _first_hops_conv_16_len = _first_hops.Length;
61                         ChannelDetails[] _first_hops_conv_16_arr = new ChannelDetails[_first_hops_conv_16_len];
62                         if (_first_hops != null) {
63                                 for (int q = 0; q < _first_hops_conv_16_len; q++) {
64                                         long _first_hops_conv_16 = _first_hops[q];
65                                         org.ldk.structs.ChannelDetails _first_hops_conv_16_hu_conv = null; if (_first_hops_conv_16 < 0 || _first_hops_conv_16 > 4096) { _first_hops_conv_16_hu_conv = new org.ldk.structs.ChannelDetails(null, _first_hops_conv_16); }
66                                         if (_first_hops_conv_16_hu_conv != null) { _first_hops_conv_16_hu_conv.ptrs_to.AddLast(this); };
67                                         _first_hops_conv_16_arr[q] = _first_hops_conv_16_hu_conv;
68                                 }
69                         }
70                         org.ldk.structs.InFlightHtlcs _inflight_htlcs_hu_conv = null; if (_inflight_htlcs < 0 || _inflight_htlcs > 4096) { _inflight_htlcs_hu_conv = new org.ldk.structs.InFlightHtlcs(null, _inflight_htlcs); }
71                         if (_inflight_htlcs_hu_conv != null) { _inflight_htlcs_hu_conv.ptrs_to.AddLast(this); };
72                         Result_RouteLightningErrorZ ret = arg.find_route(_payer, _route_params_hu_conv, _first_hops_conv_16_arr, _inflight_htlcs_hu_conv);
73                                 GC.KeepAlive(arg);
74                         long result = ret == null ? 0 : ret.clone_ptr();
75                         return result;
76                 }
77                 public long find_route_with_id(byte[] _payer, long _route_params, long[] _first_hops, long _inflight_htlcs, byte[] __payment_hash, byte[] __payment_id) {
78                         org.ldk.structs.RouteParameters _route_params_hu_conv = null; if (_route_params < 0 || _route_params > 4096) { _route_params_hu_conv = new org.ldk.structs.RouteParameters(null, _route_params); }
79                         int _first_hops_conv_16_len = _first_hops.Length;
80                         ChannelDetails[] _first_hops_conv_16_arr = new ChannelDetails[_first_hops_conv_16_len];
81                         if (_first_hops != null) {
82                                 for (int q = 0; q < _first_hops_conv_16_len; q++) {
83                                         long _first_hops_conv_16 = _first_hops[q];
84                                         org.ldk.structs.ChannelDetails _first_hops_conv_16_hu_conv = null; if (_first_hops_conv_16 < 0 || _first_hops_conv_16 > 4096) { _first_hops_conv_16_hu_conv = new org.ldk.structs.ChannelDetails(null, _first_hops_conv_16); }
85                                         if (_first_hops_conv_16_hu_conv != null) { _first_hops_conv_16_hu_conv.ptrs_to.AddLast(this); };
86                                         _first_hops_conv_16_arr[q] = _first_hops_conv_16_hu_conv;
87                                 }
88                         }
89                         org.ldk.structs.InFlightHtlcs _inflight_htlcs_hu_conv = null; if (_inflight_htlcs < 0 || _inflight_htlcs > 4096) { _inflight_htlcs_hu_conv = new org.ldk.structs.InFlightHtlcs(null, _inflight_htlcs); }
90                         if (_inflight_htlcs_hu_conv != null) { _inflight_htlcs_hu_conv.ptrs_to.AddLast(this); };
91                         Result_RouteLightningErrorZ ret = arg.find_route_with_id(_payer, _route_params_hu_conv, _first_hops_conv_16_arr, _inflight_htlcs_hu_conv, __payment_hash, __payment_id);
92                                 GC.KeepAlive(arg);
93                         long result = ret == null ? 0 : ret.clone_ptr();
94                         return result;
95                 }
96                 public void notify_payment_path_failed(long[] _path, long _short_channel_id) {
97                         int _path_conv_10_len = _path.Length;
98                         RouteHop[] _path_conv_10_arr = new RouteHop[_path_conv_10_len];
99                         for (int k = 0; k < _path_conv_10_len; k++) {
100                                 long _path_conv_10 = _path[k];
101                                 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); }
102                                 if (_path_conv_10_hu_conv != null) { _path_conv_10_hu_conv.ptrs_to.AddLast(this); };
103                                 _path_conv_10_arr[k] = _path_conv_10_hu_conv;
104                         }
105                         arg.notify_payment_path_failed(_path_conv_10_arr, _short_channel_id);
106                                 GC.KeepAlive(arg);
107                 }
108                 public void notify_payment_path_successful(long[] _path) {
109                         int _path_conv_10_len = _path.Length;
110                         RouteHop[] _path_conv_10_arr = new RouteHop[_path_conv_10_len];
111                         for (int k = 0; k < _path_conv_10_len; k++) {
112                                 long _path_conv_10 = _path[k];
113                                 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); }
114                                 if (_path_conv_10_hu_conv != null) { _path_conv_10_hu_conv.ptrs_to.AddLast(this); };
115                                 _path_conv_10_arr[k] = _path_conv_10_hu_conv;
116                         }
117                         arg.notify_payment_path_successful(_path_conv_10_arr);
118                                 GC.KeepAlive(arg);
119                 }
120                 public void notify_payment_probe_successful(long[] _path) {
121                         int _path_conv_10_len = _path.Length;
122                         RouteHop[] _path_conv_10_arr = new RouteHop[_path_conv_10_len];
123                         for (int k = 0; k < _path_conv_10_len; k++) {
124                                 long _path_conv_10 = _path[k];
125                                 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); }
126                                 if (_path_conv_10_hu_conv != null) { _path_conv_10_hu_conv.ptrs_to.AddLast(this); };
127                                 _path_conv_10_arr[k] = _path_conv_10_hu_conv;
128                         }
129                         arg.notify_payment_probe_successful(_path_conv_10_arr);
130                                 GC.KeepAlive(arg);
131                 }
132                 public void notify_payment_probe_failed(long[] _path, long _short_channel_id) {
133                         int _path_conv_10_len = _path.Length;
134                         RouteHop[] _path_conv_10_arr = new RouteHop[_path_conv_10_len];
135                         for (int k = 0; k < _path_conv_10_len; k++) {
136                                 long _path_conv_10 = _path[k];
137                                 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); }
138                                 if (_path_conv_10_hu_conv != null) { _path_conv_10_hu_conv.ptrs_to.AddLast(this); };
139                                 _path_conv_10_arr[k] = _path_conv_10_hu_conv;
140                         }
141                         arg.notify_payment_probe_failed(_path_conv_10_arr, _short_channel_id);
142                                 GC.KeepAlive(arg);
143                 }
144         }
145         public static Router new_impl(RouterInterface arg) {
146                 LDKRouterHolder impl_holder = new LDKRouterHolder();
147                 impl_holder.held = new Router(new LDKRouterImpl(arg, impl_holder));
148                 return impl_holder.held;
149         }
150         /**
151          * Finds a [`Route`] between `payer` and `payee` for a payment with the given values.
152          * 
153          * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
154          */
155         public Result_RouteLightningErrorZ find_route(byte[] payer, org.ldk.structs.RouteParameters route_params, ChannelDetails[] first_hops, org.ldk.structs.InFlightHtlcs inflight_htlcs) {
156                 long ret = bindings.Router_find_route(this.ptr, InternalUtils.check_arr_len(payer, 33), route_params == null ? 0 : route_params.ptr, first_hops != null ? InternalUtils.mapArray(first_hops, first_hops_conv_16 => first_hops_conv_16 == null ? 0 : first_hops_conv_16.ptr) : null, inflight_htlcs == null ? 0 : inflight_htlcs.ptr);
157                 GC.KeepAlive(this);
158                 GC.KeepAlive(payer);
159                 GC.KeepAlive(route_params);
160                 GC.KeepAlive(first_hops);
161                 GC.KeepAlive(inflight_htlcs);
162                 if (ret >= 0 && ret <= 4096) { return null; }
163                 Result_RouteLightningErrorZ ret_hu_conv = Result_RouteLightningErrorZ.constr_from_ptr(ret);
164                 if (this != null) { this.ptrs_to.AddLast(route_params); };
165                 if (first_hops != null) { foreach (ChannelDetails first_hops_conv_16 in first_hops) { if (this != null) { this.ptrs_to.AddLast(first_hops_conv_16); }; } };
166                 if (this != null) { this.ptrs_to.AddLast(inflight_htlcs); };
167                 return ret_hu_conv;
168         }
169
170         /**
171          * Finds a [`Route`] between `payer` and `payee` for a payment with the given values. Includes
172          * `PaymentHash` and `PaymentId` to be able to correlate the request with a specific payment.
173          * 
174          * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
175          */
176         public Result_RouteLightningErrorZ find_route_with_id(byte[] payer, org.ldk.structs.RouteParameters route_params, ChannelDetails[] first_hops, org.ldk.structs.InFlightHtlcs inflight_htlcs, byte[] _payment_hash, byte[] _payment_id) {
177                 long ret = bindings.Router_find_route_with_id(this.ptr, InternalUtils.check_arr_len(payer, 33), route_params == null ? 0 : route_params.ptr, first_hops != null ? InternalUtils.mapArray(first_hops, first_hops_conv_16 => first_hops_conv_16 == null ? 0 : first_hops_conv_16.ptr) : null, inflight_htlcs == null ? 0 : inflight_htlcs.ptr, InternalUtils.check_arr_len(_payment_hash, 32), InternalUtils.check_arr_len(_payment_id, 32));
178                 GC.KeepAlive(this);
179                 GC.KeepAlive(payer);
180                 GC.KeepAlive(route_params);
181                 GC.KeepAlive(first_hops);
182                 GC.KeepAlive(inflight_htlcs);
183                 GC.KeepAlive(_payment_hash);
184                 GC.KeepAlive(_payment_id);
185                 if (ret >= 0 && ret <= 4096) { return null; }
186                 Result_RouteLightningErrorZ ret_hu_conv = Result_RouteLightningErrorZ.constr_from_ptr(ret);
187                 if (this != null) { this.ptrs_to.AddLast(route_params); };
188                 if (first_hops != null) { foreach (ChannelDetails first_hops_conv_16 in first_hops) { if (this != null) { this.ptrs_to.AddLast(first_hops_conv_16); }; } };
189                 if (this != null) { this.ptrs_to.AddLast(inflight_htlcs); };
190                 return ret_hu_conv;
191         }
192
193         /**
194          * Lets the router know that payment through a specific path has failed.
195          */
196         public void notify_payment_path_failed(RouteHop[] path, long short_channel_id) {
197                 bindings.Router_notify_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);
198                 GC.KeepAlive(this);
199                 GC.KeepAlive(path);
200                 GC.KeepAlive(short_channel_id);
201                 foreach (RouteHop path_conv_10 in path) { if (this != null) { this.ptrs_to.AddLast(path_conv_10); }; };
202         }
203
204         /**
205          * Lets the router know that payment through a specific path was successful.
206          */
207         public void notify_payment_path_successful(RouteHop[] path) {
208                 bindings.Router_notify_payment_path_successful(this.ptr, path != null ? InternalUtils.mapArray(path, path_conv_10 => path_conv_10 == null ? 0 : path_conv_10.ptr) : null);
209                 GC.KeepAlive(this);
210                 GC.KeepAlive(path);
211                 foreach (RouteHop path_conv_10 in path) { if (this != null) { this.ptrs_to.AddLast(path_conv_10); }; };
212         }
213
214         /**
215          * Lets the router know that a payment probe was successful.
216          */
217         public void notify_payment_probe_successful(RouteHop[] path) {
218                 bindings.Router_notify_payment_probe_successful(this.ptr, path != null ? InternalUtils.mapArray(path, path_conv_10 => path_conv_10 == null ? 0 : path_conv_10.ptr) : null);
219                 GC.KeepAlive(this);
220                 GC.KeepAlive(path);
221                 foreach (RouteHop path_conv_10 in path) { if (this != null) { this.ptrs_to.AddLast(path_conv_10); }; };
222         }
223
224         /**
225          * Lets the router know that a payment probe failed.
226          */
227         public void notify_payment_probe_failed(RouteHop[] path, long short_channel_id) {
228                 bindings.Router_notify_payment_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);
229                 GC.KeepAlive(this);
230                 GC.KeepAlive(path);
231                 GC.KeepAlive(short_channel_id);
232                 foreach (RouteHop path_conv_10 in path) { if (this != null) { this.ptrs_to.AddLast(path_conv_10); }; };
233         }
234
235 }
236 } } }