[C#] Drop reference to `assert` which makes building on Win hard
[ldk-java] / c_sharp / src / org / ldk / structs / MonitorEvent.cs
1 using org.ldk.impl;
2 using org.ldk.enums;
3 using org.ldk.util;
4 using System;
5
6 namespace org { namespace ldk { namespace structs {
7
8 /**
9  * An event to be processed by the ChannelManager.
10  */
11 public class MonitorEvent : CommonBase {
12         protected MonitorEvent(object _dummy, long ptr) : base(ptr) { }
13         ~MonitorEvent() {
14                 if (ptr != 0) { bindings.MonitorEvent_free(ptr); }
15         }
16
17         internal static MonitorEvent constr_from_ptr(long ptr) {
18                 long raw_ty = bindings.LDKMonitorEvent_ty_from_ptr(ptr);
19                 switch (raw_ty) {
20                         case 0: return new MonitorEvent_HTLCEvent(ptr);
21                         case 1: return new MonitorEvent_CommitmentTxConfirmed(ptr);
22                         case 2: return new MonitorEvent_Completed(ptr);
23                         case 3: return new MonitorEvent_UpdateFailed(ptr);
24                         default:
25                                 throw new ArgumentException("Impossible enum variant");
26                 }
27         }
28
29         /** A MonitorEvent of type HTLCEvent */
30         public class MonitorEvent_HTLCEvent : MonitorEvent {
31                 public HTLCUpdate htlc_event;
32                 internal MonitorEvent_HTLCEvent(long ptr) : base(null, ptr) {
33                         long htlc_event = bindings.LDKMonitorEvent_HTLCEvent_get_htlc_event(ptr);
34                         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); }
35                         if (htlc_event_hu_conv != null) { htlc_event_hu_conv.ptrs_to.AddLast(this); };
36                         this.htlc_event = htlc_event_hu_conv;
37                 }
38         }
39         /** A MonitorEvent of type CommitmentTxConfirmed */
40         public class MonitorEvent_CommitmentTxConfirmed : MonitorEvent {
41                 public OutPoint commitment_tx_confirmed;
42                 internal MonitorEvent_CommitmentTxConfirmed(long ptr) : base(null, ptr) {
43                         long commitment_tx_confirmed = bindings.LDKMonitorEvent_CommitmentTxConfirmed_get_commitment_tx_confirmed(ptr);
44                         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); }
45                         if (commitment_tx_confirmed_hu_conv != null) { commitment_tx_confirmed_hu_conv.ptrs_to.AddLast(this); };
46                         this.commitment_tx_confirmed = commitment_tx_confirmed_hu_conv;
47                 }
48         }
49         /** A MonitorEvent of type Completed */
50         public class MonitorEvent_Completed : MonitorEvent {
51                 /**
52                  * The funding outpoint of the [`ChannelMonitor`] that was updated
53                  */
54                 public OutPoint funding_txo;
55                 /**
56                  * The Update ID from [`ChannelMonitorUpdate::update_id`] which was applied or
57                  * [`ChannelMonitor::get_latest_update_id`].
58                  * 
59                  * Note that this should only be set to a given update's ID if all previous updates for the
60                  * same [`ChannelMonitor`] have been applied and persisted.
61                  */
62                 public long monitor_update_id;
63                 internal MonitorEvent_Completed(long ptr) : base(null, ptr) {
64                         long funding_txo = bindings.LDKMonitorEvent_Completed_get_funding_txo(ptr);
65                         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); }
66                         if (funding_txo_hu_conv != null) { funding_txo_hu_conv.ptrs_to.AddLast(this); };
67                         this.funding_txo = funding_txo_hu_conv;
68                         this.monitor_update_id = bindings.LDKMonitorEvent_Completed_get_monitor_update_id(ptr);
69                 }
70         }
71         /** A MonitorEvent of type UpdateFailed */
72         public class MonitorEvent_UpdateFailed : MonitorEvent {
73                 public OutPoint update_failed;
74                 internal MonitorEvent_UpdateFailed(long ptr) : base(null, ptr) {
75                         long update_failed = bindings.LDKMonitorEvent_UpdateFailed_get_update_failed(ptr);
76                         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); }
77                         if (update_failed_hu_conv != null) { update_failed_hu_conv.ptrs_to.AddLast(this); };
78                         this.update_failed = update_failed_hu_conv;
79                 }
80         }
81         internal long clone_ptr() {
82                 long ret = bindings.MonitorEvent_clone_ptr(this.ptr);
83                 GC.KeepAlive(this);
84                 return ret;
85         }
86
87         /**
88          * Creates a copy of the MonitorEvent
89          */
90         public MonitorEvent clone() {
91                 long ret = bindings.MonitorEvent_clone(this.ptr);
92                 GC.KeepAlive(this);
93                 if (ret >= 0 && ret <= 4096) { return null; }
94                 org.ldk.structs.MonitorEvent ret_hu_conv = org.ldk.structs.MonitorEvent.constr_from_ptr(ret);
95                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
96                 return ret_hu_conv;
97         }
98
99         /**
100          * Utility method to constructs a new HTLCEvent-variant MonitorEvent
101          */
102         public static MonitorEvent htlcevent(org.ldk.structs.HTLCUpdate a) {
103                 long ret = bindings.MonitorEvent_htlcevent(a == null ? 0 : a.ptr);
104                 GC.KeepAlive(a);
105                 if (ret >= 0 && ret <= 4096) { return null; }
106                 org.ldk.structs.MonitorEvent ret_hu_conv = org.ldk.structs.MonitorEvent.constr_from_ptr(ret);
107                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
108                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(a); };
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(org.ldk.structs.OutPoint a) {
116                 long ret = bindings.MonitorEvent_commitment_tx_confirmed(a == null ? 0 : a.ptr);
117                 GC.KeepAlive(a);
118                 if (ret >= 0 && ret <= 4096) { return null; }
119                 org.ldk.structs.MonitorEvent ret_hu_conv = org.ldk.structs.MonitorEvent.constr_from_ptr(ret);
120                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
121                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(a); };
122                 return ret_hu_conv;
123         }
124
125         /**
126          * Utility method to constructs a new Completed-variant MonitorEvent
127          */
128         public static MonitorEvent completed(org.ldk.structs.OutPoint funding_txo, long monitor_update_id) {
129                 long ret = bindings.MonitorEvent_completed(funding_txo == null ? 0 : funding_txo.ptr, monitor_update_id);
130                 GC.KeepAlive(funding_txo);
131                 GC.KeepAlive(monitor_update_id);
132                 if (ret >= 0 && ret <= 4096) { return null; }
133                 org.ldk.structs.MonitorEvent ret_hu_conv = org.ldk.structs.MonitorEvent.constr_from_ptr(ret);
134                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
135                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(funding_txo); };
136                 return ret_hu_conv;
137         }
138
139         /**
140          * Utility method to constructs a new UpdateFailed-variant MonitorEvent
141          */
142         public static MonitorEvent update_failed(org.ldk.structs.OutPoint a) {
143                 long ret = bindings.MonitorEvent_update_failed(a == null ? 0 : a.ptr);
144                 GC.KeepAlive(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                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
148                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(a); };
149                 return ret_hu_conv;
150         }
151
152         /**
153          * Checks if two MonitorEvents contain equal inner contents.
154          * This ignores pointers and is_owned flags and looks at the values in fields.
155          */
156         public bool eq(org.ldk.structs.MonitorEvent b) {
157                 bool ret = bindings.MonitorEvent_eq(this.ptr, b == null ? 0 : b.ptr);
158                 GC.KeepAlive(this);
159                 GC.KeepAlive(b);
160                 return ret;
161         }
162
163         public override bool Equals(object o) {
164                 if (!(o is MonitorEvent)) return false;
165                 return this.eq((MonitorEvent)o);
166         }
167         /**
168          * Serialize the MonitorEvent object into a byte array which can be read by MonitorEvent_read
169          */
170         public byte[] write() {
171                 byte[] ret = bindings.MonitorEvent_write(this.ptr);
172                 GC.KeepAlive(this);
173                 return ret;
174         }
175
176 }
177 } } }