6 namespace org { namespace ldk { namespace structs {
9 * A trait defining behavior of an [`Invoice`] payer.
11 * While the behavior of [`InvoicePayer`] provides idempotency of duplicate `send_*payment` calls
12 * with the same [`PaymentHash`], it is up to the `Payer` to provide idempotency across restarts.
14 * [`ChannelManager`] provides idempotency for duplicate payments with the same [`PaymentId`].
16 * In order to trivially ensure idempotency for payments, the default `Payer` implementation
17 * reuses the [`PaymentHash`] bytes as the [`PaymentId`]. Custom implementations wishing to
18 * provide payment idempotency with a different idempotency key (i.e. [`PaymentId`]) should map
19 * the [`Invoice`] or spontaneous payment target pubkey to their own idempotency key.
21 * [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager
23 public class Payer : CommonBase {
24 internal readonly bindings.LDKPayer bindings_instance;
25 internal Payer(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
26 private Payer(bindings.LDKPayer arg) : base(bindings.LDKPayer_new(arg)) {
27 this.ptrs_to.AddLast(arg);
28 this.bindings_instance = arg;
31 if (ptr != 0) { bindings.Payer_free(ptr); }
34 public interface PayerInterface {
36 * Returns the payer's node id.
40 * Returns the payer's channels.
42 ChannelDetails[] first_hops();
44 * Sends a payment over the Lightning Network using the given [`Route`].
46 * Note that payment_secret (or a relevant inner pointer) may be NULL or all-0s to represent None
48 Result_NonePaymentSendFailureZ send_payment(Route _route, byte[] _payment_hash, byte[] _payment_secret, byte[] _payment_id);
50 * Sends a spontaneous payment over the Lightning Network using the given [`Route`].
52 Result_NonePaymentSendFailureZ send_spontaneous_payment(Route _route, byte[] _payment_preimage, byte[] _payment_id);
54 * Retries a failed payment path for the [`PaymentId`] using the given [`Route`].
56 Result_NonePaymentSendFailureZ retry_payment(Route _route, byte[] _payment_id);
58 * Signals that no further retries for the given payment will occur.
60 void abandon_payment(byte[] _payment_id);
62 * Construct an [`InFlightHtlcs`] containing information about currently used up liquidity
65 InFlightHtlcs inflight_htlcs();
67 private class LDKPayerHolder { internal Payer held; }
68 private class LDKPayerImpl : bindings.LDKPayer {
69 internal LDKPayerImpl(PayerInterface arg, LDKPayerHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
70 private PayerInterface arg;
71 private LDKPayerHolder impl_holder;
72 public byte[] node_id() {
73 byte[] ret = arg.node_id();
75 byte[] result = InternalUtils.check_arr_len(ret, 33);
78 public long[] first_hops() {
79 ChannelDetails[] ret = arg.first_hops();
81 long[] result = ret != null ? InternalUtils.mapArray(ret, ret_conv_16 => ret_conv_16 == null ? 0 : ret_conv_16.clone_ptr()) : null;
84 public long send_payment(long _route, byte[] _payment_hash, byte[] _payment_secret, byte[] _payment_id) {
85 org.ldk.structs.Route _route_hu_conv = null; if (_route < 0 || _route > 4096) { _route_hu_conv = new org.ldk.structs.Route(null, _route); }
86 Result_NonePaymentSendFailureZ ret = arg.send_payment(_route_hu_conv, _payment_hash, _payment_secret, _payment_id);
88 long result = ret == null ? 0 : ret.clone_ptr();
91 public long send_spontaneous_payment(long _route, byte[] _payment_preimage, byte[] _payment_id) {
92 org.ldk.structs.Route _route_hu_conv = null; if (_route < 0 || _route > 4096) { _route_hu_conv = new org.ldk.structs.Route(null, _route); }
93 Result_NonePaymentSendFailureZ ret = arg.send_spontaneous_payment(_route_hu_conv, _payment_preimage, _payment_id);
95 long result = ret == null ? 0 : ret.clone_ptr();
98 public long retry_payment(long _route, byte[] _payment_id) {
99 org.ldk.structs.Route _route_hu_conv = null; if (_route < 0 || _route > 4096) { _route_hu_conv = new org.ldk.structs.Route(null, _route); }
100 Result_NonePaymentSendFailureZ ret = arg.retry_payment(_route_hu_conv, _payment_id);
102 long result = ret == null ? 0 : ret.clone_ptr();
105 public void abandon_payment(byte[] _payment_id) {
106 arg.abandon_payment(_payment_id);
109 public long inflight_htlcs() {
110 InFlightHtlcs ret = arg.inflight_htlcs();
112 long result = ret == null ? 0 : ret.clone_ptr();
116 public static Payer new_impl(PayerInterface arg) {
117 LDKPayerHolder impl_holder = new LDKPayerHolder();
118 impl_holder.held = new Payer(new LDKPayerImpl(arg, impl_holder));
119 return impl_holder.held;
122 * Returns the payer's node id.
124 public byte[] node_id() {
125 byte[] ret = bindings.Payer_node_id(this.ptr);
131 * Returns the payer's channels.
133 public ChannelDetails[] first_hops() {
134 long[] ret = bindings.Payer_first_hops(this.ptr);
136 int ret_conv_16_len = ret.Length;
137 ChannelDetails[] ret_conv_16_arr = new ChannelDetails[ret_conv_16_len];
138 for (int q = 0; q < ret_conv_16_len; q++) {
139 long ret_conv_16 = ret[q];
140 org.ldk.structs.ChannelDetails ret_conv_16_hu_conv = null; if (ret_conv_16 < 0 || ret_conv_16 > 4096) { ret_conv_16_hu_conv = new org.ldk.structs.ChannelDetails(null, ret_conv_16); }
141 if (ret_conv_16_hu_conv != null) { ret_conv_16_hu_conv.ptrs_to.AddLast(this); };
142 ret_conv_16_arr[q] = ret_conv_16_hu_conv;
144 return ret_conv_16_arr;
148 * Sends a payment over the Lightning Network using the given [`Route`].
150 * Note that payment_secret (or a relevant inner pointer) may be NULL or all-0s to represent None
152 public Result_NonePaymentSendFailureZ send_payment(org.ldk.structs.Route route, byte[] payment_hash, byte[] payment_secret, byte[] payment_id) {
153 long ret = bindings.Payer_send_payment(this.ptr, route == null ? 0 : route.ptr, InternalUtils.check_arr_len(payment_hash, 32), InternalUtils.check_arr_len(payment_secret, 32), InternalUtils.check_arr_len(payment_id, 32));
156 GC.KeepAlive(payment_hash);
157 GC.KeepAlive(payment_secret);
158 GC.KeepAlive(payment_id);
159 if (ret >= 0 && ret <= 4096) { return null; }
160 Result_NonePaymentSendFailureZ ret_hu_conv = Result_NonePaymentSendFailureZ.constr_from_ptr(ret);
161 if (this != null) { this.ptrs_to.AddLast(route); };
166 * Sends a spontaneous payment over the Lightning Network using the given [`Route`].
168 public Result_NonePaymentSendFailureZ send_spontaneous_payment(org.ldk.structs.Route route, byte[] payment_preimage, byte[] payment_id) {
169 long ret = bindings.Payer_send_spontaneous_payment(this.ptr, route == null ? 0 : route.ptr, InternalUtils.check_arr_len(payment_preimage, 32), InternalUtils.check_arr_len(payment_id, 32));
172 GC.KeepAlive(payment_preimage);
173 GC.KeepAlive(payment_id);
174 if (ret >= 0 && ret <= 4096) { return null; }
175 Result_NonePaymentSendFailureZ ret_hu_conv = Result_NonePaymentSendFailureZ.constr_from_ptr(ret);
176 if (this != null) { this.ptrs_to.AddLast(route); };
181 * Retries a failed payment path for the [`PaymentId`] using the given [`Route`].
183 public Result_NonePaymentSendFailureZ retry_payment(org.ldk.structs.Route route, byte[] payment_id) {
184 long ret = bindings.Payer_retry_payment(this.ptr, route == null ? 0 : route.ptr, InternalUtils.check_arr_len(payment_id, 32));
187 GC.KeepAlive(payment_id);
188 if (ret >= 0 && ret <= 4096) { return null; }
189 Result_NonePaymentSendFailureZ ret_hu_conv = Result_NonePaymentSendFailureZ.constr_from_ptr(ret);
190 if (this != null) { this.ptrs_to.AddLast(route); };
195 * Signals that no further retries for the given payment will occur.
197 public void abandon_payment(byte[] payment_id) {
198 bindings.Payer_abandon_payment(this.ptr, InternalUtils.check_arr_len(payment_id, 32));
200 GC.KeepAlive(payment_id);
204 * Construct an [`InFlightHtlcs`] containing information about currently used up liquidity
207 public InFlightHtlcs inflight_htlcs() {
208 long ret = bindings.Payer_inflight_htlcs(this.ptr);
210 if (ret >= 0 && ret <= 4096) { return null; }
211 org.ldk.structs.InFlightHtlcs ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InFlightHtlcs(null, ret); }
212 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };