Update auto-generated bindings to 0.0.103
[ldk-java] / src / main / java / org / ldk / structs / Payer.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
8
9 /**
10  * A trait defining behavior of an [`Invoice`] payer.
11  */
12 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
13 public class Payer extends CommonBase {
14         final bindings.LDKPayer bindings_instance;
15         Payer(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
16         private Payer(bindings.LDKPayer arg) {
17                 super(bindings.LDKPayer_new(arg));
18                 this.ptrs_to.add(arg);
19                 this.bindings_instance = arg;
20         }
21         @Override @SuppressWarnings("deprecation")
22         protected void finalize() throws Throwable {
23                 if (ptr != 0) { bindings.Payer_free(ptr); } super.finalize();
24         }
25
26         public static interface PayerInterface {
27                 /**
28                  * Returns the payer's node id.
29                  */
30                 byte[] node_id();
31                 /**
32                  * Returns the payer's channels.
33                  */
34                 ChannelDetails[] first_hops();
35                 /**
36                  * Sends a payment over the Lightning Network using the given [`Route`].
37                  * 
38                  * Note that payment_secret (or a relevant inner pointer) may be NULL or all-0s to represent None
39                  */
40                 Result_PaymentIdPaymentSendFailureZ send_payment(Route route, byte[] payment_hash, byte[] payment_secret);
41                 /**
42                  * Retries a failed payment path for the [`PaymentId`] using the given [`Route`].
43                  */
44                 Result_NonePaymentSendFailureZ retry_payment(Route route, byte[] payment_id);
45         }
46         private static class LDKPayerHolder { Payer held; }
47         public static Payer new_impl(PayerInterface arg) {
48                 final LDKPayerHolder impl_holder = new LDKPayerHolder();
49                 impl_holder.held = new Payer(new bindings.LDKPayer() {
50                         @Override public byte[] node_id() {
51                                 byte[] ret = arg.node_id();
52                                 return ret;
53                         }
54                         @Override public long[] first_hops() {
55                                 ChannelDetails[] ret = arg.first_hops();
56                                 long[] result = ret != null ? Arrays.stream(ret).mapToLong(ret_conv_16 -> ret_conv_16 == null ? 0 : ret_conv_16.ptr & ~1).toArray() : null;
57                                 return result;
58                         }
59                         @Override public long send_payment(long route, byte[] payment_hash, byte[] payment_secret) {
60                                 Route route_hu_conv = null; if (route < 0 || route > 4096) { route_hu_conv = new Route(null, route); }
61                                 Result_PaymentIdPaymentSendFailureZ ret = arg.send_payment(route_hu_conv, payment_hash, payment_secret);
62                                 long result = ret != null ? ret.ptr : 0;
63                                 return result;
64                         }
65                         @Override public long retry_payment(long route, byte[] payment_id) {
66                                 Route route_hu_conv = null; if (route < 0 || route > 4096) { route_hu_conv = new Route(null, route); }
67                                 Result_NonePaymentSendFailureZ ret = arg.retry_payment(route_hu_conv, payment_id);
68                                 long result = ret != null ? ret.ptr : 0;
69                                 return result;
70                         }
71                 });
72                 return impl_holder.held;
73         }
74         /**
75          * Returns the payer's node id.
76          */
77         public byte[] node_id() {
78                 byte[] ret = bindings.Payer_node_id(this.ptr);
79                 return ret;
80         }
81
82         /**
83          * Returns the payer's channels.
84          */
85         public ChannelDetails[] first_hops() {
86                 long[] ret = bindings.Payer_first_hops(this.ptr);
87                 ChannelDetails[] ret_conv_16_arr = new ChannelDetails[ret.length];
88                 for (int q = 0; q < ret.length; q++) {
89                         long ret_conv_16 = ret[q];
90                         ChannelDetails ret_conv_16_hu_conv = null; if (ret_conv_16 < 0 || ret_conv_16 > 4096) { ret_conv_16_hu_conv = new ChannelDetails(null, ret_conv_16); }
91                         ret_conv_16_hu_conv.ptrs_to.add(this);
92                         ret_conv_16_arr[q] = ret_conv_16_hu_conv;
93                 }
94                 return ret_conv_16_arr;
95         }
96
97         /**
98          * Sends a payment over the Lightning Network using the given [`Route`].
99          * 
100          * Note that payment_secret (or a relevant inner pointer) may be NULL or all-0s to represent None
101          */
102         public Result_PaymentIdPaymentSendFailureZ send_payment(Route route, byte[] payment_hash, @Nullable byte[] payment_secret) {
103                 long ret = bindings.Payer_send_payment(this.ptr, route == null ? 0 : route.ptr & ~1, payment_hash, payment_secret);
104                 if (ret >= 0 && ret <= 4096) { return null; }
105                 Result_PaymentIdPaymentSendFailureZ ret_hu_conv = Result_PaymentIdPaymentSendFailureZ.constr_from_ptr(ret);
106                 this.ptrs_to.add(route);
107                 return ret_hu_conv;
108         }
109
110         /**
111          * Retries a failed payment path for the [`PaymentId`] using the given [`Route`].
112          */
113         public Result_NonePaymentSendFailureZ retry_payment(Route route, byte[] payment_id) {
114                 long ret = bindings.Payer_retry_payment(this.ptr, route == null ? 0 : route.ptr & ~1, payment_id);
115                 if (ret >= 0 && ret <= 4096) { return null; }
116                 Result_NonePaymentSendFailureZ ret_hu_conv = Result_NonePaymentSendFailureZ.constr_from_ptr(ret);
117                 this.ptrs_to.add(route);
118                 return ret_hu_conv;
119         }
120
121 }