Update auto-generated bindings to 0.0.103
[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         public final static class HTLCEvent extends MonitorEvent {
39                 public final HTLCUpdate htlc_event;
40                 private HTLCEvent(long ptr, bindings.LDKMonitorEvent.HTLCEvent obj) {
41                         super(null, ptr);
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;
46                 }
47         }
48         public final static class CommitmentTxConfirmed extends MonitorEvent {
49                 public final OutPoint commitment_tx_confirmed;
50                 private CommitmentTxConfirmed(long ptr, bindings.LDKMonitorEvent.CommitmentTxConfirmed obj) {
51                         super(null, ptr);
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;
56                 }
57         }
58         public final static class UpdateCompleted extends MonitorEvent {
59                 /**
60                  * The funding outpoint of the [`ChannelMonitor`] that was updated
61                 */
62                 public final OutPoint funding_txo;
63                 /**
64                  * The Update ID from [`ChannelMonitorUpdate::update_id`] which was applied or
65                  * [`ChannelMonitor::get_latest_update_id`].
66                  * 
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.
69                 */
70                 public final long monitor_update_id;
71                 private UpdateCompleted(long ptr, bindings.LDKMonitorEvent.UpdateCompleted obj) {
72                         super(null, ptr);
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;
78                 }
79         }
80         public final static class UpdateFailed extends MonitorEvent {
81                 public final OutPoint update_failed;
82                 private UpdateFailed(long ptr, bindings.LDKMonitorEvent.UpdateFailed obj) {
83                         super(null, ptr);
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;
88                 }
89         }
90         /**
91          * Creates a copy of the MonitorEvent
92          */
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);
98                 return ret_hu_conv;
99         }
100
101         /**
102          * Utility method to constructs a new HTLCEvent-variant MonitorEvent
103          */
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);
109                 return ret_hu_conv;
110         }
111
112         /**
113          * Utility method to constructs a new CommitmentTxConfirmed-variant MonitorEvent
114          */
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);
120                 return ret_hu_conv;
121         }
122
123         /**
124          * Utility method to constructs a new UpdateCompleted-variant MonitorEvent
125          */
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);
131                 return ret_hu_conv;
132         }
133
134         /**
135          * Utility method to constructs a new UpdateFailed-variant MonitorEvent
136          */
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);
142                 return ret_hu_conv;
143         }
144
145         /**
146          * Serialize the MonitorEvent object into a byte array which can be read by MonitorEvent_read
147          */
148         public byte[] write() {
149                 byte[] ret = bindings.MonitorEvent_write(this.ptr);
150                 return ret;
151         }
152
153 }