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.HolderForceClosed.class) {
28 return new HolderForceClosed(ptr, (bindings.LDKMonitorEvent.HolderForceClosed)raw_val);
30 if (raw_val.getClass() == bindings.LDKMonitorEvent.Completed.class) {
31 return new Completed(ptr, (bindings.LDKMonitorEvent.Completed)raw_val);
33 assert false; return null; // Unreachable without extending the (internal) bindings interface
37 * A monitor event containing an HTLCUpdate.
39 public final static class HTLCEvent extends MonitorEvent {
40 public final org.ldk.structs.HTLCUpdate htlc_event;
41 private HTLCEvent(long ptr, bindings.LDKMonitorEvent.HTLCEvent obj) {
43 long htlc_event = obj.htlc_event;
44 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); }
45 if (htlc_event_hu_conv != null) { htlc_event_hu_conv.ptrs_to.add(this); };
46 this.htlc_event = htlc_event_hu_conv;
50 * A monitor event that the Channel's commitment transaction was confirmed.
52 public final static class HolderForceClosed extends MonitorEvent {
53 public final org.ldk.structs.OutPoint holder_force_closed;
54 private HolderForceClosed(long ptr, bindings.LDKMonitorEvent.HolderForceClosed obj) {
56 long holder_force_closed = obj.holder_force_closed;
57 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); }
58 if (holder_force_closed_hu_conv != null) { holder_force_closed_hu_conv.ptrs_to.add(this); };
59 this.holder_force_closed = holder_force_closed_hu_conv;
63 * Indicates a [`ChannelMonitor`] update has completed. See
64 * [`ChannelMonitorUpdateStatus::InProgress`] for more information on how this is used.
66 * [`ChannelMonitorUpdateStatus::InProgress`]: super::ChannelMonitorUpdateStatus::InProgress
68 public final static class Completed extends MonitorEvent {
70 * The funding outpoint of the [`ChannelMonitor`] that was updated
72 public final org.ldk.structs.OutPoint funding_txo;
74 * The Update ID from [`ChannelMonitorUpdate::update_id`] which was applied or
75 * [`ChannelMonitor::get_latest_update_id`].
77 * Note that this should only be set to a given update's ID if all previous updates for the
78 * same [`ChannelMonitor`] have been applied and persisted.
80 public final long monitor_update_id;
81 private Completed(long ptr, bindings.LDKMonitorEvent.Completed obj) {
83 long funding_txo = obj.funding_txo;
84 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); }
85 if (funding_txo_hu_conv != null) { funding_txo_hu_conv.ptrs_to.add(this); };
86 this.funding_txo = funding_txo_hu_conv;
87 this.monitor_update_id = obj.monitor_update_id;
91 long ret = bindings.MonitorEvent_clone_ptr(this.ptr);
92 Reference.reachabilityFence(this);
97 * Creates a copy of the MonitorEvent
99 public MonitorEvent clone() {
100 long ret = bindings.MonitorEvent_clone(this.ptr);
101 Reference.reachabilityFence(this);
102 if (ret >= 0 && ret <= 4096) { return null; }
103 org.ldk.structs.MonitorEvent ret_hu_conv = org.ldk.structs.MonitorEvent.constr_from_ptr(ret);
104 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
109 * Utility method to constructs a new HTLCEvent-variant MonitorEvent
111 public static MonitorEvent htlcevent(org.ldk.structs.HTLCUpdate a) {
112 long ret = bindings.MonitorEvent_htlcevent(a == null ? 0 : a.ptr);
113 Reference.reachabilityFence(a);
114 if (ret >= 0 && ret <= 4096) { return null; }
115 org.ldk.structs.MonitorEvent ret_hu_conv = org.ldk.structs.MonitorEvent.constr_from_ptr(ret);
116 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
117 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };
122 * Utility method to constructs a new HolderForceClosed-variant MonitorEvent
124 public static MonitorEvent holder_force_closed(org.ldk.structs.OutPoint a) {
125 long ret = bindings.MonitorEvent_holder_force_closed(a == null ? 0 : a.ptr);
126 Reference.reachabilityFence(a);
127 if (ret >= 0 && ret <= 4096) { return null; }
128 org.ldk.structs.MonitorEvent ret_hu_conv = org.ldk.structs.MonitorEvent.constr_from_ptr(ret);
129 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
130 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };
135 * Utility method to constructs a new Completed-variant MonitorEvent
137 public static MonitorEvent completed(org.ldk.structs.OutPoint funding_txo, long monitor_update_id) {
138 long ret = bindings.MonitorEvent_completed(funding_txo == null ? 0 : funding_txo.ptr, monitor_update_id);
139 Reference.reachabilityFence(funding_txo);
140 Reference.reachabilityFence(monitor_update_id);
141 if (ret >= 0 && ret <= 4096) { return null; }
142 org.ldk.structs.MonitorEvent ret_hu_conv = org.ldk.structs.MonitorEvent.constr_from_ptr(ret);
143 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
144 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(funding_txo); };
149 * Checks if two MonitorEvents contain equal inner contents.
150 * This ignores pointers and is_owned flags and looks at the values in fields.
152 public boolean eq(org.ldk.structs.MonitorEvent b) {
153 boolean ret = bindings.MonitorEvent_eq(this.ptr, b == null ? 0 : b.ptr);
154 Reference.reachabilityFence(this);
155 Reference.reachabilityFence(b);
159 @Override public boolean equals(Object o) {
160 if (!(o instanceof MonitorEvent)) return false;
161 return this.eq((MonitorEvent)o);
164 * Serialize the MonitorEvent object into a byte array which can be read by MonitorEvent_read
166 public byte[] write() {
167 byte[] ret = bindings.MonitorEvent_write(this.ptr);
168 Reference.reachabilityFence(this);