[Java] Update auto-generated Java 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.Completed.class) {
31                         return new Completed(ptr, (bindings.LDKMonitorEvent.Completed)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                         org.ldk.structs.HTLCUpdate htlc_event_hu_conv = null; if (htlc_event < 0 || htlc_event > 4096) { htlc_event_hu_conv = new org.ldk.structs.HTLCUpdate(null, htlc_event); }
48                         if (htlc_event_hu_conv != null) { 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                         org.ldk.structs.OutPoint commitment_tx_confirmed_hu_conv = null; if (commitment_tx_confirmed < 0 || commitment_tx_confirmed > 4096) { commitment_tx_confirmed_hu_conv = new org.ldk.structs.OutPoint(null, commitment_tx_confirmed); }
61                         if (commitment_tx_confirmed_hu_conv != null) { 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          * [`ChannelMonitorUpdateStatus::InProgress`] for more information on how this is used.
68          * 
69          * [`ChannelMonitorUpdateStatus::InProgress`]: super::ChannelMonitorUpdateStatus::InProgress
70          */
71         public final static class Completed 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 Completed(long ptr, bindings.LDKMonitorEvent.Completed obj) {
85                         super(null, ptr);
86                         long funding_txo = obj.funding_txo;
87                         org.ldk.structs.OutPoint funding_txo_hu_conv = null; if (funding_txo < 0 || funding_txo > 4096) { funding_txo_hu_conv = new org.ldk.structs.OutPoint(null, funding_txo); }
88                         if (funding_txo_hu_conv != null) { 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          * [`ChannelMonitorUpdateStatus::PermanentFailure`] for more information on how this is used.
96          * 
97          * [`ChannelMonitorUpdateStatus::PermanentFailure`]: super::ChannelMonitorUpdateStatus::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                         org.ldk.structs.OutPoint update_failed_hu_conv = null; if (update_failed < 0 || update_failed > 4096) { update_failed_hu_conv = new org.ldk.structs.OutPoint(null, update_failed); }
105                         if (update_failed_hu_conv != null) { 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                 if (ret_hu_conv != null) { 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);
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                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
136                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };
137                 return ret_hu_conv;
138         }
139
140         /**
141          * Utility method to constructs a new CommitmentTxConfirmed-variant MonitorEvent
142          */
143         public static MonitorEvent commitment_tx_confirmed(OutPoint a) {
144                 long ret = bindings.MonitorEvent_commitment_tx_confirmed(a == null ? 0 : a.ptr);
145                 Reference.reachabilityFence(a);
146                 if (ret >= 0 && ret <= 4096) { return null; }
147                 org.ldk.structs.MonitorEvent ret_hu_conv = org.ldk.structs.MonitorEvent.constr_from_ptr(ret);
148                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
149                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };
150                 return ret_hu_conv;
151         }
152
153         /**
154          * Utility method to constructs a new Completed-variant MonitorEvent
155          */
156         public static MonitorEvent completed(OutPoint funding_txo, long monitor_update_id) {
157                 long ret = bindings.MonitorEvent_completed(funding_txo == null ? 0 : funding_txo.ptr, monitor_update_id);
158                 Reference.reachabilityFence(funding_txo);
159                 Reference.reachabilityFence(monitor_update_id);
160                 if (ret >= 0 && ret <= 4096) { return null; }
161                 org.ldk.structs.MonitorEvent ret_hu_conv = org.ldk.structs.MonitorEvent.constr_from_ptr(ret);
162                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
163                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(funding_txo); };
164                 return ret_hu_conv;
165         }
166
167         /**
168          * Utility method to constructs a new UpdateFailed-variant MonitorEvent
169          */
170         public static MonitorEvent update_failed(OutPoint a) {
171                 long ret = bindings.MonitorEvent_update_failed(a == null ? 0 : a.ptr);
172                 Reference.reachabilityFence(a);
173                 if (ret >= 0 && ret <= 4096) { return null; }
174                 org.ldk.structs.MonitorEvent ret_hu_conv = org.ldk.structs.MonitorEvent.constr_from_ptr(ret);
175                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
176                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };
177                 return ret_hu_conv;
178         }
179
180         /**
181          * Checks if two MonitorEvents contain equal inner contents.
182          * This ignores pointers and is_owned flags and looks at the values in fields.
183          */
184         public boolean eq(MonitorEvent b) {
185                 boolean ret = bindings.MonitorEvent_eq(this.ptr, b == null ? 0 : b.ptr);
186                 Reference.reachabilityFence(this);
187                 Reference.reachabilityFence(b);
188                 return ret;
189         }
190
191         @Override public boolean equals(Object o) {
192                 if (!(o instanceof MonitorEvent)) return false;
193                 return this.eq((MonitorEvent)o);
194         }
195         /**
196          * Serialize the MonitorEvent object into a byte array which can be read by MonitorEvent_read
197          */
198         public byte[] write() {
199                 byte[] ret = bindings.MonitorEvent_write(this.ptr);
200                 Reference.reachabilityFence(this);
201                 return ret;
202         }
203
204 }