1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * An event to be processed by the ChannelManager.
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 {
20 if (ptr != 0) { bindings.MonitorEvent_free(ptr); }
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);
27 if (raw_val.getClass() == bindings.LDKMonitorEvent.HolderForceClosedWithInfo.class) {
28 return new HolderForceClosedWithInfo(ptr, (bindings.LDKMonitorEvent.HolderForceClosedWithInfo)raw_val);
30 if (raw_val.getClass() == bindings.LDKMonitorEvent.HolderForceClosed.class) {
31 return new HolderForceClosed(ptr, (bindings.LDKMonitorEvent.HolderForceClosed)raw_val);
33 if (raw_val.getClass() == bindings.LDKMonitorEvent.Completed.class) {
34 return new Completed(ptr, (bindings.LDKMonitorEvent.Completed)raw_val);
36 assert false; return null; // Unreachable without extending the (internal) bindings interface
40 * A monitor event containing an HTLCUpdate.
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) {
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;
53 * Indicates we broadcasted the channel's latest commitment transaction and thus closed the
54 * channel. Holds information about the channel and why it was closed.
56 public final static class HolderForceClosedWithInfo extends MonitorEvent {
58 * The reason the channel was closed.
60 public final org.ldk.structs.ClosureReason reason;
62 * The funding outpoint of the channel.
64 public final org.ldk.structs.OutPoint outpoint;
66 * The channel ID of the channel.
68 public final org.ldk.structs.ChannelId channel_id;
69 private HolderForceClosedWithInfo(long ptr, bindings.LDKMonitorEvent.HolderForceClosedWithInfo obj) {
71 long reason = obj.reason;
72 org.ldk.structs.ClosureReason reason_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(reason);
73 if (reason_hu_conv != null) { reason_hu_conv.ptrs_to.add(this); };
74 this.reason = reason_hu_conv;
75 long outpoint = obj.outpoint;
76 org.ldk.structs.OutPoint outpoint_hu_conv = null; if (outpoint < 0 || outpoint > 4096) { outpoint_hu_conv = new org.ldk.structs.OutPoint(null, outpoint); }
77 if (outpoint_hu_conv != null) { outpoint_hu_conv.ptrs_to.add(this); };
78 this.outpoint = outpoint_hu_conv;
79 long channel_id = obj.channel_id;
80 org.ldk.structs.ChannelId channel_id_hu_conv = null; if (channel_id < 0 || channel_id > 4096) { channel_id_hu_conv = new org.ldk.structs.ChannelId(null, channel_id); }
81 if (channel_id_hu_conv != null) { channel_id_hu_conv.ptrs_to.add(this); };
82 this.channel_id = channel_id_hu_conv;
86 * Indicates we broadcasted the channel's latest commitment transaction and thus closed the
89 public final static class HolderForceClosed extends MonitorEvent {
90 public final org.ldk.structs.OutPoint holder_force_closed;
91 private HolderForceClosed(long ptr, bindings.LDKMonitorEvent.HolderForceClosed obj) {
93 long holder_force_closed = obj.holder_force_closed;
94 org.ldk.structs.OutPoint holder_force_closed_hu_conv = null; if (holder_force_closed < 0 || holder_force_closed > 4096) { holder_force_closed_hu_conv = new org.ldk.structs.OutPoint(null, holder_force_closed); }
95 if (holder_force_closed_hu_conv != null) { holder_force_closed_hu_conv.ptrs_to.add(this); };
96 this.holder_force_closed = holder_force_closed_hu_conv;
100 * Indicates a [`ChannelMonitor`] update has completed. See
101 * [`ChannelMonitorUpdateStatus::InProgress`] for more information on how this is used.
103 * [`ChannelMonitorUpdateStatus::InProgress`]: super::ChannelMonitorUpdateStatus::InProgress
105 public final static class Completed extends MonitorEvent {
107 * The funding outpoint of the [`ChannelMonitor`] that was updated
109 public final org.ldk.structs.OutPoint funding_txo;
111 * The channel ID of the channel associated with the [`ChannelMonitor`]
113 public final org.ldk.structs.ChannelId channel_id;
115 * The Update ID from [`ChannelMonitorUpdate::update_id`] which was applied or
116 * [`ChannelMonitor::get_latest_update_id`].
118 * Note that this should only be set to a given update's ID if all previous updates for the
119 * same [`ChannelMonitor`] have been applied and persisted.
121 public final long monitor_update_id;
122 private Completed(long ptr, bindings.LDKMonitorEvent.Completed obj) {
124 long funding_txo = obj.funding_txo;
125 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); }
126 if (funding_txo_hu_conv != null) { funding_txo_hu_conv.ptrs_to.add(this); };
127 this.funding_txo = funding_txo_hu_conv;
128 long channel_id = obj.channel_id;
129 org.ldk.structs.ChannelId channel_id_hu_conv = null; if (channel_id < 0 || channel_id > 4096) { channel_id_hu_conv = new org.ldk.structs.ChannelId(null, channel_id); }
130 if (channel_id_hu_conv != null) { channel_id_hu_conv.ptrs_to.add(this); };
131 this.channel_id = channel_id_hu_conv;
132 this.monitor_update_id = obj.monitor_update_id;
136 long ret = bindings.MonitorEvent_clone_ptr(this.ptr);
137 Reference.reachabilityFence(this);
142 * Creates a copy of the MonitorEvent
144 public MonitorEvent clone() {
145 long ret = bindings.MonitorEvent_clone(this.ptr);
146 Reference.reachabilityFence(this);
147 if (ret >= 0 && ret <= 4096) { return null; }
148 org.ldk.structs.MonitorEvent ret_hu_conv = org.ldk.structs.MonitorEvent.constr_from_ptr(ret);
149 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
154 * Utility method to constructs a new HTLCEvent-variant MonitorEvent
156 public static MonitorEvent htlcevent(org.ldk.structs.HTLCUpdate a) {
157 long ret = bindings.MonitorEvent_htlcevent(a.ptr);
158 Reference.reachabilityFence(a);
159 if (ret >= 0 && ret <= 4096) { return null; }
160 org.ldk.structs.MonitorEvent ret_hu_conv = org.ldk.structs.MonitorEvent.constr_from_ptr(ret);
161 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
162 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };
167 * Utility method to constructs a new HolderForceClosedWithInfo-variant MonitorEvent
169 public static MonitorEvent holder_force_closed_with_info(org.ldk.structs.ClosureReason reason, org.ldk.structs.OutPoint outpoint, org.ldk.structs.ChannelId channel_id) {
170 long ret = bindings.MonitorEvent_holder_force_closed_with_info(reason.ptr, outpoint.ptr, channel_id.ptr);
171 Reference.reachabilityFence(reason);
172 Reference.reachabilityFence(outpoint);
173 Reference.reachabilityFence(channel_id);
174 if (ret >= 0 && ret <= 4096) { return null; }
175 org.ldk.structs.MonitorEvent ret_hu_conv = org.ldk.structs.MonitorEvent.constr_from_ptr(ret);
176 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
177 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(reason); };
178 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(outpoint); };
179 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channel_id); };
184 * Utility method to constructs a new HolderForceClosed-variant MonitorEvent
186 public static MonitorEvent holder_force_closed(org.ldk.structs.OutPoint a) {
187 long ret = bindings.MonitorEvent_holder_force_closed(a.ptr);
188 Reference.reachabilityFence(a);
189 if (ret >= 0 && ret <= 4096) { return null; }
190 org.ldk.structs.MonitorEvent ret_hu_conv = org.ldk.structs.MonitorEvent.constr_from_ptr(ret);
191 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
192 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };
197 * Utility method to constructs a new Completed-variant MonitorEvent
199 public static MonitorEvent completed(org.ldk.structs.OutPoint funding_txo, org.ldk.structs.ChannelId channel_id, long monitor_update_id) {
200 long ret = bindings.MonitorEvent_completed(funding_txo.ptr, channel_id.ptr, monitor_update_id);
201 Reference.reachabilityFence(funding_txo);
202 Reference.reachabilityFence(channel_id);
203 Reference.reachabilityFence(monitor_update_id);
204 if (ret >= 0 && ret <= 4096) { return null; }
205 org.ldk.structs.MonitorEvent ret_hu_conv = org.ldk.structs.MonitorEvent.constr_from_ptr(ret);
206 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
207 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(funding_txo); };
208 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channel_id); };
213 * Checks if two MonitorEvents contain equal inner contents.
214 * This ignores pointers and is_owned flags and looks at the values in fields.
216 public boolean eq(org.ldk.structs.MonitorEvent b) {
217 boolean ret = bindings.MonitorEvent_eq(this.ptr, b.ptr);
218 Reference.reachabilityFence(this);
219 Reference.reachabilityFence(b);
223 @Override public boolean equals(Object o) {
224 if (!(o instanceof MonitorEvent)) return false;
225 return this.eq((MonitorEvent)o);
228 * Serialize the MonitorEvent object into a byte array which can be read by MonitorEvent_read
230 public byte[] write() {
231 byte[] ret = bindings.MonitorEvent_write(this.ptr);
232 Reference.reachabilityFence(this);