7 namespace org { namespace ldk { namespace structs {
11 /** An implementation of Router */
12 public interface RouterInterface {
13 /**Finds a [`Route`] for a payment between the given `payer` and a payee.
15 * The `payee` and the payment's value are given in [`RouteParameters::payment_params`]
16 * and [`RouteParameters::final_value_msat`], respectively.
18 * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
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.
23 * The `payee` and the payment's value are given in [`RouteParameters::payment_params`]
24 * and [`RouteParameters::final_value_msat`], respectively.
26 * Includes a [`PaymentHash`] and a [`PaymentId`] to be able to correlate the request with a specific
29 * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
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 /**Creates [`BlindedPath`]s for payment to the `recipient` node. The channels in `first_hops`
33 * are assumed to be with the `recipient`'s peers. The payment secret and any constraints are
36 Result_CVec_C2Tuple_BlindedPayInfoBlindedPathZZNoneZ create_blinded_payment_paths(byte[] recipient, ChannelDetails[] first_hops, ReceiveTlvs tlvs, long amount_msats);
40 * A trait defining behavior for routing a payment.
42 public class Router : CommonBase {
43 internal bindings.LDKRouter bindings_instance;
44 internal long instance_idx;
46 internal Router(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
48 if (ptr != 0) { bindings.Router_free(ptr); }
51 private class LDKRouterHolder { internal Router held; }
52 private class LDKRouterImpl : bindings.LDKRouter {
53 internal LDKRouterImpl(RouterInterface arg, LDKRouterHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
54 private RouterInterface arg;
55 private LDKRouterHolder impl_holder;
56 public long find_route(long _payer, long _route_params, long _first_hops, long _inflight_htlcs) {
57 byte[] _payer_conv = InternalUtils.decodeUint8Array(_payer);
58 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); }
59 int _first_hops_conv_16_len = InternalUtils.getArrayLength(_first_hops);
60 ChannelDetails[] _first_hops_conv_16_arr = new ChannelDetails[_first_hops_conv_16_len];
61 if (_first_hops != null) {
62 for (int q = 0; q < _first_hops_conv_16_len; q++) {
63 long _first_hops_conv_16 = InternalUtils.getU64ArrayElem(_first_hops, q);
64 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); }
65 if (_first_hops_conv_16_hu_conv != null) { _first_hops_conv_16_hu_conv.ptrs_to.AddLast(this); };
66 _first_hops_conv_16_arr[q] = _first_hops_conv_16_hu_conv;
69 bindings.free_buffer(_first_hops);
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_conv, _route_params_hu_conv, _first_hops_conv_16_arr, _inflight_htlcs_hu_conv);
74 long result = ret.clone_ptr();
77 public long find_route_with_id(long _payer, long _route_params, long _first_hops, long _inflight_htlcs, long __payment_hash, long __payment_id) {
78 byte[] _payer_conv = InternalUtils.decodeUint8Array(_payer);
79 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); }
80 int _first_hops_conv_16_len = InternalUtils.getArrayLength(_first_hops);
81 ChannelDetails[] _first_hops_conv_16_arr = new ChannelDetails[_first_hops_conv_16_len];
82 if (_first_hops != null) {
83 for (int q = 0; q < _first_hops_conv_16_len; q++) {
84 long _first_hops_conv_16 = InternalUtils.getU64ArrayElem(_first_hops, q);
85 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); }
86 if (_first_hops_conv_16_hu_conv != null) { _first_hops_conv_16_hu_conv.ptrs_to.AddLast(this); };
87 _first_hops_conv_16_arr[q] = _first_hops_conv_16_hu_conv;
90 bindings.free_buffer(_first_hops);
91 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); }
92 if (_inflight_htlcs_hu_conv != null) { _inflight_htlcs_hu_conv.ptrs_to.AddLast(this); };
93 byte[] __payment_hash_conv = InternalUtils.decodeUint8Array(__payment_hash);
94 byte[] __payment_id_conv = InternalUtils.decodeUint8Array(__payment_id);
95 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);
97 long result = ret.clone_ptr();
100 public long create_blinded_payment_paths(long _recipient, long _first_hops, long _tlvs, long _amount_msats) {
101 byte[] _recipient_conv = InternalUtils.decodeUint8Array(_recipient);
102 int _first_hops_conv_16_len = InternalUtils.getArrayLength(_first_hops);
103 ChannelDetails[] _first_hops_conv_16_arr = new ChannelDetails[_first_hops_conv_16_len];
104 for (int q = 0; q < _first_hops_conv_16_len; q++) {
105 long _first_hops_conv_16 = InternalUtils.getU64ArrayElem(_first_hops, q);
106 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); }
107 if (_first_hops_conv_16_hu_conv != null) { _first_hops_conv_16_hu_conv.ptrs_to.AddLast(this); };
108 _first_hops_conv_16_arr[q] = _first_hops_conv_16_hu_conv;
110 bindings.free_buffer(_first_hops);
111 org.ldk.structs.ReceiveTlvs _tlvs_hu_conv = null; if (_tlvs < 0 || _tlvs > 4096) { _tlvs_hu_conv = new org.ldk.structs.ReceiveTlvs(null, _tlvs); }
112 if (_tlvs_hu_conv != null) { _tlvs_hu_conv.ptrs_to.AddLast(this); };
113 Result_CVec_C2Tuple_BlindedPayInfoBlindedPathZZNoneZ ret = arg.create_blinded_payment_paths(_recipient_conv, _first_hops_conv_16_arr, _tlvs_hu_conv, _amount_msats);
115 long result = ret.clone_ptr();
120 /** Creates a new instance of Router from a given implementation */
121 public static Router new_impl(RouterInterface arg, MessageRouterInterface messageRouter_impl) {
122 LDKRouterHolder impl_holder = new LDKRouterHolder();
123 LDKRouterImpl impl = new LDKRouterImpl(arg, impl_holder);
124 MessageRouter messageRouter = MessageRouter.new_impl(messageRouter_impl);
125 long[] ptr_idx = bindings.LDKRouter_new(impl, messageRouter.instance_idx);
127 impl_holder.held = new Router(null, ptr_idx[0]);
128 impl_holder.held.instance_idx = ptr_idx[1];
129 impl_holder.held.bindings_instance = impl;
130 impl_holder.held.ptrs_to.AddLast(messageRouter);
131 return impl_holder.held;
135 * Finds a [`Route`] for a payment between the given `payer` and a payee.
137 * The `payee` and the payment's value are given in [`RouteParameters::payment_params`]
138 * and [`RouteParameters::final_value_msat`], respectively.
140 * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
142 public Result_RouteLightningErrorZ find_route(byte[] payer, org.ldk.structs.RouteParameters route_params, ChannelDetails[] first_hops, org.ldk.structs.InFlightHtlcs inflight_htlcs) {
143 long ret = bindings.Router_find_route(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(payer, 33)), route_params.ptr, InternalUtils.encodeUint64Array(InternalUtils.mapArray(first_hops, first_hops_conv_16 => first_hops_conv_16.ptr)), inflight_htlcs.ptr);
146 GC.KeepAlive(route_params);
147 GC.KeepAlive(first_hops);
148 GC.KeepAlive(inflight_htlcs);
149 if (ret >= 0 && ret <= 4096) { return null; }
150 Result_RouteLightningErrorZ ret_hu_conv = Result_RouteLightningErrorZ.constr_from_ptr(ret);
151 if (this != null) { this.ptrs_to.AddLast(route_params); };
152 if (first_hops != null) { foreach (ChannelDetails first_hops_conv_16 in first_hops) { if (this != null) { this.ptrs_to.AddLast(first_hops_conv_16); }; } };
153 if (this != null) { this.ptrs_to.AddLast(inflight_htlcs); };
158 * Finds a [`Route`] for a payment between the given `payer` and a payee.
160 * The `payee` and the payment's value are given in [`RouteParameters::payment_params`]
161 * and [`RouteParameters::final_value_msat`], respectively.
163 * Includes a [`PaymentHash`] and a [`PaymentId`] to be able to correlate the request with a specific
166 * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
168 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) {
169 long ret = bindings.Router_find_route_with_id(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(payer, 33)), route_params.ptr, InternalUtils.encodeUint64Array(InternalUtils.mapArray(first_hops, first_hops_conv_16 => first_hops_conv_16.ptr)), inflight_htlcs.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(_payment_hash, 32)), InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(_payment_id, 32)));
172 GC.KeepAlive(route_params);
173 GC.KeepAlive(first_hops);
174 GC.KeepAlive(inflight_htlcs);
175 GC.KeepAlive(_payment_hash);
176 GC.KeepAlive(_payment_id);
177 if (ret >= 0 && ret <= 4096) { return null; }
178 Result_RouteLightningErrorZ ret_hu_conv = Result_RouteLightningErrorZ.constr_from_ptr(ret);
179 if (this != null) { this.ptrs_to.AddLast(route_params); };
180 if (first_hops != null) { foreach (ChannelDetails first_hops_conv_16 in first_hops) { if (this != null) { this.ptrs_to.AddLast(first_hops_conv_16); }; } };
181 if (this != null) { this.ptrs_to.AddLast(inflight_htlcs); };
186 * Creates [`BlindedPath`]s for payment to the `recipient` node. The channels in `first_hops`
187 * are assumed to be with the `recipient`'s peers. The payment secret and any constraints are
190 public Result_CVec_C2Tuple_BlindedPayInfoBlindedPathZZNoneZ create_blinded_payment_paths(byte[] recipient, ChannelDetails[] first_hops, org.ldk.structs.ReceiveTlvs tlvs, long amount_msats) {
191 long ret = bindings.Router_create_blinded_payment_paths(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(recipient, 33)), InternalUtils.encodeUint64Array(InternalUtils.mapArray(first_hops, first_hops_conv_16 => first_hops_conv_16.ptr)), tlvs.ptr, amount_msats);
193 GC.KeepAlive(recipient);
194 GC.KeepAlive(first_hops);
196 GC.KeepAlive(amount_msats);
197 if (ret >= 0 && ret <= 4096) { return null; }
198 Result_CVec_C2Tuple_BlindedPayInfoBlindedPathZZNoneZ ret_hu_conv = Result_CVec_C2Tuple_BlindedPayInfoBlindedPathZZNoneZ.constr_from_ptr(ret);
199 foreach (ChannelDetails first_hops_conv_16 in first_hops) { if (this != null) { this.ptrs_to.AddLast(first_hops_conv_16); }; };
200 if (this != null) { this.ptrs_to.AddLast(tlvs); };