1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
10 * An Event which you should probably take some action in response to.
12 * Note that while Writeable and Readable are implemented for Event, you probably shouldn't use
13 * them directly as they don't round-trip exactly (for example FundingGenerationReady is never
14 * written as it makes no sense to respond to it after reconnecting to peers).
16 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
17 public class Event extends CommonBase {
18 private Event(Object _dummy, long ptr) { super(ptr); }
19 @Override @SuppressWarnings("deprecation")
20 protected void finalize() throws Throwable {
22 if (ptr != 0) { bindings.Event_free(ptr); }
24 static Event constr_from_ptr(long ptr) {
25 bindings.LDKEvent raw_val = bindings.LDKEvent_ref_from_ptr(ptr);
26 if (raw_val.getClass() == bindings.LDKEvent.FundingGenerationReady.class) {
27 return new FundingGenerationReady(ptr, (bindings.LDKEvent.FundingGenerationReady)raw_val);
29 if (raw_val.getClass() == bindings.LDKEvent.PaymentReceived.class) {
30 return new PaymentReceived(ptr, (bindings.LDKEvent.PaymentReceived)raw_val);
32 if (raw_val.getClass() == bindings.LDKEvent.PaymentSent.class) {
33 return new PaymentSent(ptr, (bindings.LDKEvent.PaymentSent)raw_val);
35 if (raw_val.getClass() == bindings.LDKEvent.PaymentFailed.class) {
36 return new PaymentFailed(ptr, (bindings.LDKEvent.PaymentFailed)raw_val);
38 if (raw_val.getClass() == bindings.LDKEvent.PendingHTLCsForwardable.class) {
39 return new PendingHTLCsForwardable(ptr, (bindings.LDKEvent.PendingHTLCsForwardable)raw_val);
41 if (raw_val.getClass() == bindings.LDKEvent.SpendableOutputs.class) {
42 return new SpendableOutputs(ptr, (bindings.LDKEvent.SpendableOutputs)raw_val);
44 assert false; return null; // Unreachable without extending the (internal) bindings interface
47 public final static class FundingGenerationReady extends Event {
48 public final byte[] temporary_channel_id;
49 public final long channel_value_satoshis;
50 public final byte[] output_script;
51 public final long user_channel_id;
52 private FundingGenerationReady(long ptr, bindings.LDKEvent.FundingGenerationReady obj) {
54 this.temporary_channel_id = obj.temporary_channel_id;
55 this.channel_value_satoshis = obj.channel_value_satoshis;
56 this.output_script = obj.output_script;
57 this.user_channel_id = obj.user_channel_id;
60 public final static class PaymentReceived extends Event {
61 public final byte[] payment_hash;
62 public final byte[] payment_secret;
63 public final long amt;
64 private PaymentReceived(long ptr, bindings.LDKEvent.PaymentReceived obj) {
66 this.payment_hash = obj.payment_hash;
67 this.payment_secret = obj.payment_secret;
71 public final static class PaymentSent extends Event {
72 public final byte[] payment_preimage;
73 private PaymentSent(long ptr, bindings.LDKEvent.PaymentSent obj) {
75 this.payment_preimage = obj.payment_preimage;
78 public final static class PaymentFailed extends Event {
79 public final byte[] payment_hash;
80 public final boolean rejected_by_dest;
81 private PaymentFailed(long ptr, bindings.LDKEvent.PaymentFailed obj) {
83 this.payment_hash = obj.payment_hash;
84 this.rejected_by_dest = obj.rejected_by_dest;
87 public final static class PendingHTLCsForwardable extends Event {
88 public final long time_forwardable;
89 private PendingHTLCsForwardable(long ptr, bindings.LDKEvent.PendingHTLCsForwardable obj) {
91 this.time_forwardable = obj.time_forwardable;
94 public final static class SpendableOutputs extends Event {
95 public final SpendableOutputDescriptor[] outputs;
96 private SpendableOutputs(long ptr, bindings.LDKEvent.SpendableOutputs obj) {
98 long[] outputs = obj.outputs;
99 SpendableOutputDescriptor[] outputs_conv_27_arr = new SpendableOutputDescriptor[outputs.length];
100 for (int b = 0; b < outputs.length; b++) {
101 long outputs_conv_27 = outputs[b];
102 SpendableOutputDescriptor outputs_conv_27_hu_conv = SpendableOutputDescriptor.constr_from_ptr(outputs_conv_27);
103 outputs_conv_27_hu_conv.ptrs_to.add(this);
104 outputs_conv_27_arr[b] = outputs_conv_27_hu_conv;
106 this.outputs = outputs_conv_27_arr;
110 * Creates a copy of the Event
112 public Event clone() {
113 long ret = bindings.Event_clone(this.ptr);
114 Event ret_hu_conv = Event.constr_from_ptr(ret);
115 ret_hu_conv.ptrs_to.add(this);
120 * Serialize the Event object into a byte array which can be read by Event_read
122 public byte[] write() {
123 byte[] ret = bindings.Event_write(this.ptr);