a8dbb2a54f6eb012bdabfbb1bb7896585367436f
[ldk-java] / c_sharp / src / org / ldk / structs / Router.cs
1
2 using org.ldk.impl;
3 using org.ldk.enums;
4 using org.ldk.util;
5 using System;
6
7 namespace org { namespace ldk { namespace structs {
8
9
10
11 /** An implementation of Router */
12 public interface RouterInterface {
13         /**Finds a [`Route`] for a payment between the given `payer` and a payee.
14          * 
15          * The `payee` and the payment's value are given in [`RouteParameters::payment_params`]
16          * and [`RouteParameters::final_value_msat`], respectively.
17          * 
18          * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
19          */
20         Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters route_params, ChannelDetails[] first_hops, InFlightHtlcs inflight_htlcs);
21         /**Finds a [`Route`] for a payment between the given `payer` and a payee.
22          * 
23          * The `payee` and the payment's value are given in [`RouteParameters::payment_params`]
24          * and [`RouteParameters::final_value_msat`], respectively.
25          * 
26          * Includes a [`PaymentHash`] and a [`PaymentId`] to be able to correlate the request with a specific
27          * payment.
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_with_id(byte[] payer, RouteParameters route_params, ChannelDetails[] first_hops, InFlightHtlcs inflight_htlcs, byte[] _payment_hash, byte[] _payment_id);
32 }
33
34 /**
35  * A trait defining behavior for routing a payment.
36  */
37 public class Router : CommonBase {
38         internal bindings.LDKRouter bindings_instance;
39         internal long instance_idx;
40
41         internal Router(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
42         ~Router() {
43                 if (ptr != 0) { bindings.Router_free(ptr); }
44         }
45
46         private class LDKRouterHolder { internal Router held; }
47         private class LDKRouterImpl : bindings.LDKRouter {
48                 internal LDKRouterImpl(RouterInterface arg, LDKRouterHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
49                 private RouterInterface arg;
50                 private LDKRouterHolder impl_holder;
51                 public long find_route(long _payer, long _route_params, long _first_hops, long _inflight_htlcs) {
52                         byte[] _payer_conv = InternalUtils.decodeUint8Array(_payer);
53                         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); }
54                         int _first_hops_conv_16_len = InternalUtils.getArrayLength(_first_hops);
55                         ChannelDetails[] _first_hops_conv_16_arr = new ChannelDetails[_first_hops_conv_16_len];
56                         if (_first_hops != null) {
57                                 for (int q = 0; q < _first_hops_conv_16_len; q++) {
58                                         long _first_hops_conv_16 = InternalUtils.getU64ArrayElem(_first_hops, q);
59                                         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); }
60                                         if (_first_hops_conv_16_hu_conv != null) { _first_hops_conv_16_hu_conv.ptrs_to.AddLast(this); };
61                                         _first_hops_conv_16_arr[q] = _first_hops_conv_16_hu_conv;
62                                 }
63                         }
64                         bindings.free_buffer(_first_hops);
65                         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); }
66                         if (_inflight_htlcs_hu_conv != null) { _inflight_htlcs_hu_conv.ptrs_to.AddLast(this); };
67                         Result_RouteLightningErrorZ ret = arg.find_route(_payer_conv, _route_params_hu_conv, _first_hops_conv_16_arr, _inflight_htlcs_hu_conv);
68                                 GC.KeepAlive(arg);
69                         long result = ret == null ? 0 : ret.clone_ptr();
70                         return result;
71                 }
72                 public long find_route_with_id(long _payer, long _route_params, long _first_hops, long _inflight_htlcs, long __payment_hash, long __payment_id) {
73                         byte[] _payer_conv = InternalUtils.decodeUint8Array(_payer);
74                         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); }
75                         int _first_hops_conv_16_len = InternalUtils.getArrayLength(_first_hops);
76                         ChannelDetails[] _first_hops_conv_16_arr = new ChannelDetails[_first_hops_conv_16_len];
77                         if (_first_hops != null) {
78                                 for (int q = 0; q < _first_hops_conv_16_len; q++) {
79                                         long _first_hops_conv_16 = InternalUtils.getU64ArrayElem(_first_hops, q);
80                                         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); }
81                                         if (_first_hops_conv_16_hu_conv != null) { _first_hops_conv_16_hu_conv.ptrs_to.AddLast(this); };
82                                         _first_hops_conv_16_arr[q] = _first_hops_conv_16_hu_conv;
83                                 }
84                         }
85                         bindings.free_buffer(_first_hops);
86                         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); }
87                         if (_inflight_htlcs_hu_conv != null) { _inflight_htlcs_hu_conv.ptrs_to.AddLast(this); };
88                         byte[] __payment_hash_conv = InternalUtils.decodeUint8Array(__payment_hash);
89                         byte[] __payment_id_conv = InternalUtils.decodeUint8Array(__payment_id);
90                         Result_RouteLightningErrorZ ret = arg.find_route_with_id(_payer_conv, _route_params_hu_conv, _first_hops_conv_16_arr, _inflight_htlcs_hu_conv, __payment_hash_conv, __payment_id_conv);
91                                 GC.KeepAlive(arg);
92                         long result = ret == null ? 0 : ret.clone_ptr();
93                         return result;
94                 }
95         }
96
97         /** Creates a new instance of Router from a given implementation */
98         public static Router new_impl(RouterInterface arg) {
99                 LDKRouterHolder impl_holder = new LDKRouterHolder();
100                 LDKRouterImpl impl = new LDKRouterImpl(arg, impl_holder);
101                 long[] ptr_idx = bindings.LDKRouter_new(impl);
102
103                 impl_holder.held = new Router(null, ptr_idx[0]);
104                 impl_holder.held.instance_idx = ptr_idx[1];
105                 impl_holder.held.bindings_instance = impl;
106                 return impl_holder.held;
107         }
108
109         /**
110          * Finds a [`Route`] for a payment between the given `payer` and a payee.
111          * 
112          * The `payee` and the payment's value are given in [`RouteParameters::payment_params`]
113          * and [`RouteParameters::final_value_msat`], respectively.
114          * 
115          * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
116          */
117         public Result_RouteLightningErrorZ find_route(byte[] payer, org.ldk.structs.RouteParameters route_params, ChannelDetails[] first_hops, org.ldk.structs.InFlightHtlcs inflight_htlcs) {
118                 long ret = bindings.Router_find_route(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(payer, 33)), route_params == null ? 0 : route_params.ptr, InternalUtils.encodeUint64Array(InternalUtils.mapArray(first_hops, first_hops_conv_16 => first_hops_conv_16 == null ? 0 : first_hops_conv_16.ptr)), inflight_htlcs == null ? 0 : inflight_htlcs.ptr);
119                 GC.KeepAlive(this);
120                 GC.KeepAlive(payer);
121                 GC.KeepAlive(route_params);
122                 GC.KeepAlive(first_hops);
123                 GC.KeepAlive(inflight_htlcs);
124                 if (ret >= 0 && ret <= 4096) { return null; }
125                 Result_RouteLightningErrorZ ret_hu_conv = Result_RouteLightningErrorZ.constr_from_ptr(ret);
126                 if (this != null) { this.ptrs_to.AddLast(route_params); };
127                 if (first_hops != null) { foreach (ChannelDetails first_hops_conv_16 in first_hops) { if (this != null) { this.ptrs_to.AddLast(first_hops_conv_16); }; } };
128                 if (this != null) { this.ptrs_to.AddLast(inflight_htlcs); };
129                 return ret_hu_conv;
130         }
131
132         /**
133          * Finds a [`Route`] for a payment between the given `payer` and a payee.
134          * 
135          * The `payee` and the payment's value are given in [`RouteParameters::payment_params`]
136          * and [`RouteParameters::final_value_msat`], respectively.
137          * 
138          * Includes a [`PaymentHash`] and a [`PaymentId`] to be able to correlate the request with a specific
139          * payment.
140          * 
141          * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
142          */
143         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) {
144                 long ret = bindings.Router_find_route_with_id(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(payer, 33)), route_params == null ? 0 : route_params.ptr, InternalUtils.encodeUint64Array(InternalUtils.mapArray(first_hops, first_hops_conv_16 => first_hops_conv_16 == null ? 0 : first_hops_conv_16.ptr)), inflight_htlcs == null ? 0 : inflight_htlcs.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(_payment_hash, 32)), InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(_payment_id, 32)));
145                 GC.KeepAlive(this);
146                 GC.KeepAlive(payer);
147                 GC.KeepAlive(route_params);
148                 GC.KeepAlive(first_hops);
149                 GC.KeepAlive(inflight_htlcs);
150                 GC.KeepAlive(_payment_hash);
151                 GC.KeepAlive(_payment_id);
152                 if (ret >= 0 && ret <= 4096) { return null; }
153                 Result_RouteLightningErrorZ ret_hu_conv = Result_RouteLightningErrorZ.constr_from_ptr(ret);
154                 if (this != null) { this.ptrs_to.AddLast(route_params); };
155                 if (first_hops != null) { foreach (ChannelDetails first_hops_conv_16 in first_hops) { if (this != null) { this.ptrs_to.AddLast(first_hops_conv_16); }; } };
156                 if (this != null) { this.ptrs_to.AddLast(inflight_htlcs); };
157                 return ret_hu_conv;
158         }
159
160 }
161 } } }