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.CommitmentTxConfirmed.class) {
28 return new CommitmentTxConfirmed(ptr, (bindings.LDKMonitorEvent.CommitmentTxConfirmed)raw_val);
30 if (raw_val.getClass() == bindings.LDKMonitorEvent.UpdateCompleted.class) {
31 return new UpdateCompleted(ptr, (bindings.LDKMonitorEvent.UpdateCompleted)raw_val);
33 if (raw_val.getClass() == bindings.LDKMonitorEvent.UpdateFailed.class) {
34 return new UpdateFailed(ptr, (bindings.LDKMonitorEvent.UpdateFailed)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 htlc_event_hu_conv.ptrs_to.add(this);
49 this.htlc_event = htlc_event_hu_conv;
53 * A monitor event that the Channel's commitment transaction was confirmed.
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) {
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 commitment_tx_confirmed_hu_conv.ptrs_to.add(this);
62 this.commitment_tx_confirmed = commitment_tx_confirmed_hu_conv;
66 * Indicates a [`ChannelMonitor`] update has completed. See
67 * [`ChannelMonitorUpdateErr::TemporaryFailure`] for more information on how this is used.
69 * [`ChannelMonitorUpdateErr::TemporaryFailure`]: super::ChannelMonitorUpdateErr::TemporaryFailure
71 public final static class UpdateCompleted extends MonitorEvent {
73 * The funding outpoint of the [`ChannelMonitor`] that was updated
75 public final org.ldk.structs.OutPoint funding_txo;
77 * The Update ID from [`ChannelMonitorUpdate::update_id`] which was applied or
78 * [`ChannelMonitor::get_latest_update_id`].
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.
83 public final long monitor_update_id;
84 private UpdateCompleted(long ptr, bindings.LDKMonitorEvent.UpdateCompleted obj) {
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 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;
94 * Indicates a [`ChannelMonitor`] update has failed. See
95 * [`ChannelMonitorUpdateErr::PermanentFailure`] for more information on how this is used.
97 * [`ChannelMonitorUpdateErr::PermanentFailure`]: super::ChannelMonitorUpdateErr::PermanentFailure
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) {
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 update_failed_hu_conv.ptrs_to.add(this);
106 this.update_failed = update_failed_hu_conv;
110 long ret = bindings.MonitorEvent_clone_ptr(this.ptr);
111 Reference.reachabilityFence(this);
116 * Creates a copy of the MonitorEvent
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);
128 * Utility method to constructs a new HTLCEvent-variant MonitorEvent
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);
140 * Utility method to constructs a new CommitmentTxConfirmed-variant MonitorEvent
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);
152 * Utility method to constructs a new UpdateCompleted-variant MonitorEvent
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);
165 * Utility method to constructs a new UpdateFailed-variant MonitorEvent
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);
177 * Serialize the MonitorEvent object into a byte array which can be read by MonitorEvent_read
179 public byte[] write() {
180 byte[] ret = bindings.MonitorEvent_write(this.ptr);
181 Reference.reachabilityFence(this);