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