Update auto-generated bindings to 0.0.103
[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.PaymentPathFailed.class) {
37                         return new PaymentPathFailed(ptr, (bindings.LDKEvent.PaymentPathFailed)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                 if (raw_val.getClass() == bindings.LDKEvent.PaymentForwarded.class) {
46                         return new PaymentForwarded(ptr, (bindings.LDKEvent.PaymentForwarded)raw_val);
47                 }
48                 if (raw_val.getClass() == bindings.LDKEvent.ChannelClosed.class) {
49                         return new ChannelClosed(ptr, (bindings.LDKEvent.ChannelClosed)raw_val);
50                 }
51                 if (raw_val.getClass() == bindings.LDKEvent.DiscardFunding.class) {
52                         return new DiscardFunding(ptr, (bindings.LDKEvent.DiscardFunding)raw_val);
53                 }
54                 assert false; return null; // Unreachable without extending the (internal) bindings interface
55         }
56
57         public final static class FundingGenerationReady extends Event {
58                 /**
59                  * The random channel_id we picked which you'll need to pass into
60                  * ChannelManager::funding_transaction_generated.
61                 */
62                 public final byte[] temporary_channel_id;
63                 /**
64                  * The value, in satoshis, that the output should have.
65                 */
66                 public final long channel_value_satoshis;
67                 /**
68                  * The script which should be used in the transaction output.
69                 */
70                 public final byte[] output_script;
71                 /**
72                  * The `user_channel_id` value passed in to [`ChannelManager::create_channel`], or 0 for
73                  * an inbound channel.
74                  * 
75                  * [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
76                 */
77                 public final long user_channel_id;
78                 private FundingGenerationReady(long ptr, bindings.LDKEvent.FundingGenerationReady obj) {
79                         super(null, ptr);
80                         this.temporary_channel_id = obj.temporary_channel_id;
81                         this.channel_value_satoshis = obj.channel_value_satoshis;
82                         this.output_script = obj.output_script;
83                         this.user_channel_id = obj.user_channel_id;
84                 }
85         }
86         public final static class PaymentReceived extends Event {
87                 /**
88                  * The hash for which the preimage should be handed to the ChannelManager.
89                 */
90                 public final byte[] payment_hash;
91                 /**
92                  * The value, in thousandths of a satoshi, that this payment is for.
93                 */
94                 public final long amt;
95                 /**
96                  * Information for claiming this received payment, based on whether the purpose of the
97                  * payment is to pay an invoice or to send a spontaneous payment.
98                 */
99                 public final PaymentPurpose purpose;
100                 private PaymentReceived(long ptr, bindings.LDKEvent.PaymentReceived obj) {
101                         super(null, ptr);
102                         this.payment_hash = obj.payment_hash;
103                         this.amt = obj.amt;
104                         long purpose = obj.purpose;
105                         PaymentPurpose purpose_hu_conv = PaymentPurpose.constr_from_ptr(purpose);
106                         purpose_hu_conv.ptrs_to.add(this);
107                         this.purpose = purpose_hu_conv;
108                 }
109         }
110         public final static class PaymentSent extends Event {
111                 /**
112                  * The id returned by [`ChannelManager::send_payment`] and used with
113                  * [`ChannelManager::retry_payment`].
114                  * 
115                  * [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
116                  * [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
117                  * 
118                  * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
119                 */
120                 @Nullable public final byte[] payment_id;
121                 /**
122                  * The preimage to the hash given to ChannelManager::send_payment.
123                  * Note that this serves as a payment receipt, if you wish to have such a thing, you must
124                  * store it somehow!
125                 */
126                 public final byte[] payment_preimage;
127                 /**
128                  * The hash which was given to [`ChannelManager::send_payment`].
129                  * 
130                  * [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
131                 */
132                 public final byte[] payment_hash;
133                 /**
134                  * The total fee which was spent at intermediate hops in this payment, across all paths.
135                  * 
136                  * Note that, like [`Route::get_total_fees`] this does *not* include any potential
137                  * overpayment to the recipient node.
138                  * 
139                  * If the recipient or an intermediate node misbehaves and gives us free money, this may
140                  * overstate the amount paid, though this is unlikely.
141                  * 
142                  * [`Route::get_total_fees`]: crate::routing::router::Route::get_total_fees
143                 */
144                 public final Option_u64Z fee_paid_msat;
145                 private PaymentSent(long ptr, bindings.LDKEvent.PaymentSent obj) {
146                         super(null, ptr);
147                         this.payment_id = obj.payment_id;
148                         this.payment_preimage = obj.payment_preimage;
149                         this.payment_hash = obj.payment_hash;
150                         long fee_paid_msat = obj.fee_paid_msat;
151                         Option_u64Z fee_paid_msat_hu_conv = Option_u64Z.constr_from_ptr(fee_paid_msat);
152                         fee_paid_msat_hu_conv.ptrs_to.add(this);
153                         this.fee_paid_msat = fee_paid_msat_hu_conv;
154                 }
155         }
156         public final static class PaymentPathFailed extends Event {
157                 /**
158                  * The id returned by [`ChannelManager::send_payment`] and used with
159                  * [`ChannelManager::retry_payment`].
160                  * 
161                  * [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
162                  * [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
163                  * 
164                  * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
165                 */
166                 @Nullable public final byte[] payment_id;
167                 /**
168                  * The hash which was given to ChannelManager::send_payment.
169                 */
170                 public final byte[] payment_hash;
171                 /**
172                  * Indicates the payment was rejected for some reason by the recipient. This implies that
173                  * the payment has failed, not just the route in question. If this is not set, you may
174                  * retry the payment via a different route.
175                 */
176                 public final boolean rejected_by_dest;
177                 /**
178                  * Any failure information conveyed via the Onion return packet by a node along the failed
179                  * payment route.
180                  * 
181                  * Should be applied to the [`NetworkGraph`] so that routing decisions can take into
182                  * account the update. [`NetGraphMsgHandler`] is capable of doing this.
183                  * 
184                  * [`NetworkGraph`]: crate::routing::network_graph::NetworkGraph
185                  * [`NetGraphMsgHandler`]: crate::routing::network_graph::NetGraphMsgHandler
186                 */
187                 public final Option_NetworkUpdateZ network_update;
188                 /**
189                  * For both single-path and multi-path payments, this is set if all paths of the payment have
190                  * failed. This will be set to false if (1) this is an MPP payment and (2) other parts of the
191                  * larger MPP payment were still in flight when this event was generated.
192                 */
193                 public final boolean all_paths_failed;
194                 /**
195                  * The payment path that failed.
196                 */
197                 public final RouteHop[] path;
198                 /**
199                  * The channel responsible for the failed payment path.
200                  * 
201                  * If this is `Some`, then the corresponding channel should be avoided when the payment is
202                  * retried. May be `None` for older [`Event`] serializations.
203                 */
204                 public final Option_u64Z short_channel_id;
205                 /**
206                  * Parameters needed to compute a new [`Route`] when retrying the failed payment path.
207                  * 
208                  * See [`find_route`] for details.
209                  * 
210                  * [`Route`]: crate::routing::router::Route
211                  * [`find_route`]: crate::routing::router::find_route
212                  * 
213                  * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
214                 */
215                 @Nullable public final RouteParameters retry;
216                 private PaymentPathFailed(long ptr, bindings.LDKEvent.PaymentPathFailed obj) {
217                         super(null, ptr);
218                         this.payment_id = obj.payment_id;
219                         this.payment_hash = obj.payment_hash;
220                         this.rejected_by_dest = obj.rejected_by_dest;
221                         long network_update = obj.network_update;
222                         Option_NetworkUpdateZ network_update_hu_conv = Option_NetworkUpdateZ.constr_from_ptr(network_update);
223                         network_update_hu_conv.ptrs_to.add(this);
224                         this.network_update = network_update_hu_conv;
225                         this.all_paths_failed = obj.all_paths_failed;
226                         long[] path = obj.path;
227                         RouteHop[] path_conv_10_arr = new RouteHop[path.length];
228                         for (int k = 0; k < path.length; k++) {
229                                 long path_conv_10 = path[k];
230                                 RouteHop path_conv_10_hu_conv = null; if (path_conv_10 < 0 || path_conv_10 > 4096) { path_conv_10_hu_conv = new RouteHop(null, path_conv_10); }
231                                 path_conv_10_hu_conv.ptrs_to.add(this);
232                                 path_conv_10_arr[k] = path_conv_10_hu_conv;
233                         }
234                         this.path = path_conv_10_arr;
235                         long short_channel_id = obj.short_channel_id;
236                         Option_u64Z short_channel_id_hu_conv = Option_u64Z.constr_from_ptr(short_channel_id);
237                         short_channel_id_hu_conv.ptrs_to.add(this);
238                         this.short_channel_id = short_channel_id_hu_conv;
239                         long retry = obj.retry;
240                         RouteParameters retry_hu_conv = null; if (retry < 0 || retry > 4096) { retry_hu_conv = new RouteParameters(null, retry); }
241                         retry_hu_conv.ptrs_to.add(this);
242                         this.retry = retry_hu_conv;
243                 }
244         }
245         public final static class PendingHTLCsForwardable extends Event {
246                 /**
247                  * The minimum amount of time that should be waited prior to calling
248                  * process_pending_htlc_forwards. To increase the effort required to correlate payments,
249                  * you should wait a random amount of time in roughly the range (now + time_forwardable,
250                  * now + 5*time_forwardable).
251                 */
252                 public final long time_forwardable;
253                 private PendingHTLCsForwardable(long ptr, bindings.LDKEvent.PendingHTLCsForwardable obj) {
254                         super(null, ptr);
255                         this.time_forwardable = obj.time_forwardable;
256                 }
257         }
258         public final static class SpendableOutputs extends Event {
259                 /**
260                  * The outputs which you should store as spendable by you.
261                 */
262                 public final SpendableOutputDescriptor[] outputs;
263                 private SpendableOutputs(long ptr, bindings.LDKEvent.SpendableOutputs obj) {
264                         super(null, ptr);
265                         long[] outputs = obj.outputs;
266                         SpendableOutputDescriptor[] outputs_conv_27_arr = new SpendableOutputDescriptor[outputs.length];
267                         for (int b = 0; b < outputs.length; b++) {
268                                 long outputs_conv_27 = outputs[b];
269                                 SpendableOutputDescriptor outputs_conv_27_hu_conv = SpendableOutputDescriptor.constr_from_ptr(outputs_conv_27);
270                                 outputs_conv_27_hu_conv.ptrs_to.add(this);
271                                 outputs_conv_27_arr[b] = outputs_conv_27_hu_conv;
272                         }
273                         this.outputs = outputs_conv_27_arr;
274                 }
275         }
276         public final static class PaymentForwarded extends Event {
277                 /**
278                  * The fee, in milli-satoshis, which was earned as a result of the payment.
279                  * 
280                  * Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC
281                  * was pending, the amount the next hop claimed will have been rounded down to the nearest
282                  * whole satoshi. Thus, the fee calculated here may be higher than expected as we still
283                  * claimed the full value in millisatoshis from the source. In this case,
284                  * `claim_from_onchain_tx` will be set.
285                  * 
286                  * If the channel which sent us the payment has been force-closed, we will claim the funds
287                  * via an on-chain transaction. In that case we do not yet know the on-chain transaction
288                  * fees which we will spend and will instead set this to `None`. It is possible duplicate
289                  * `PaymentForwarded` events are generated for the same payment iff `fee_earned_msat` is
290                  * `None`.
291                 */
292                 public final Option_u64Z fee_earned_msat;
293                 /**
294                  * If this is `true`, the forwarded HTLC was claimed by our counterparty via an on-chain
295                  * transaction.
296                 */
297                 public final boolean claim_from_onchain_tx;
298                 private PaymentForwarded(long ptr, bindings.LDKEvent.PaymentForwarded obj) {
299                         super(null, ptr);
300                         long fee_earned_msat = obj.fee_earned_msat;
301                         Option_u64Z fee_earned_msat_hu_conv = Option_u64Z.constr_from_ptr(fee_earned_msat);
302                         fee_earned_msat_hu_conv.ptrs_to.add(this);
303                         this.fee_earned_msat = fee_earned_msat_hu_conv;
304                         this.claim_from_onchain_tx = obj.claim_from_onchain_tx;
305                 }
306         }
307         public final static class ChannelClosed extends Event {
308                 /**
309                  * The channel_id of the channel which has been closed. Note that on-chain transactions
310                  * resolving the channel are likely still awaiting confirmation.
311                 */
312                 public final byte[] channel_id;
313                 /**
314                  * The `user_channel_id` value passed in to [`ChannelManager::create_channel`], or 0 for
315                  * an inbound channel. This will always be zero for objects serialized with LDK versions
316                  * prior to 0.0.102.
317                  * 
318                  * [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
319                 */
320                 public final long user_channel_id;
321                 /**
322                  * The reason the channel was closed.
323                 */
324                 public final ClosureReason reason;
325                 private ChannelClosed(long ptr, bindings.LDKEvent.ChannelClosed obj) {
326                         super(null, ptr);
327                         this.channel_id = obj.channel_id;
328                         this.user_channel_id = obj.user_channel_id;
329                         long reason = obj.reason;
330                         ClosureReason reason_hu_conv = ClosureReason.constr_from_ptr(reason);
331                         reason_hu_conv.ptrs_to.add(this);
332                         this.reason = reason_hu_conv;
333                 }
334         }
335         public final static class DiscardFunding extends Event {
336                 /**
337                  * The channel_id of the channel which has been closed.
338                 */
339                 public final byte[] channel_id;
340                 /**
341                  * The full transaction received from the user
342                 */
343                 public final byte[] transaction;
344                 private DiscardFunding(long ptr, bindings.LDKEvent.DiscardFunding obj) {
345                         super(null, ptr);
346                         this.channel_id = obj.channel_id;
347                         this.transaction = obj.transaction;
348                 }
349         }
350         /**
351          * Creates a copy of the Event
352          */
353         public Event clone() {
354                 long ret = bindings.Event_clone(this.ptr);
355                 if (ret >= 0 && ret <= 4096) { return null; }
356                 Event ret_hu_conv = Event.constr_from_ptr(ret);
357                 ret_hu_conv.ptrs_to.add(this);
358                 return ret_hu_conv;
359         }
360
361         /**
362          * Utility method to constructs a new FundingGenerationReady-variant Event
363          */
364         public static Event funding_generation_ready(byte[] temporary_channel_id, long channel_value_satoshis, byte[] output_script, long user_channel_id) {
365                 long ret = bindings.Event_funding_generation_ready(temporary_channel_id, channel_value_satoshis, output_script, user_channel_id);
366                 if (ret >= 0 && ret <= 4096) { return null; }
367                 Event ret_hu_conv = Event.constr_from_ptr(ret);
368                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
369                 return ret_hu_conv;
370         }
371
372         /**
373          * Utility method to constructs a new PaymentReceived-variant Event
374          */
375         public static Event payment_received(byte[] payment_hash, long amt, PaymentPurpose purpose) {
376                 long ret = bindings.Event_payment_received(payment_hash, amt, purpose.ptr);
377                 if (ret >= 0 && ret <= 4096) { return null; }
378                 Event ret_hu_conv = Event.constr_from_ptr(ret);
379                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
380                 return ret_hu_conv;
381         }
382
383         /**
384          * Utility method to constructs a new PaymentSent-variant Event
385          */
386         public static Event payment_sent(byte[] payment_id, byte[] payment_preimage, byte[] payment_hash, Option_u64Z fee_paid_msat) {
387                 long ret = bindings.Event_payment_sent(payment_id, payment_preimage, payment_hash, fee_paid_msat.ptr);
388                 if (ret >= 0 && ret <= 4096) { return null; }
389                 Event ret_hu_conv = Event.constr_from_ptr(ret);
390                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
391                 return ret_hu_conv;
392         }
393
394         /**
395          * Utility method to constructs a new PaymentPathFailed-variant Event
396          */
397         public static Event payment_path_failed(byte[] payment_id, byte[] payment_hash, boolean rejected_by_dest, Option_NetworkUpdateZ network_update, boolean all_paths_failed, RouteHop[] path, Option_u64Z short_channel_id, RouteParameters retry) {
398                 long ret = bindings.Event_payment_path_failed(payment_id, payment_hash, rejected_by_dest, network_update.ptr, all_paths_failed, path != null ? Arrays.stream(path).mapToLong(path_conv_10 -> path_conv_10 == null ? 0 : path_conv_10.ptr & ~1).toArray() : null, short_channel_id.ptr, retry == null ? 0 : retry.ptr & ~1);
399                 if (ret >= 0 && ret <= 4096) { return null; }
400                 Event ret_hu_conv = Event.constr_from_ptr(ret);
401                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
402                 return ret_hu_conv;
403         }
404
405         /**
406          * Utility method to constructs a new PendingHTLCsForwardable-variant Event
407          */
408         public static Event pending_htlcs_forwardable(long time_forwardable) {
409                 long ret = bindings.Event_pending_htlcs_forwardable(time_forwardable);
410                 if (ret >= 0 && ret <= 4096) { return null; }
411                 Event ret_hu_conv = Event.constr_from_ptr(ret);
412                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
413                 return ret_hu_conv;
414         }
415
416         /**
417          * Utility method to constructs a new SpendableOutputs-variant Event
418          */
419         public static Event spendable_outputs(SpendableOutputDescriptor[] outputs) {
420                 long ret = bindings.Event_spendable_outputs(outputs != null ? Arrays.stream(outputs).mapToLong(outputs_conv_27 -> outputs_conv_27.ptr).toArray() : null);
421                 if (ret >= 0 && ret <= 4096) { return null; }
422                 Event ret_hu_conv = Event.constr_from_ptr(ret);
423                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
424                 return ret_hu_conv;
425         }
426
427         /**
428          * Utility method to constructs a new PaymentForwarded-variant Event
429          */
430         public static Event payment_forwarded(Option_u64Z fee_earned_msat, boolean claim_from_onchain_tx) {
431                 long ret = bindings.Event_payment_forwarded(fee_earned_msat.ptr, claim_from_onchain_tx);
432                 if (ret >= 0 && ret <= 4096) { return null; }
433                 Event ret_hu_conv = Event.constr_from_ptr(ret);
434                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
435                 return ret_hu_conv;
436         }
437
438         /**
439          * Utility method to constructs a new ChannelClosed-variant Event
440          */
441         public static Event channel_closed(byte[] channel_id, long user_channel_id, ClosureReason reason) {
442                 long ret = bindings.Event_channel_closed(channel_id, user_channel_id, reason.ptr);
443                 if (ret >= 0 && ret <= 4096) { return null; }
444                 Event ret_hu_conv = Event.constr_from_ptr(ret);
445                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
446                 return ret_hu_conv;
447         }
448
449         /**
450          * Utility method to constructs a new DiscardFunding-variant Event
451          */
452         public static Event discard_funding(byte[] channel_id, byte[] transaction) {
453                 long ret = bindings.Event_discard_funding(channel_id, transaction);
454                 if (ret >= 0 && ret <= 4096) { return null; }
455                 Event ret_hu_conv = Event.constr_from_ptr(ret);
456                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
457                 return ret_hu_conv;
458         }
459
460         /**
461          * Serialize the Event object into a byte array which can be read by Event_read
462          */
463         public byte[] write() {
464                 byte[] ret = bindings.Event_write(this.ptr);
465                 return ret;
466         }
467
468 }