32c60514176fb7661143bb71420ec87310ca8d69
[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`] for a payment between the given `payer` and a payee.
25                  * 
26                  * The `payee` and the payment's value are given in [`RouteParameters::payment_params`]
27                  * and [`RouteParameters::final_value_msat`], respectively.
28                  * 
29                  * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
30                  */
31                 Result_RouteLightningErrorZ find_route(byte[] _payer, RouteParameters _route_params, ChannelDetails[] _first_hops, InFlightHtlcs _inflight_htlcs);
32                 /**
33                  * Finds a [`Route`] for a payment between the given `payer` and a payee.
34                  * 
35                  * The `payee` and the payment's value are given in [`RouteParameters::payment_params`]
36                  * and [`RouteParameters::final_value_msat`], respectively.
37                  * 
38                  * Includes a [`PaymentHash`] and a [`PaymentId`] to be able to correlate the request with a specific
39                  * payment.
40                  * 
41                  * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
42                  */
43                 Result_RouteLightningErrorZ find_route_with_id(byte[] _payer, RouteParameters _route_params, ChannelDetails[] _first_hops, InFlightHtlcs _inflight_htlcs, byte[] __payment_hash, byte[] __payment_id);
44         }
45         private class LDKRouterHolder { internal Router held; }
46         private class LDKRouterImpl : bindings.LDKRouter {
47                 internal LDKRouterImpl(RouterInterface arg, LDKRouterHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
48                 private RouterInterface arg;
49                 private LDKRouterHolder impl_holder;
50                 public long find_route(byte[] _payer, long _route_params, long[] _first_hops, long _inflight_htlcs) {
51                         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); }
52                         int _first_hops_conv_16_len = _first_hops.Length;
53                         ChannelDetails[] _first_hops_conv_16_arr = new ChannelDetails[_first_hops_conv_16_len];
54                         if (_first_hops != null) {
55                                 for (int q = 0; q < _first_hops_conv_16_len; q++) {
56                                         long _first_hops_conv_16 = _first_hops[q];
57                                         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); }
58                                         if (_first_hops_conv_16_hu_conv != null) { _first_hops_conv_16_hu_conv.ptrs_to.AddLast(this); };
59                                         _first_hops_conv_16_arr[q] = _first_hops_conv_16_hu_conv;
60                                 }
61                         }
62                         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); }
63                         if (_inflight_htlcs_hu_conv != null) { _inflight_htlcs_hu_conv.ptrs_to.AddLast(this); };
64                         Result_RouteLightningErrorZ ret = arg.find_route(_payer, _route_params_hu_conv, _first_hops_conv_16_arr, _inflight_htlcs_hu_conv);
65                                 GC.KeepAlive(arg);
66                         long result = ret == null ? 0 : ret.clone_ptr();
67                         return result;
68                 }
69                 public long find_route_with_id(byte[] _payer, long _route_params, long[] _first_hops, long _inflight_htlcs, byte[] __payment_hash, byte[] __payment_id) {
70                         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); }
71                         int _first_hops_conv_16_len = _first_hops.Length;
72                         ChannelDetails[] _first_hops_conv_16_arr = new ChannelDetails[_first_hops_conv_16_len];
73                         if (_first_hops != null) {
74                                 for (int q = 0; q < _first_hops_conv_16_len; q++) {
75                                         long _first_hops_conv_16 = _first_hops[q];
76                                         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); }
77                                         if (_first_hops_conv_16_hu_conv != null) { _first_hops_conv_16_hu_conv.ptrs_to.AddLast(this); };
78                                         _first_hops_conv_16_arr[q] = _first_hops_conv_16_hu_conv;
79                                 }
80                         }
81                         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); }
82                         if (_inflight_htlcs_hu_conv != null) { _inflight_htlcs_hu_conv.ptrs_to.AddLast(this); };
83                         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);
84                                 GC.KeepAlive(arg);
85                         long result = ret == null ? 0 : ret.clone_ptr();
86                         return result;
87                 }
88         }
89         public static Router new_impl(RouterInterface arg) {
90                 LDKRouterHolder impl_holder = new LDKRouterHolder();
91                 impl_holder.held = new Router(new LDKRouterImpl(arg, impl_holder));
92                 return impl_holder.held;
93         }
94         /**
95          * Finds a [`Route`] for a payment between the given `payer` and a payee.
96          * 
97          * The `payee` and the payment's value are given in [`RouteParameters::payment_params`]
98          * and [`RouteParameters::final_value_msat`], respectively.
99          * 
100          * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
101          */
102         public Result_RouteLightningErrorZ find_route(byte[] payer, org.ldk.structs.RouteParameters route_params, ChannelDetails[] first_hops, org.ldk.structs.InFlightHtlcs inflight_htlcs) {
103                 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);
104                 GC.KeepAlive(this);
105                 GC.KeepAlive(payer);
106                 GC.KeepAlive(route_params);
107                 GC.KeepAlive(first_hops);
108                 GC.KeepAlive(inflight_htlcs);
109                 if (ret >= 0 && ret <= 4096) { return null; }
110                 Result_RouteLightningErrorZ ret_hu_conv = Result_RouteLightningErrorZ.constr_from_ptr(ret);
111                 if (this != null) { this.ptrs_to.AddLast(route_params); };
112                 if (first_hops != null) { foreach (ChannelDetails first_hops_conv_16 in first_hops) { if (this != null) { this.ptrs_to.AddLast(first_hops_conv_16); }; } };
113                 if (this != null) { this.ptrs_to.AddLast(inflight_htlcs); };
114                 return ret_hu_conv;
115         }
116
117         /**
118          * Finds a [`Route`] for a payment between the given `payer` and a payee.
119          * 
120          * The `payee` and the payment's value are given in [`RouteParameters::payment_params`]
121          * and [`RouteParameters::final_value_msat`], respectively.
122          * 
123          * Includes a [`PaymentHash`] and a [`PaymentId`] to be able to correlate the request with a specific
124          * payment.
125          * 
126          * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
127          */
128         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) {
129                 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));
130                 GC.KeepAlive(this);
131                 GC.KeepAlive(payer);
132                 GC.KeepAlive(route_params);
133                 GC.KeepAlive(first_hops);
134                 GC.KeepAlive(inflight_htlcs);
135                 GC.KeepAlive(_payment_hash);
136                 GC.KeepAlive(_payment_id);
137                 if (ret >= 0 && ret <= 4096) { return null; }
138                 Result_RouteLightningErrorZ ret_hu_conv = Result_RouteLightningErrorZ.constr_from_ptr(ret);
139                 if (this != null) { this.ptrs_to.AddLast(route_params); };
140                 if (first_hops != null) { foreach (ChannelDetails first_hops_conv_16 in first_hops) { if (this != null) { this.ptrs_to.AddLast(first_hops_conv_16); }; } };
141                 if (this != null) { this.ptrs_to.AddLast(inflight_htlcs); };
142                 return ret_hu_conv;
143         }
144
145 }
146 } } }