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
38 public final static class HTLCEvent extends MonitorEvent {
39 public final HTLCUpdate htlc_event;
40 private HTLCEvent(long ptr, bindings.LDKMonitorEvent.HTLCEvent obj) {
42 long htlc_event = obj.htlc_event;
43 HTLCUpdate htlc_event_hu_conv = null; if (htlc_event < 0 || htlc_event > 4096) { htlc_event_hu_conv = new HTLCUpdate(null, htlc_event); }
44 htlc_event_hu_conv.ptrs_to.add(this);
45 this.htlc_event = htlc_event_hu_conv;
48 public final static class CommitmentTxConfirmed extends MonitorEvent {
49 public final OutPoint commitment_tx_confirmed;
50 private CommitmentTxConfirmed(long ptr, bindings.LDKMonitorEvent.CommitmentTxConfirmed obj) {
52 long commitment_tx_confirmed = obj.commitment_tx_confirmed;
53 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); }
54 commitment_tx_confirmed_hu_conv.ptrs_to.add(this);
55 this.commitment_tx_confirmed = commitment_tx_confirmed_hu_conv;
58 public final static class UpdateCompleted extends MonitorEvent {
60 * The funding outpoint of the [`ChannelMonitor`] that was updated
62 public final OutPoint funding_txo;
64 * The Update ID from [`ChannelMonitorUpdate::update_id`] which was applied or
65 * [`ChannelMonitor::get_latest_update_id`].
67 * Note that this should only be set to a given update's ID if all previous updates for the
68 * same [`ChannelMonitor`] have been applied and persisted.
70 public final long monitor_update_id;
71 private UpdateCompleted(long ptr, bindings.LDKMonitorEvent.UpdateCompleted obj) {
73 long funding_txo = obj.funding_txo;
74 OutPoint funding_txo_hu_conv = null; if (funding_txo < 0 || funding_txo > 4096) { funding_txo_hu_conv = new OutPoint(null, funding_txo); }
75 funding_txo_hu_conv.ptrs_to.add(this);
76 this.funding_txo = funding_txo_hu_conv;
77 this.monitor_update_id = obj.monitor_update_id;
80 public final static class UpdateFailed extends MonitorEvent {
81 public final OutPoint update_failed;
82 private UpdateFailed(long ptr, bindings.LDKMonitorEvent.UpdateFailed obj) {
84 long update_failed = obj.update_failed;
85 OutPoint update_failed_hu_conv = null; if (update_failed < 0 || update_failed > 4096) { update_failed_hu_conv = new OutPoint(null, update_failed); }
86 update_failed_hu_conv.ptrs_to.add(this);
87 this.update_failed = update_failed_hu_conv;
91 * Creates a copy of the MonitorEvent
93 public MonitorEvent clone() {
94 long ret = bindings.MonitorEvent_clone(this.ptr);
95 if (ret >= 0 && ret <= 4096) { return null; }
96 MonitorEvent ret_hu_conv = MonitorEvent.constr_from_ptr(ret);
97 ret_hu_conv.ptrs_to.add(this);
102 * Utility method to constructs a new HTLCEvent-variant MonitorEvent
104 public static MonitorEvent htlcevent(HTLCUpdate a) {
105 long ret = bindings.MonitorEvent_htlcevent(a == null ? 0 : a.ptr & ~1);
106 if (ret >= 0 && ret <= 4096) { return null; }
107 MonitorEvent ret_hu_conv = MonitorEvent.constr_from_ptr(ret);
108 ret_hu_conv.ptrs_to.add(ret_hu_conv);
113 * Utility method to constructs a new CommitmentTxConfirmed-variant MonitorEvent
115 public static MonitorEvent commitment_tx_confirmed(OutPoint a) {
116 long ret = bindings.MonitorEvent_commitment_tx_confirmed(a == null ? 0 : a.ptr & ~1);
117 if (ret >= 0 && ret <= 4096) { return null; }
118 MonitorEvent ret_hu_conv = MonitorEvent.constr_from_ptr(ret);
119 ret_hu_conv.ptrs_to.add(ret_hu_conv);
124 * Utility method to constructs a new UpdateCompleted-variant MonitorEvent
126 public static MonitorEvent update_completed(OutPoint funding_txo, long monitor_update_id) {
127 long ret = bindings.MonitorEvent_update_completed(funding_txo == null ? 0 : funding_txo.ptr & ~1, monitor_update_id);
128 if (ret >= 0 && ret <= 4096) { return null; }
129 MonitorEvent ret_hu_conv = MonitorEvent.constr_from_ptr(ret);
130 ret_hu_conv.ptrs_to.add(ret_hu_conv);
135 * Utility method to constructs a new UpdateFailed-variant MonitorEvent
137 public static MonitorEvent update_failed(OutPoint a) {
138 long ret = bindings.MonitorEvent_update_failed(a == null ? 0 : a.ptr & ~1);
139 if (ret >= 0 && ret <= 4096) { return null; }
140 MonitorEvent ret_hu_conv = MonitorEvent.constr_from_ptr(ret);
141 ret_hu_conv.ptrs_to.add(ret_hu_conv);
146 * Serialize the MonitorEvent object into a byte array which can be read by MonitorEvent_read
148 public byte[] write() {
149 byte[] ret = bindings.MonitorEvent_write(this.ptr);