[Java] Update auto-generated Java bindings for 0.0.116
[ldk-java] / src / main / java / org / ldk / structs / RecipientOnionFields.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 java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * Information which is provided, encrypted, to the payment recipient when sending HTLCs.
13  * 
14  * This should generally be constructed with data communicated to us from the recipient (via a
15  * BOLT11 or BOLT12 invoice).
16  */
17 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
18 public class RecipientOnionFields extends CommonBase {
19         RecipientOnionFields(Object _dummy, long ptr) { super(ptr); }
20         @Override @SuppressWarnings("deprecation")
21         protected void finalize() throws Throwable {
22                 super.finalize();
23                 if (ptr != 0) { bindings.RecipientOnionFields_free(ptr); }
24         }
25
26         /**
27          * The [`PaymentSecret`] is an arbitrary 32 bytes provided by the recipient for us to repeat
28          * in the onion. It is unrelated to `payment_hash` (or [`PaymentPreimage`]) and exists to
29          * authenticate the sender to the recipient and prevent payment-probing (deanonymization)
30          * attacks.
31          * 
32          * If you do not have one, the [`Route`] you pay over must not contain multiple paths as
33          * multi-path payments require a recipient-provided secret.
34          * 
35          * Some implementations may reject spontaneous payments with payment secrets, so you may only
36          * want to provide a secret for a spontaneous payment if MPP is needed and you know your
37          * recipient will not reject it.
38          */
39         public Option_PaymentSecretZ get_payment_secret() {
40                 long ret = bindings.RecipientOnionFields_get_payment_secret(this.ptr);
41                 Reference.reachabilityFence(this);
42                 if (ret >= 0 && ret <= 4096) { return null; }
43                 org.ldk.structs.Option_PaymentSecretZ ret_hu_conv = org.ldk.structs.Option_PaymentSecretZ.constr_from_ptr(ret);
44                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
45                 return ret_hu_conv;
46         }
47
48         /**
49          * The [`PaymentSecret`] is an arbitrary 32 bytes provided by the recipient for us to repeat
50          * in the onion. It is unrelated to `payment_hash` (or [`PaymentPreimage`]) and exists to
51          * authenticate the sender to the recipient and prevent payment-probing (deanonymization)
52          * attacks.
53          * 
54          * If you do not have one, the [`Route`] you pay over must not contain multiple paths as
55          * multi-path payments require a recipient-provided secret.
56          * 
57          * Some implementations may reject spontaneous payments with payment secrets, so you may only
58          * want to provide a secret for a spontaneous payment if MPP is needed and you know your
59          * recipient will not reject it.
60          */
61         public void set_payment_secret(org.ldk.structs.Option_PaymentSecretZ val) {
62                 bindings.RecipientOnionFields_set_payment_secret(this.ptr, val.ptr);
63                 Reference.reachabilityFence(this);
64                 Reference.reachabilityFence(val);
65                 if (this != null) { this.ptrs_to.add(val); };
66         }
67
68         /**
69          * The payment metadata serves a similar purpose as [`Self::payment_secret`] but is of
70          * arbitrary length. This gives recipients substantially more flexibility to receive
71          * additional data.
72          * 
73          * In LDK, while the [`Self::payment_secret`] is fixed based on an internal authentication
74          * scheme to authenticate received payments against expected payments and invoices, this field
75          * is not used in LDK for received payments, and can be used to store arbitrary data in
76          * invoices which will be received with the payment.
77          * 
78          * Note that this field was added to the lightning specification more recently than
79          * [`Self::payment_secret`] and while nearly all lightning senders support secrets, metadata
80          * may not be supported as universally.
81          * 
82          * Returns a copy of the field.
83          */
84         public Option_CVec_u8ZZ get_payment_metadata() {
85                 long ret = bindings.RecipientOnionFields_get_payment_metadata(this.ptr);
86                 Reference.reachabilityFence(this);
87                 if (ret >= 0 && ret <= 4096) { return null; }
88                 org.ldk.structs.Option_CVec_u8ZZ ret_hu_conv = org.ldk.structs.Option_CVec_u8ZZ.constr_from_ptr(ret);
89                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
90                 return ret_hu_conv;
91         }
92
93         /**
94          * The payment metadata serves a similar purpose as [`Self::payment_secret`] but is of
95          * arbitrary length. This gives recipients substantially more flexibility to receive
96          * additional data.
97          * 
98          * In LDK, while the [`Self::payment_secret`] is fixed based on an internal authentication
99          * scheme to authenticate received payments against expected payments and invoices, this field
100          * is not used in LDK for received payments, and can be used to store arbitrary data in
101          * invoices which will be received with the payment.
102          * 
103          * Note that this field was added to the lightning specification more recently than
104          * [`Self::payment_secret`] and while nearly all lightning senders support secrets, metadata
105          * may not be supported as universally.
106          */
107         public void set_payment_metadata(org.ldk.structs.Option_CVec_u8ZZ val) {
108                 bindings.RecipientOnionFields_set_payment_metadata(this.ptr, val.ptr);
109                 Reference.reachabilityFence(this);
110                 Reference.reachabilityFence(val);
111                 if (this != null) { this.ptrs_to.add(val); };
112         }
113
114         /**
115          * Constructs a new RecipientOnionFields given each field
116          */
117         public static RecipientOnionFields of(org.ldk.structs.Option_PaymentSecretZ payment_secret_arg, org.ldk.structs.Option_CVec_u8ZZ payment_metadata_arg) {
118                 long ret = bindings.RecipientOnionFields_new(payment_secret_arg.ptr, payment_metadata_arg.ptr);
119                 Reference.reachabilityFence(payment_secret_arg);
120                 Reference.reachabilityFence(payment_metadata_arg);
121                 if (ret >= 0 && ret <= 4096) { return null; }
122                 org.ldk.structs.RecipientOnionFields ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RecipientOnionFields(null, ret); }
123                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
124                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(payment_secret_arg); };
125                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(payment_metadata_arg); };
126                 return ret_hu_conv;
127         }
128
129         long clone_ptr() {
130                 long ret = bindings.RecipientOnionFields_clone_ptr(this.ptr);
131                 Reference.reachabilityFence(this);
132                 return ret;
133         }
134
135         /**
136          * Creates a copy of the RecipientOnionFields
137          */
138         public RecipientOnionFields clone() {
139                 long ret = bindings.RecipientOnionFields_clone(this.ptr);
140                 Reference.reachabilityFence(this);
141                 if (ret >= 0 && ret <= 4096) { return null; }
142                 org.ldk.structs.RecipientOnionFields ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RecipientOnionFields(null, ret); }
143                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
144                 return ret_hu_conv;
145         }
146
147         /**
148          * Checks if two RecipientOnionFieldss contain equal inner contents.
149          * This ignores pointers and is_owned flags and looks at the values in fields.
150          * Two objects with NULL inner values will be considered "equal" here.
151          */
152         public boolean eq(org.ldk.structs.RecipientOnionFields b) {
153                 boolean ret = bindings.RecipientOnionFields_eq(this.ptr, b == null ? 0 : b.ptr);
154                 Reference.reachabilityFence(this);
155                 Reference.reachabilityFence(b);
156                 if (this != null) { this.ptrs_to.add(b); };
157                 return ret;
158         }
159
160         @Override public boolean equals(Object o) {
161                 if (!(o instanceof RecipientOnionFields)) return false;
162                 return this.eq((RecipientOnionFields)o);
163         }
164         /**
165          * Serialize the RecipientOnionFields object into a byte array which can be read by RecipientOnionFields_read
166          */
167         public byte[] write() {
168                 byte[] ret = bindings.RecipientOnionFields_write(this.ptr);
169                 Reference.reachabilityFence(this);
170                 return ret;
171         }
172
173         /**
174          * Read a RecipientOnionFields from a byte array, created by RecipientOnionFields_write
175          */
176         public static Result_RecipientOnionFieldsDecodeErrorZ read(byte[] ser) {
177                 long ret = bindings.RecipientOnionFields_read(ser);
178                 Reference.reachabilityFence(ser);
179                 if (ret >= 0 && ret <= 4096) { return null; }
180                 Result_RecipientOnionFieldsDecodeErrorZ ret_hu_conv = Result_RecipientOnionFieldsDecodeErrorZ.constr_from_ptr(ret);
181                 return ret_hu_conv;
182         }
183
184         /**
185          * Creates a [`RecipientOnionFields`] from only a [`PaymentSecret`]. This is the most common
186          * set of onion fields for today's BOLT11 invoices - most nodes require a [`PaymentSecret`]
187          * but do not require or provide any further data.
188          */
189         public static RecipientOnionFields secret_only(byte[] payment_secret) {
190                 long ret = bindings.RecipientOnionFields_secret_only(InternalUtils.check_arr_len(payment_secret, 32));
191                 Reference.reachabilityFence(payment_secret);
192                 if (ret >= 0 && ret <= 4096) { return null; }
193                 org.ldk.structs.RecipientOnionFields ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RecipientOnionFields(null, ret); }
194                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
195                 return ret_hu_conv;
196         }
197
198         /**
199          * Creates a new [`RecipientOnionFields`] with no fields. This generally does not create
200          * payable HTLCs except for single-path spontaneous payments, i.e. this should generally
201          * only be used for calls to [`ChannelManager::send_spontaneous_payment`]. If you are sending
202          * a spontaneous MPP this will not work as all MPP require payment secrets; you may
203          * instead want to use [`RecipientOnionFields::secret_only`].
204          * 
205          * [`ChannelManager::send_spontaneous_payment`]: super::channelmanager::ChannelManager::send_spontaneous_payment
206          * [`RecipientOnionFields::secret_only`]: RecipientOnionFields::secret_only
207          */
208         public static RecipientOnionFields spontaneous_empty() {
209                 long ret = bindings.RecipientOnionFields_spontaneous_empty();
210                 if (ret >= 0 && ret <= 4096) { return null; }
211                 org.ldk.structs.RecipientOnionFields ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RecipientOnionFields(null, ret); }
212                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
213                 return ret_hu_conv;
214         }
215
216 }