1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
11 * An event to be processed by the ChannelManager.
13 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
14 public class MonitorEvent extends CommonBase {
15 private MonitorEvent(Object _dummy, long ptr) { super(ptr); }
16 @Override @SuppressWarnings("deprecation")
17 protected void finalize() throws Throwable {
19 if (ptr != 0) { bindings.MonitorEvent_free(ptr); }
21 static MonitorEvent constr_from_ptr(long ptr) {
22 bindings.LDKMonitorEvent raw_val = bindings.LDKMonitorEvent_ref_from_ptr(ptr);
23 if (raw_val.getClass() == bindings.LDKMonitorEvent.HTLCEvent.class) {
24 return new HTLCEvent(ptr, (bindings.LDKMonitorEvent.HTLCEvent)raw_val);
26 if (raw_val.getClass() == bindings.LDKMonitorEvent.CommitmentTxConfirmed.class) {
27 return new CommitmentTxConfirmed(ptr, (bindings.LDKMonitorEvent.CommitmentTxConfirmed)raw_val);
29 if (raw_val.getClass() == bindings.LDKMonitorEvent.UpdateCompleted.class) {
30 return new UpdateCompleted(ptr, (bindings.LDKMonitorEvent.UpdateCompleted)raw_val);
32 if (raw_val.getClass() == bindings.LDKMonitorEvent.UpdateFailed.class) {
33 return new UpdateFailed(ptr, (bindings.LDKMonitorEvent.UpdateFailed)raw_val);
35 assert false; return null; // Unreachable without extending the (internal) bindings interface
39 * A monitor event containing an HTLCUpdate.
41 public final static class HTLCEvent extends MonitorEvent {
42 public final HTLCUpdate htlc_event;
43 private HTLCEvent(long ptr, bindings.LDKMonitorEvent.HTLCEvent obj) {
45 long htlc_event = obj.htlc_event;
46 HTLCUpdate htlc_event_hu_conv = null; if (htlc_event < 0 || htlc_event > 4096) { htlc_event_hu_conv = new HTLCUpdate(null, htlc_event); }
47 htlc_event_hu_conv.ptrs_to.add(this);
48 this.htlc_event = htlc_event_hu_conv;
52 * A monitor event that the Channel's commitment transaction was confirmed.
54 public final static class CommitmentTxConfirmed extends MonitorEvent {
55 public final OutPoint commitment_tx_confirmed;
56 private CommitmentTxConfirmed(long ptr, bindings.LDKMonitorEvent.CommitmentTxConfirmed obj) {
58 long commitment_tx_confirmed = obj.commitment_tx_confirmed;
59 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); }
60 commitment_tx_confirmed_hu_conv.ptrs_to.add(this);
61 this.commitment_tx_confirmed = commitment_tx_confirmed_hu_conv;
65 * Indicates a [`ChannelMonitor`] update has completed. See
66 * [`ChannelMonitorUpdateErr::TemporaryFailure`] for more information on how this is used.
68 * [`ChannelMonitorUpdateErr::TemporaryFailure`]: super::ChannelMonitorUpdateErr::TemporaryFailure
70 public final static class UpdateCompleted extends MonitorEvent {
72 * The funding outpoint of the [`ChannelMonitor`] that was updated
74 public final OutPoint funding_txo;
76 * The Update ID from [`ChannelMonitorUpdate::update_id`] which was applied or
77 * [`ChannelMonitor::get_latest_update_id`].
79 * Note that this should only be set to a given update's ID if all previous updates for the
80 * same [`ChannelMonitor`] have been applied and persisted.
82 public final long monitor_update_id;
83 private UpdateCompleted(long ptr, bindings.LDKMonitorEvent.UpdateCompleted obj) {
85 long funding_txo = obj.funding_txo;
86 OutPoint funding_txo_hu_conv = null; if (funding_txo < 0 || funding_txo > 4096) { funding_txo_hu_conv = new OutPoint(null, funding_txo); }
87 funding_txo_hu_conv.ptrs_to.add(this);
88 this.funding_txo = funding_txo_hu_conv;
89 this.monitor_update_id = obj.monitor_update_id;
93 * Indicates a [`ChannelMonitor`] update has failed. See
94 * [`ChannelMonitorUpdateErr::PermanentFailure`] for more information on how this is used.
96 * [`ChannelMonitorUpdateErr::PermanentFailure`]: super::ChannelMonitorUpdateErr::PermanentFailure
98 public final static class UpdateFailed extends MonitorEvent {
99 public final OutPoint update_failed;
100 private UpdateFailed(long ptr, bindings.LDKMonitorEvent.UpdateFailed obj) {
102 long update_failed = obj.update_failed;
103 OutPoint update_failed_hu_conv = null; if (update_failed < 0 || update_failed > 4096) { update_failed_hu_conv = new OutPoint(null, update_failed); }
104 update_failed_hu_conv.ptrs_to.add(this);
105 this.update_failed = update_failed_hu_conv;
109 long ret = bindings.MonitorEvent_clone_ptr(this.ptr);
114 * Creates a copy of the MonitorEvent
116 public MonitorEvent clone() {
117 long ret = bindings.MonitorEvent_clone(this.ptr);
118 if (ret >= 0 && ret <= 4096) { return null; }
119 MonitorEvent ret_hu_conv = MonitorEvent.constr_from_ptr(ret);
120 ret_hu_conv.ptrs_to.add(this);
125 * Utility method to constructs a new HTLCEvent-variant MonitorEvent
127 public static MonitorEvent htlcevent(HTLCUpdate a) {
128 long ret = bindings.MonitorEvent_htlcevent(a == null ? 0 : a.ptr & ~1);
129 if (ret >= 0 && ret <= 4096) { return null; }
130 MonitorEvent ret_hu_conv = MonitorEvent.constr_from_ptr(ret);
131 ret_hu_conv.ptrs_to.add(ret_hu_conv);
136 * Utility method to constructs a new CommitmentTxConfirmed-variant MonitorEvent
138 public static MonitorEvent commitment_tx_confirmed(OutPoint a) {
139 long ret = bindings.MonitorEvent_commitment_tx_confirmed(a == null ? 0 : a.ptr & ~1);
140 if (ret >= 0 && ret <= 4096) { return null; }
141 MonitorEvent ret_hu_conv = MonitorEvent.constr_from_ptr(ret);
142 ret_hu_conv.ptrs_to.add(ret_hu_conv);
147 * Utility method to constructs a new UpdateCompleted-variant MonitorEvent
149 public static MonitorEvent update_completed(OutPoint funding_txo, long monitor_update_id) {
150 long ret = bindings.MonitorEvent_update_completed(funding_txo == null ? 0 : funding_txo.ptr & ~1, monitor_update_id);
151 if (ret >= 0 && ret <= 4096) { return null; }
152 MonitorEvent ret_hu_conv = MonitorEvent.constr_from_ptr(ret);
153 ret_hu_conv.ptrs_to.add(ret_hu_conv);
158 * Utility method to constructs a new UpdateFailed-variant MonitorEvent
160 public static MonitorEvent update_failed(OutPoint a) {
161 long ret = bindings.MonitorEvent_update_failed(a == null ? 0 : a.ptr & ~1);
162 if (ret >= 0 && ret <= 4096) { return null; }
163 MonitorEvent ret_hu_conv = MonitorEvent.constr_from_ptr(ret);
164 ret_hu_conv.ptrs_to.add(ret_hu_conv);
169 * Serialize the MonitorEvent object into a byte array which can be read by MonitorEvent_read
171 public byte[] write() {
172 byte[] ret = bindings.MonitorEvent_write(this.ptr);