Update auto-generated bindings to latest upstream
[ldk-java] / src / main / java / org / ldk / structs / Event.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 /**
11  * An Event which you should probably take some action in response to.
12  * 
13  * Note that while Writeable and Readable are implemented for Event, you probably shouldn't use
14  * them directly as they don't round-trip exactly (for example FundingGenerationReady is never
15  * written as it makes no sense to respond to it after reconnecting to peers).
16  */
17 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
18 public class Event extends CommonBase {
19         private Event(Object _dummy, long ptr) { super(ptr); }
20         @Override @SuppressWarnings("deprecation")
21         protected void finalize() throws Throwable {
22                 super.finalize();
23                 if (ptr != 0) { bindings.Event_free(ptr); }
24         }
25         static Event constr_from_ptr(long ptr) {
26                 bindings.LDKEvent raw_val = bindings.LDKEvent_ref_from_ptr(ptr);
27                 if (raw_val.getClass() == bindings.LDKEvent.FundingGenerationReady.class) {
28                         return new FundingGenerationReady(ptr, (bindings.LDKEvent.FundingGenerationReady)raw_val);
29                 }
30                 if (raw_val.getClass() == bindings.LDKEvent.PaymentReceived.class) {
31                         return new PaymentReceived(ptr, (bindings.LDKEvent.PaymentReceived)raw_val);
32                 }
33                 if (raw_val.getClass() == bindings.LDKEvent.PaymentSent.class) {
34                         return new PaymentSent(ptr, (bindings.LDKEvent.PaymentSent)raw_val);
35                 }
36                 if (raw_val.getClass() == bindings.LDKEvent.PaymentFailed.class) {
37                         return new PaymentFailed(ptr, (bindings.LDKEvent.PaymentFailed)raw_val);
38                 }
39                 if (raw_val.getClass() == bindings.LDKEvent.PendingHTLCsForwardable.class) {
40                         return new PendingHTLCsForwardable(ptr, (bindings.LDKEvent.PendingHTLCsForwardable)raw_val);
41                 }
42                 if (raw_val.getClass() == bindings.LDKEvent.SpendableOutputs.class) {
43                         return new SpendableOutputs(ptr, (bindings.LDKEvent.SpendableOutputs)raw_val);
44                 }
45                 assert false; return null; // Unreachable without extending the (internal) bindings interface
46         }
47
48         public final static class FundingGenerationReady extends Event {
49                 /**
50                  * The random channel_id we picked which you'll need to pass into
51                  * ChannelManager::funding_transaction_generated.
52                 */
53                 public final byte[] temporary_channel_id;
54                 /**
55                  * The value, in satoshis, that the output should have.
56                 */
57                 public final long channel_value_satoshis;
58                 /**
59                  * The script which should be used in the transaction output.
60                 */
61                 public final byte[] output_script;
62                 /**
63                  * The value passed in to ChannelManager::create_channel
64                 */
65                 public final long user_channel_id;
66                 private FundingGenerationReady(long ptr, bindings.LDKEvent.FundingGenerationReady obj) {
67                         super(null, ptr);
68                         this.temporary_channel_id = obj.temporary_channel_id;
69                         this.channel_value_satoshis = obj.channel_value_satoshis;
70                         this.output_script = obj.output_script;
71                         this.user_channel_id = obj.user_channel_id;
72                 }
73         }
74         public final static class PaymentReceived extends Event {
75                 /**
76                  * The hash for which the preimage should be handed to the ChannelManager.
77                 */
78                 public final byte[] payment_hash;
79                 /**
80                  * The preimage to the payment_hash, if the payment hash (and secret) were fetched via
81                  * [`ChannelManager::create_inbound_payment`]. If provided, this can be handed directly to
82                  * [`ChannelManager::claim_funds`].
83                  * 
84                  * [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
85                  * [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
86                  * 
87                  * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
88                 */
89                 @Nullable public final byte[] payment_preimage;
90                 /**
91                  * The \"payment secret\". This authenticates the sender to the recipient, preventing a
92                  * number of deanonymization attacks during the routing process.
93                  * It is provided here for your reference, however its accuracy is enforced directly by
94                  * [`ChannelManager`] using the values you previously provided to
95                  * [`ChannelManager::create_inbound_payment`] or
96                  * [`ChannelManager::create_inbound_payment_for_hash`].
97                  * 
98                  * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
99                  * [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
100                  * [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
101                 */
102                 public final byte[] payment_secret;
103                 /**
104                  * The value, in thousandths of a satoshi, that this payment is for. Note that you must
105                  * compare this to the expected value before accepting the payment (as otherwise you are
106                  * providing proof-of-payment for less than the value you expected!).
107                 */
108                 public final long amt;
109                 /**
110                  * This is the `user_payment_id` which was provided to
111                  * [`ChannelManager::create_inbound_payment_for_hash`] or
112                  * [`ChannelManager::create_inbound_payment`]. It has no meaning inside of LDK and is
113                  * simply copied here. It may be used to correlate PaymentReceived events with invoice
114                  * metadata stored elsewhere.
115                  * 
116                  * [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
117                  * [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
118                 */
119                 public final long user_payment_id;
120                 private PaymentReceived(long ptr, bindings.LDKEvent.PaymentReceived obj) {
121                         super(null, ptr);
122                         this.payment_hash = obj.payment_hash;
123                         this.payment_preimage = obj.payment_preimage;
124                         this.payment_secret = obj.payment_secret;
125                         this.amt = obj.amt;
126                         this.user_payment_id = obj.user_payment_id;
127                 }
128         }
129         public final static class PaymentSent extends Event {
130                 /**
131                  * The preimage to the hash given to ChannelManager::send_payment.
132                  * Note that this serves as a payment receipt, if you wish to have such a thing, you must
133                  * store it somehow!
134                 */
135                 public final byte[] payment_preimage;
136                 private PaymentSent(long ptr, bindings.LDKEvent.PaymentSent obj) {
137                         super(null, ptr);
138                         this.payment_preimage = obj.payment_preimage;
139                 }
140         }
141         public final static class PaymentFailed extends Event {
142                 /**
143                  * The hash which was given to ChannelManager::send_payment.
144                 */
145                 public final byte[] payment_hash;
146                 /**
147                  * Indicates the payment was rejected for some reason by the recipient. This implies that
148                  * the payment has failed, not just the route in question. If this is not set, you may
149                  * retry the payment via a different route.
150                 */
151                 public final boolean rejected_by_dest;
152                 private PaymentFailed(long ptr, bindings.LDKEvent.PaymentFailed obj) {
153                         super(null, ptr);
154                         this.payment_hash = obj.payment_hash;
155                         this.rejected_by_dest = obj.rejected_by_dest;
156                 }
157         }
158         public final static class PendingHTLCsForwardable extends Event {
159                 /**
160                  * The minimum amount of time that should be waited prior to calling
161                  * process_pending_htlc_forwards. To increase the effort required to correlate payments,
162                  * you should wait a random amount of time in roughly the range (now + time_forwardable,
163                  * now + 5*time_forwardable).
164                 */
165                 public final long time_forwardable;
166                 private PendingHTLCsForwardable(long ptr, bindings.LDKEvent.PendingHTLCsForwardable obj) {
167                         super(null, ptr);
168                         this.time_forwardable = obj.time_forwardable;
169                 }
170         }
171         public final static class SpendableOutputs extends Event {
172                 /**
173                  * The outputs which you should store as spendable by you.
174                 */
175                 public final SpendableOutputDescriptor[] outputs;
176                 private SpendableOutputs(long ptr, bindings.LDKEvent.SpendableOutputs obj) {
177                         super(null, ptr);
178                         long[] outputs = obj.outputs;
179                         SpendableOutputDescriptor[] outputs_conv_27_arr = new SpendableOutputDescriptor[outputs.length];
180                         for (int b = 0; b < outputs.length; b++) {
181                                 long outputs_conv_27 = outputs[b];
182                                 SpendableOutputDescriptor outputs_conv_27_hu_conv = SpendableOutputDescriptor.constr_from_ptr(outputs_conv_27);
183                                 outputs_conv_27_hu_conv.ptrs_to.add(this);
184                                 outputs_conv_27_arr[b] = outputs_conv_27_hu_conv;
185                         }
186                         this.outputs = outputs_conv_27_arr;
187                 }
188         }
189         /**
190          * Creates a copy of the Event
191          */
192         public Event clone() {
193                 long ret = bindings.Event_clone(this.ptr);
194                 if (ret < 1024) { return null; }
195                 Event ret_hu_conv = Event.constr_from_ptr(ret);
196                 ret_hu_conv.ptrs_to.add(this);
197                 return ret_hu_conv;
198         }
199
200         /**
201          * Utility method to constructs a new FundingGenerationReady-variant Event
202          */
203         public static Event funding_generation_ready(byte[] temporary_channel_id, long channel_value_satoshis, byte[] output_script, long user_channel_id) {
204                 long ret = bindings.Event_funding_generation_ready(temporary_channel_id, channel_value_satoshis, output_script, user_channel_id);
205                 if (ret < 1024) { return null; }
206                 Event ret_hu_conv = Event.constr_from_ptr(ret);
207                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
208                 return ret_hu_conv;
209         }
210
211         /**
212          * Utility method to constructs a new PaymentReceived-variant Event
213          */
214         public static Event payment_received(byte[] payment_hash, byte[] payment_preimage, byte[] payment_secret, long amt, long user_payment_id) {
215                 long ret = bindings.Event_payment_received(payment_hash, payment_preimage, payment_secret, amt, user_payment_id);
216                 if (ret < 1024) { return null; }
217                 Event ret_hu_conv = Event.constr_from_ptr(ret);
218                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
219                 return ret_hu_conv;
220         }
221
222         /**
223          * Utility method to constructs a new PaymentSent-variant Event
224          */
225         public static Event payment_sent(byte[] payment_preimage) {
226                 long ret = bindings.Event_payment_sent(payment_preimage);
227                 if (ret < 1024) { return null; }
228                 Event ret_hu_conv = Event.constr_from_ptr(ret);
229                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
230                 return ret_hu_conv;
231         }
232
233         /**
234          * Utility method to constructs a new PaymentFailed-variant Event
235          */
236         public static Event payment_failed(byte[] payment_hash, boolean rejected_by_dest) {
237                 long ret = bindings.Event_payment_failed(payment_hash, rejected_by_dest);
238                 if (ret < 1024) { return null; }
239                 Event ret_hu_conv = Event.constr_from_ptr(ret);
240                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
241                 return ret_hu_conv;
242         }
243
244         /**
245          * Utility method to constructs a new PendingHTLCsForwardable-variant Event
246          */
247         public static Event pending_htlcs_forwardable(long time_forwardable) {
248                 long ret = bindings.Event_pending_htlcs_forwardable(time_forwardable);
249                 if (ret < 1024) { return null; }
250                 Event ret_hu_conv = Event.constr_from_ptr(ret);
251                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
252                 return ret_hu_conv;
253         }
254
255         /**
256          * Utility method to constructs a new SpendableOutputs-variant Event
257          */
258         public static Event spendable_outputs(SpendableOutputDescriptor[] outputs) {
259                 long ret = bindings.Event_spendable_outputs(outputs != null ? Arrays.stream(outputs).mapToLong(outputs_conv_27 -> outputs_conv_27.ptr).toArray() : null);
260                 if (ret < 1024) { return null; }
261                 Event ret_hu_conv = Event.constr_from_ptr(ret);
262                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
263                 /* TODO 2 SpendableOutputDescriptor  */;
264                 return ret_hu_conv;
265         }
266
267         /**
268          * Serialize the Event object into a byte array which can be read by Event_read
269          */
270         public byte[] write() {
271                 byte[] ret = bindings.Event_write(this.ptr);
272                 return ret;
273         }
274
275 }