[Java] Update auto-generated bindings
[ldk-java] / src / main / java / org / ldk / structs / MonitorEvent.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 java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * An event to be processed by the ChannelManager.
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class MonitorEvent extends CommonBase {
16         private MonitorEvent(Object _dummy, long ptr) { super(ptr); }
17         @Override @SuppressWarnings("deprecation")
18         protected void finalize() throws Throwable {
19                 super.finalize();
20                 if (ptr != 0) { bindings.MonitorEvent_free(ptr); }
21         }
22         static MonitorEvent constr_from_ptr(long ptr) {
23                 bindings.LDKMonitorEvent raw_val = bindings.LDKMonitorEvent_ref_from_ptr(ptr);
24                 if (raw_val.getClass() == bindings.LDKMonitorEvent.HTLCEvent.class) {
25                         return new HTLCEvent(ptr, (bindings.LDKMonitorEvent.HTLCEvent)raw_val);
26                 }
27                 if (raw_val.getClass() == bindings.LDKMonitorEvent.CommitmentTxConfirmed.class) {
28                         return new CommitmentTxConfirmed(ptr, (bindings.LDKMonitorEvent.CommitmentTxConfirmed)raw_val);
29                 }
30                 if (raw_val.getClass() == bindings.LDKMonitorEvent.UpdateCompleted.class) {
31                         return new UpdateCompleted(ptr, (bindings.LDKMonitorEvent.UpdateCompleted)raw_val);
32                 }
33                 if (raw_val.getClass() == bindings.LDKMonitorEvent.UpdateFailed.class) {
34                         return new UpdateFailed(ptr, (bindings.LDKMonitorEvent.UpdateFailed)raw_val);
35                 }
36                 assert false; return null; // Unreachable without extending the (internal) bindings interface
37         }
38
39         /**
40          * A monitor event containing an HTLCUpdate.
41          */
42         public final static class HTLCEvent extends MonitorEvent {
43                 public final org.ldk.structs.HTLCUpdate htlc_event;
44                 private HTLCEvent(long ptr, bindings.LDKMonitorEvent.HTLCEvent obj) {
45                         super(null, ptr);
46                         long htlc_event = obj.htlc_event;
47                         HTLCUpdate htlc_event_hu_conv = null; if (htlc_event < 0 || htlc_event > 4096) { htlc_event_hu_conv = new HTLCUpdate(null, htlc_event); }
48                         htlc_event_hu_conv.ptrs_to.add(this);
49                         this.htlc_event = htlc_event_hu_conv;
50                 }
51         }
52         /**
53          * A monitor event that the Channel's commitment transaction was confirmed.
54          */
55         public final static class CommitmentTxConfirmed extends MonitorEvent {
56                 public final org.ldk.structs.OutPoint commitment_tx_confirmed;
57                 private CommitmentTxConfirmed(long ptr, bindings.LDKMonitorEvent.CommitmentTxConfirmed obj) {
58                         super(null, ptr);
59                         long commitment_tx_confirmed = obj.commitment_tx_confirmed;
60                         OutPoint commitment_tx_confirmed_hu_conv = null; if (commitment_tx_confirmed < 0 || commitment_tx_confirmed > 4096) { commitment_tx_confirmed_hu_conv = new OutPoint(null, commitment_tx_confirmed); }
61                         commitment_tx_confirmed_hu_conv.ptrs_to.add(this);
62                         this.commitment_tx_confirmed = commitment_tx_confirmed_hu_conv;
63                 }
64         }
65         /**
66          * Indicates a [`ChannelMonitor`] update has completed. See
67          * [`ChannelMonitorUpdateErr::TemporaryFailure`] for more information on how this is used.
68          * 
69          * [`ChannelMonitorUpdateErr::TemporaryFailure`]: super::ChannelMonitorUpdateErr::TemporaryFailure
70          */
71         public final static class UpdateCompleted extends MonitorEvent {
72                 /**
73                  * The funding outpoint of the [`ChannelMonitor`] that was updated
74                 */
75                 public final org.ldk.structs.OutPoint funding_txo;
76                 /**
77                  * The Update ID from [`ChannelMonitorUpdate::update_id`] which was applied or
78                  * [`ChannelMonitor::get_latest_update_id`].
79                  * 
80                  * Note that this should only be set to a given update's ID if all previous updates for the
81                  * same [`ChannelMonitor`] have been applied and persisted.
82                 */
83                 public final long monitor_update_id;
84                 private UpdateCompleted(long ptr, bindings.LDKMonitorEvent.UpdateCompleted obj) {
85                         super(null, ptr);
86                         long funding_txo = obj.funding_txo;
87                         OutPoint funding_txo_hu_conv = null; if (funding_txo < 0 || funding_txo > 4096) { funding_txo_hu_conv = new OutPoint(null, funding_txo); }
88                         funding_txo_hu_conv.ptrs_to.add(this);
89                         this.funding_txo = funding_txo_hu_conv;
90                         this.monitor_update_id = obj.monitor_update_id;
91                 }
92         }
93         /**
94          * Indicates a [`ChannelMonitor`] update has failed. See
95          * [`ChannelMonitorUpdateErr::PermanentFailure`] for more information on how this is used.
96          * 
97          * [`ChannelMonitorUpdateErr::PermanentFailure`]: super::ChannelMonitorUpdateErr::PermanentFailure
98          */
99         public final static class UpdateFailed extends MonitorEvent {
100                 public final org.ldk.structs.OutPoint update_failed;
101                 private UpdateFailed(long ptr, bindings.LDKMonitorEvent.UpdateFailed obj) {
102                         super(null, ptr);
103                         long update_failed = obj.update_failed;
104                         OutPoint update_failed_hu_conv = null; if (update_failed < 0 || update_failed > 4096) { update_failed_hu_conv = new OutPoint(null, update_failed); }
105                         update_failed_hu_conv.ptrs_to.add(this);
106                         this.update_failed = update_failed_hu_conv;
107                 }
108         }
109         long clone_ptr() {
110                 long ret = bindings.MonitorEvent_clone_ptr(this.ptr);
111                 Reference.reachabilityFence(this);
112                 return ret;
113         }
114
115         /**
116          * Creates a copy of the MonitorEvent
117          */
118         public MonitorEvent clone() {
119                 long ret = bindings.MonitorEvent_clone(this.ptr);
120                 Reference.reachabilityFence(this);
121                 if (ret >= 0 && ret <= 4096) { return null; }
122                 org.ldk.structs.MonitorEvent ret_hu_conv = org.ldk.structs.MonitorEvent.constr_from_ptr(ret);
123                 ret_hu_conv.ptrs_to.add(this);
124                 return ret_hu_conv;
125         }
126
127         /**
128          * Utility method to constructs a new HTLCEvent-variant MonitorEvent
129          */
130         public static MonitorEvent htlcevent(HTLCUpdate a) {
131                 long ret = bindings.MonitorEvent_htlcevent(a == null ? 0 : a.ptr & ~1);
132                 Reference.reachabilityFence(a);
133                 if (ret >= 0 && ret <= 4096) { return null; }
134                 org.ldk.structs.MonitorEvent ret_hu_conv = org.ldk.structs.MonitorEvent.constr_from_ptr(ret);
135                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
136                 return ret_hu_conv;
137         }
138
139         /**
140          * Utility method to constructs a new CommitmentTxConfirmed-variant MonitorEvent
141          */
142         public static MonitorEvent commitment_tx_confirmed(OutPoint a) {
143                 long ret = bindings.MonitorEvent_commitment_tx_confirmed(a == null ? 0 : a.ptr & ~1);
144                 Reference.reachabilityFence(a);
145                 if (ret >= 0 && ret <= 4096) { return null; }
146                 org.ldk.structs.MonitorEvent ret_hu_conv = org.ldk.structs.MonitorEvent.constr_from_ptr(ret);
147                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
148                 return ret_hu_conv;
149         }
150
151         /**
152          * Utility method to constructs a new UpdateCompleted-variant MonitorEvent
153          */
154         public static MonitorEvent update_completed(OutPoint funding_txo, long monitor_update_id) {
155                 long ret = bindings.MonitorEvent_update_completed(funding_txo == null ? 0 : funding_txo.ptr & ~1, monitor_update_id);
156                 Reference.reachabilityFence(funding_txo);
157                 Reference.reachabilityFence(monitor_update_id);
158                 if (ret >= 0 && ret <= 4096) { return null; }
159                 org.ldk.structs.MonitorEvent ret_hu_conv = org.ldk.structs.MonitorEvent.constr_from_ptr(ret);
160                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
161                 return ret_hu_conv;
162         }
163
164         /**
165          * Utility method to constructs a new UpdateFailed-variant MonitorEvent
166          */
167         public static MonitorEvent update_failed(OutPoint a) {
168                 long ret = bindings.MonitorEvent_update_failed(a == null ? 0 : a.ptr & ~1);
169                 Reference.reachabilityFence(a);
170                 if (ret >= 0 && ret <= 4096) { return null; }
171                 org.ldk.structs.MonitorEvent ret_hu_conv = org.ldk.structs.MonitorEvent.constr_from_ptr(ret);
172                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
173                 return ret_hu_conv;
174         }
175
176         /**
177          * Serialize the MonitorEvent object into a byte array which can be read by MonitorEvent_read
178          */
179         public byte[] write() {
180                 byte[] ret = bindings.MonitorEvent_write(this.ptr);
181                 Reference.reachabilityFence(this);
182                 return ret;
183         }
184
185 }