38a63b38a112bf8a488127346129cd09bdd5976b
[ldk-java] / src / main / java / org / ldk / structs / MonitorEvent.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
8
9
10 /**
11  * An event to be processed by the ChannelManager.
12  */
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 {
18                 super.finalize();
19                 if (ptr != 0) { bindings.MonitorEvent_free(ptr); }
20         }
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);
25                 }
26                 if (raw_val.getClass() == bindings.LDKMonitorEvent.CommitmentTxConfirmed.class) {
27                         return new CommitmentTxConfirmed(ptr, (bindings.LDKMonitorEvent.CommitmentTxConfirmed)raw_val);
28                 }
29                 if (raw_val.getClass() == bindings.LDKMonitorEvent.UpdateCompleted.class) {
30                         return new UpdateCompleted(ptr, (bindings.LDKMonitorEvent.UpdateCompleted)raw_val);
31                 }
32                 if (raw_val.getClass() == bindings.LDKMonitorEvent.UpdateFailed.class) {
33                         return new UpdateFailed(ptr, (bindings.LDKMonitorEvent.UpdateFailed)raw_val);
34                 }
35                 assert false; return null; // Unreachable without extending the (internal) bindings interface
36         }
37
38         /**
39          * A monitor event containing an HTLCUpdate.
40          */
41         public final static class HTLCEvent extends MonitorEvent {
42                 public final HTLCUpdate htlc_event;
43                 private HTLCEvent(long ptr, bindings.LDKMonitorEvent.HTLCEvent obj) {
44                         super(null, ptr);
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;
49                 }
50         }
51         /**
52          * A monitor event that the Channel's commitment transaction was confirmed.
53          */
54         public final static class CommitmentTxConfirmed extends MonitorEvent {
55                 public final OutPoint commitment_tx_confirmed;
56                 private CommitmentTxConfirmed(long ptr, bindings.LDKMonitorEvent.CommitmentTxConfirmed obj) {
57                         super(null, ptr);
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;
62                 }
63         }
64         /**
65          * Indicates a [`ChannelMonitor`] update has completed. See
66          * [`ChannelMonitorUpdateErr::TemporaryFailure`] for more information on how this is used.
67          * 
68          * [`ChannelMonitorUpdateErr::TemporaryFailure`]: super::ChannelMonitorUpdateErr::TemporaryFailure
69          */
70         public final static class UpdateCompleted extends MonitorEvent {
71                 /**
72                  * The funding outpoint of the [`ChannelMonitor`] that was updated
73                 */
74                 public final OutPoint funding_txo;
75                 /**
76                  * The Update ID from [`ChannelMonitorUpdate::update_id`] which was applied or
77                  * [`ChannelMonitor::get_latest_update_id`].
78                  * 
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.
81                 */
82                 public final long monitor_update_id;
83                 private UpdateCompleted(long ptr, bindings.LDKMonitorEvent.UpdateCompleted obj) {
84                         super(null, ptr);
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;
90                 }
91         }
92         /**
93          * Indicates a [`ChannelMonitor`] update has failed. See
94          * [`ChannelMonitorUpdateErr::PermanentFailure`] for more information on how this is used.
95          * 
96          * [`ChannelMonitorUpdateErr::PermanentFailure`]: super::ChannelMonitorUpdateErr::PermanentFailure
97          */
98         public final static class UpdateFailed extends MonitorEvent {
99                 public final OutPoint update_failed;
100                 private UpdateFailed(long ptr, bindings.LDKMonitorEvent.UpdateFailed obj) {
101                         super(null, ptr);
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;
106                 }
107         }
108         long clone_ptr() {
109                 long ret = bindings.MonitorEvent_clone_ptr(this.ptr);
110                 return ret;
111         }
112
113         /**
114          * Creates a copy of the MonitorEvent
115          */
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);
121                 return ret_hu_conv;
122         }
123
124         /**
125          * Utility method to constructs a new HTLCEvent-variant MonitorEvent
126          */
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);
132                 return ret_hu_conv;
133         }
134
135         /**
136          * Utility method to constructs a new CommitmentTxConfirmed-variant MonitorEvent
137          */
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);
143                 return ret_hu_conv;
144         }
145
146         /**
147          * Utility method to constructs a new UpdateCompleted-variant MonitorEvent
148          */
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);
154                 return ret_hu_conv;
155         }
156
157         /**
158          * Utility method to constructs a new UpdateFailed-variant MonitorEvent
159          */
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);
165                 return ret_hu_conv;
166         }
167
168         /**
169          * Serialize the MonitorEvent object into a byte array which can be read by MonitorEvent_read
170          */
171         public byte[] write() {
172                 byte[] ret = bindings.MonitorEvent_write(this.ptr);
173                 return ret;
174         }
175
176 }