Update auto-generated files
[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                 if (raw_val.getClass() == bindings.LDKEvent.PaymentForwarded.class) {
46                         return new PaymentForwarded(ptr, (bindings.LDKEvent.PaymentForwarded)raw_val);
47                 }
48                 assert false; return null; // Unreachable without extending the (internal) bindings interface
49         }
50
51         public final static class FundingGenerationReady extends Event {
52                 /**
53                  * The random channel_id we picked which you'll need to pass into
54                  * ChannelManager::funding_transaction_generated.
55                 */
56                 public final byte[] temporary_channel_id;
57                 /**
58                  * The value, in satoshis, that the output should have.
59                 */
60                 public final long channel_value_satoshis;
61                 /**
62                  * The script which should be used in the transaction output.
63                 */
64                 public final byte[] output_script;
65                 /**
66                  * The value passed in to ChannelManager::create_channel
67                 */
68                 public final long user_channel_id;
69                 private FundingGenerationReady(long ptr, bindings.LDKEvent.FundingGenerationReady obj) {
70                         super(null, ptr);
71                         this.temporary_channel_id = obj.temporary_channel_id;
72                         this.channel_value_satoshis = obj.channel_value_satoshis;
73                         this.output_script = obj.output_script;
74                         this.user_channel_id = obj.user_channel_id;
75                 }
76         }
77         public final static class PaymentReceived extends Event {
78                 /**
79                  * The hash for which the preimage should be handed to the ChannelManager.
80                 */
81                 public final byte[] payment_hash;
82                 /**
83                  * The value, in thousandths of a satoshi, that this payment is for. Note that you must
84                  * compare this to the expected value before accepting the payment (as otherwise you are
85                  * providing proof-of-payment for less than the value you expected!).
86                 */
87                 public final long amt;
88                 /**
89                  * Information for claiming this received payment, based on whether the purpose of the
90                  * payment is to pay an invoice or to send a spontaneous payment.
91                 */
92                 public final PaymentPurpose purpose;
93                 private PaymentReceived(long ptr, bindings.LDKEvent.PaymentReceived obj) {
94                         super(null, ptr);
95                         this.payment_hash = obj.payment_hash;
96                         this.amt = obj.amt;
97                         long purpose = obj.purpose;
98                         PaymentPurpose purpose_hu_conv = PaymentPurpose.constr_from_ptr(purpose);
99                         purpose_hu_conv.ptrs_to.add(this);
100                         this.purpose = purpose_hu_conv;
101                 }
102         }
103         public final static class PaymentSent extends Event {
104                 /**
105                  * The preimage to the hash given to ChannelManager::send_payment.
106                  * Note that this serves as a payment receipt, if you wish to have such a thing, you must
107                  * store it somehow!
108                 */
109                 public final byte[] payment_preimage;
110                 private PaymentSent(long ptr, bindings.LDKEvent.PaymentSent obj) {
111                         super(null, ptr);
112                         this.payment_preimage = obj.payment_preimage;
113                 }
114         }
115         public final static class PaymentFailed extends Event {
116                 /**
117                  * The hash which was given to ChannelManager::send_payment.
118                 */
119                 public final byte[] payment_hash;
120                 /**
121                  * Indicates the payment was rejected for some reason by the recipient. This implies that
122                  * the payment has failed, not just the route in question. If this is not set, you may
123                  * retry the payment via a different route.
124                 */
125                 public final boolean rejected_by_dest;
126                 private PaymentFailed(long ptr, bindings.LDKEvent.PaymentFailed obj) {
127                         super(null, ptr);
128                         this.payment_hash = obj.payment_hash;
129                         this.rejected_by_dest = obj.rejected_by_dest;
130                 }
131         }
132         public final static class PendingHTLCsForwardable extends Event {
133                 /**
134                  * The minimum amount of time that should be waited prior to calling
135                  * process_pending_htlc_forwards. To increase the effort required to correlate payments,
136                  * you should wait a random amount of time in roughly the range (now + time_forwardable,
137                  * now + 5*time_forwardable).
138                 */
139                 public final long time_forwardable;
140                 private PendingHTLCsForwardable(long ptr, bindings.LDKEvent.PendingHTLCsForwardable obj) {
141                         super(null, ptr);
142                         this.time_forwardable = obj.time_forwardable;
143                 }
144         }
145         public final static class SpendableOutputs extends Event {
146                 /**
147                  * The outputs which you should store as spendable by you.
148                 */
149                 public final SpendableOutputDescriptor[] outputs;
150                 private SpendableOutputs(long ptr, bindings.LDKEvent.SpendableOutputs obj) {
151                         super(null, ptr);
152                         long[] outputs = obj.outputs;
153                         SpendableOutputDescriptor[] outputs_conv_27_arr = new SpendableOutputDescriptor[outputs.length];
154                         for (int b = 0; b < outputs.length; b++) {
155                                 long outputs_conv_27 = outputs[b];
156                                 SpendableOutputDescriptor outputs_conv_27_hu_conv = SpendableOutputDescriptor.constr_from_ptr(outputs_conv_27);
157                                 outputs_conv_27_hu_conv.ptrs_to.add(this);
158                                 outputs_conv_27_arr[b] = outputs_conv_27_hu_conv;
159                         }
160                         this.outputs = outputs_conv_27_arr;
161                 }
162         }
163         public final static class PaymentForwarded extends Event {
164                 /**
165                  * The fee, in milli-satoshis, which was earned as a result of the payment.
166                  * 
167                  * Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC
168                  * was pending, the amount the next hop claimed will have been rounded down to the nearest
169                  * whole satoshi. Thus, the fee calculated here may be higher than expected as we still
170                  * claimed the full value in millisatoshis from the source. In this case,
171                  * `claim_from_onchain_tx` will be set.
172                  * 
173                  * If the channel which sent us the payment has been force-closed, we will claim the funds
174                  * via an on-chain transaction. In that case we do not yet know the on-chain transaction
175                  * fees which we will spend and will instead set this to `None`. It is possible duplicate
176                  * `PaymentForwarded` events are generated for the same payment iff `fee_earned_msat` is
177                  * `None`.
178                 */
179                 public final Option_u64Z fee_earned_msat;
180                 /**
181                  * If this is `true`, the forwarded HTLC was claimed by our counterparty via an on-chain
182                  * transaction.
183                 */
184                 public final boolean claim_from_onchain_tx;
185                 private PaymentForwarded(long ptr, bindings.LDKEvent.PaymentForwarded obj) {
186                         super(null, ptr);
187                         long fee_earned_msat = obj.fee_earned_msat;
188                         Option_u64Z fee_earned_msat_hu_conv = Option_u64Z.constr_from_ptr(fee_earned_msat);
189                         fee_earned_msat_hu_conv.ptrs_to.add(this);
190                         this.fee_earned_msat = fee_earned_msat_hu_conv;
191                         this.claim_from_onchain_tx = obj.claim_from_onchain_tx;
192                 }
193         }
194         /**
195          * Creates a copy of the Event
196          */
197         public Event clone() {
198                 long ret = bindings.Event_clone(this.ptr);
199                 if (ret < 1024) { return null; }
200                 Event ret_hu_conv = Event.constr_from_ptr(ret);
201                 ret_hu_conv.ptrs_to.add(this);
202                 return ret_hu_conv;
203         }
204
205         /**
206          * Utility method to constructs a new FundingGenerationReady-variant Event
207          */
208         public static Event funding_generation_ready(byte[] temporary_channel_id, long channel_value_satoshis, byte[] output_script, long user_channel_id) {
209                 long ret = bindings.Event_funding_generation_ready(temporary_channel_id, channel_value_satoshis, output_script, user_channel_id);
210                 if (ret < 1024) { return null; }
211                 Event ret_hu_conv = Event.constr_from_ptr(ret);
212                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
213                 return ret_hu_conv;
214         }
215
216         /**
217          * Utility method to constructs a new PaymentReceived-variant Event
218          */
219         public static Event payment_received(byte[] payment_hash, long amt, PaymentPurpose purpose) {
220                 long ret = bindings.Event_payment_received(payment_hash, amt, purpose.ptr);
221                 if (ret < 1024) { return null; }
222                 Event ret_hu_conv = Event.constr_from_ptr(ret);
223                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
224                 return ret_hu_conv;
225         }
226
227         /**
228          * Utility method to constructs a new PaymentSent-variant Event
229          */
230         public static Event payment_sent(byte[] payment_preimage) {
231                 long ret = bindings.Event_payment_sent(payment_preimage);
232                 if (ret < 1024) { return null; }
233                 Event ret_hu_conv = Event.constr_from_ptr(ret);
234                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
235                 return ret_hu_conv;
236         }
237
238         /**
239          * Utility method to constructs a new PaymentFailed-variant Event
240          */
241         public static Event payment_failed(byte[] payment_hash, boolean rejected_by_dest) {
242                 long ret = bindings.Event_payment_failed(payment_hash, rejected_by_dest);
243                 if (ret < 1024) { return null; }
244                 Event ret_hu_conv = Event.constr_from_ptr(ret);
245                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
246                 return ret_hu_conv;
247         }
248
249         /**
250          * Utility method to constructs a new PendingHTLCsForwardable-variant Event
251          */
252         public static Event pending_htlcs_forwardable(long time_forwardable) {
253                 long ret = bindings.Event_pending_htlcs_forwardable(time_forwardable);
254                 if (ret < 1024) { return null; }
255                 Event ret_hu_conv = Event.constr_from_ptr(ret);
256                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
257                 return ret_hu_conv;
258         }
259
260         /**
261          * Utility method to constructs a new SpendableOutputs-variant Event
262          */
263         public static Event spendable_outputs(SpendableOutputDescriptor[] outputs) {
264                 long ret = bindings.Event_spendable_outputs(outputs != null ? Arrays.stream(outputs).mapToLong(outputs_conv_27 -> outputs_conv_27.ptr).toArray() : null);
265                 if (ret < 1024) { return null; }
266                 Event ret_hu_conv = Event.constr_from_ptr(ret);
267                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
268                 /* TODO 2 SpendableOutputDescriptor  */;
269                 return ret_hu_conv;
270         }
271
272         /**
273          * Utility method to constructs a new PaymentForwarded-variant Event
274          */
275         public static Event payment_forwarded(Option_u64Z fee_earned_msat, boolean claim_from_onchain_tx) {
276                 long ret = bindings.Event_payment_forwarded(fee_earned_msat.ptr, claim_from_onchain_tx);
277                 if (ret < 1024) { return null; }
278                 Event ret_hu_conv = Event.constr_from_ptr(ret);
279                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
280                 return ret_hu_conv;
281         }
282
283         /**
284          * Serialize the Event object into a byte array which can be read by Event_read
285          */
286         public byte[] write() {
287                 byte[] ret = bindings.Event_write(this.ptr);
288                 return ret;
289         }
290
291 }