[C#] Update auto-generated files
[ldk-java] / c_sharp / src / org / ldk / structs / Persist.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  * `Persist` defines behavior for persisting channel monitors: this could mean
10  * writing once to disk, and/or uploading to one or more backup services.
11  * 
12  * Each method can return three possible values:
13  * If persistence (including any relevant `fsync()` calls) happens immediately, the
14  * implementation should return [`ChannelMonitorUpdateStatus::Completed`], indicating normal
15  * channel operation should continue.
16  * If persistence happens asynchronously, implementations should first ensure the
17  * [`ChannelMonitor`] or [`ChannelMonitorUpdate`] are written durably to disk, and then return
18  * [`ChannelMonitorUpdateStatus::InProgress`] while the update continues in the background.
19  * Once the update completes, [`ChainMonitor::channel_monitor_updated`] should be called with
20  * the corresponding [`MonitorUpdateId`].
21  * 
22  * Note that unlike the direct [`chain::Watch`] interface,
23  * [`ChainMonitor::channel_monitor_updated`] must be called once for *each* update which occurs.
24  * 
25  * If persistence fails for some reason, implementations should return
26  * [`ChannelMonitorUpdateStatus::PermanentFailure`], in which case the channel will likely be
27  * closed without broadcasting the latest state. See
28  * [`ChannelMonitorUpdateStatus::PermanentFailure`] for more details.
29  */
30 public class Persist : CommonBase {
31         internal readonly bindings.LDKPersist bindings_instance;
32         internal Persist(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
33         private Persist(bindings.LDKPersist arg) : base(bindings.LDKPersist_new(arg)) {
34                 this.ptrs_to.AddLast(arg);
35                 this.bindings_instance = arg;
36         }
37         ~Persist() {
38                 if (ptr != 0) { bindings.Persist_free(ptr); }
39         }
40
41         public interface PersistInterface {
42                 /**
43                  * Persist a new channel's data in response to a [`chain::Watch::watch_channel`] call. This is
44                  * called by [`ChannelManager`] for new channels, or may be called directly, e.g. on startup.
45                  * 
46                  * The data can be stored any way you want, but the identifier provided by LDK is the
47                  * channel's outpoint (and it is up to you to maintain a correct mapping between the outpoint
48                  * and the stored channel data). Note that you **must** persist every new monitor to disk.
49                  * 
50                  * The `update_id` is used to identify this call to [`ChainMonitor::channel_monitor_updated`],
51                  * if you return [`ChannelMonitorUpdateStatus::InProgress`].
52                  * 
53                  * See [`Writeable::write`] on [`ChannelMonitor`] for writing out a `ChannelMonitor`
54                  * and [`ChannelMonitorUpdateStatus`] for requirements when returning errors.
55                  * 
56                  * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
57                  * [`Writeable::write`]: crate::util::ser::Writeable::write
58                  */
59                 ChannelMonitorUpdateStatus persist_new_channel(OutPoint _channel_id, ChannelMonitor _data, MonitorUpdateId _update_id);
60                 /**
61                  * Update one channel's data. The provided [`ChannelMonitor`] has already applied the given
62                  * update.
63                  * 
64                  * Note that on every update, you **must** persist either the [`ChannelMonitorUpdate`] or the
65                  * updated monitor itself to disk/backups. See the [`Persist`] trait documentation for more
66                  * details.
67                  * 
68                  * During blockchain synchronization operations, this may be called with no
69                  * [`ChannelMonitorUpdate`], in which case the full [`ChannelMonitor`] needs to be persisted.
70                  * Note that after the full [`ChannelMonitor`] is persisted any previous
71                  * [`ChannelMonitorUpdate`]s which were persisted should be discarded - they can no longer be
72                  * applied to the persisted [`ChannelMonitor`] as they were already applied.
73                  * 
74                  * If an implementer chooses to persist the updates only, they need to make
75                  * sure that all the updates are applied to the `ChannelMonitors` *before
76                  * the set of channel monitors is given to the `ChannelManager`
77                  * deserialization routine. See [`ChannelMonitor::update_monitor`] for
78                  * applying a monitor update to a monitor. If full `ChannelMonitors` are
79                  * persisted, then there is no need to persist individual updates.
80                  * 
81                  * Note that there could be a performance tradeoff between persisting complete
82                  * channel monitors on every update vs. persisting only updates and applying
83                  * them in batches. The size of each monitor grows `O(number of state updates)`
84                  * whereas updates are small and `O(1)`.
85                  * 
86                  * The `update_id` is used to identify this call to [`ChainMonitor::channel_monitor_updated`],
87                  * if you return [`ChannelMonitorUpdateStatus::InProgress`].
88                  * 
89                  * See [`Writeable::write`] on [`ChannelMonitor`] for writing out a `ChannelMonitor`,
90                  * [`Writeable::write`] on [`ChannelMonitorUpdate`] for writing out an update, and
91                  * [`ChannelMonitorUpdateStatus`] for requirements when returning errors.
92                  * 
93                  * [`Writeable::write`]: crate::util::ser::Writeable::write
94                  * 
95                  * Note that update (or a relevant inner pointer) may be NULL or all-0s to represent None
96                  */
97                 ChannelMonitorUpdateStatus update_persisted_channel(OutPoint _channel_id, ChannelMonitorUpdate _update, ChannelMonitor _data, MonitorUpdateId _update_id);
98         }
99         private class LDKPersistHolder { internal Persist held; }
100         private class LDKPersistImpl : bindings.LDKPersist {
101                 internal LDKPersistImpl(PersistInterface arg, LDKPersistHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
102                 private PersistInterface arg;
103                 private LDKPersistHolder impl_holder;
104                 public ChannelMonitorUpdateStatus persist_new_channel(long _channel_id, long _data, long _update_id) {
105                         org.ldk.structs.OutPoint _channel_id_hu_conv = null; if (_channel_id < 0 || _channel_id > 4096) { _channel_id_hu_conv = new org.ldk.structs.OutPoint(null, _channel_id); }
106                         if (_channel_id_hu_conv != null) { _channel_id_hu_conv.ptrs_to.AddLast(this); };
107                         org.ldk.structs.ChannelMonitor _data_hu_conv = null; if (_data < 0 || _data > 4096) { _data_hu_conv = new org.ldk.structs.ChannelMonitor(null, _data); }
108                         org.ldk.structs.MonitorUpdateId _update_id_hu_conv = null; if (_update_id < 0 || _update_id > 4096) { _update_id_hu_conv = new org.ldk.structs.MonitorUpdateId(null, _update_id); }
109                         if (_update_id_hu_conv != null) { _update_id_hu_conv.ptrs_to.AddLast(this); };
110                         ChannelMonitorUpdateStatus ret = arg.persist_new_channel(_channel_id_hu_conv, _data_hu_conv, _update_id_hu_conv);
111                                 GC.KeepAlive(arg);
112                         return ret;
113                 }
114                 public ChannelMonitorUpdateStatus update_persisted_channel(long _channel_id, long _update, long _data, long _update_id) {
115                         org.ldk.structs.OutPoint _channel_id_hu_conv = null; if (_channel_id < 0 || _channel_id > 4096) { _channel_id_hu_conv = new org.ldk.structs.OutPoint(null, _channel_id); }
116                         if (_channel_id_hu_conv != null) { _channel_id_hu_conv.ptrs_to.AddLast(this); };
117                         org.ldk.structs.ChannelMonitorUpdate _update_hu_conv = null; if (_update < 0 || _update > 4096) { _update_hu_conv = new org.ldk.structs.ChannelMonitorUpdate(null, _update); }
118                         if (_update_hu_conv != null) { _update_hu_conv.ptrs_to.AddLast(this); };
119                         org.ldk.structs.ChannelMonitor _data_hu_conv = null; if (_data < 0 || _data > 4096) { _data_hu_conv = new org.ldk.structs.ChannelMonitor(null, _data); }
120                         org.ldk.structs.MonitorUpdateId _update_id_hu_conv = null; if (_update_id < 0 || _update_id > 4096) { _update_id_hu_conv = new org.ldk.structs.MonitorUpdateId(null, _update_id); }
121                         if (_update_id_hu_conv != null) { _update_id_hu_conv.ptrs_to.AddLast(this); };
122                         ChannelMonitorUpdateStatus ret = arg.update_persisted_channel(_channel_id_hu_conv, _update_hu_conv, _data_hu_conv, _update_id_hu_conv);
123                                 GC.KeepAlive(arg);
124                         return ret;
125                 }
126         }
127         public static Persist new_impl(PersistInterface arg) {
128                 LDKPersistHolder impl_holder = new LDKPersistHolder();
129                 impl_holder.held = new Persist(new LDKPersistImpl(arg, impl_holder));
130                 return impl_holder.held;
131         }
132         /**
133          * Persist a new channel's data in response to a [`chain::Watch::watch_channel`] call. This is
134          * called by [`ChannelManager`] for new channels, or may be called directly, e.g. on startup.
135          * 
136          * The data can be stored any way you want, but the identifier provided by LDK is the
137          * channel's outpoint (and it is up to you to maintain a correct mapping between the outpoint
138          * and the stored channel data). Note that you **must** persist every new monitor to disk.
139          * 
140          * The `update_id` is used to identify this call to [`ChainMonitor::channel_monitor_updated`],
141          * if you return [`ChannelMonitorUpdateStatus::InProgress`].
142          * 
143          * See [`Writeable::write`] on [`ChannelMonitor`] for writing out a `ChannelMonitor`
144          * and [`ChannelMonitorUpdateStatus`] for requirements when returning errors.
145          * 
146          * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
147          * [`Writeable::write`]: crate::util::ser::Writeable::write
148          */
149         public ChannelMonitorUpdateStatus persist_new_channel(org.ldk.structs.OutPoint channel_id, org.ldk.structs.ChannelMonitor data, org.ldk.structs.MonitorUpdateId update_id) {
150                 ChannelMonitorUpdateStatus ret = bindings.Persist_persist_new_channel(this.ptr, channel_id == null ? 0 : channel_id.ptr, data == null ? 0 : data.ptr, update_id == null ? 0 : update_id.ptr);
151                 GC.KeepAlive(this);
152                 GC.KeepAlive(channel_id);
153                 GC.KeepAlive(data);
154                 GC.KeepAlive(update_id);
155                 if (this != null) { this.ptrs_to.AddLast(channel_id); };
156                 if (this != null) { this.ptrs_to.AddLast(data); };
157                 if (this != null) { this.ptrs_to.AddLast(update_id); };
158                 return ret;
159         }
160
161         /**
162          * Update one channel's data. The provided [`ChannelMonitor`] has already applied the given
163          * update.
164          * 
165          * Note that on every update, you **must** persist either the [`ChannelMonitorUpdate`] or the
166          * updated monitor itself to disk/backups. See the [`Persist`] trait documentation for more
167          * details.
168          * 
169          * During blockchain synchronization operations, this may be called with no
170          * [`ChannelMonitorUpdate`], in which case the full [`ChannelMonitor`] needs to be persisted.
171          * Note that after the full [`ChannelMonitor`] is persisted any previous
172          * [`ChannelMonitorUpdate`]s which were persisted should be discarded - they can no longer be
173          * applied to the persisted [`ChannelMonitor`] as they were already applied.
174          * 
175          * If an implementer chooses to persist the updates only, they need to make
176          * sure that all the updates are applied to the `ChannelMonitors` *before
177          * the set of channel monitors is given to the `ChannelManager`
178          * deserialization routine. See [`ChannelMonitor::update_monitor`] for
179          * applying a monitor update to a monitor. If full `ChannelMonitors` are
180          * persisted, then there is no need to persist individual updates.
181          * 
182          * Note that there could be a performance tradeoff between persisting complete
183          * channel monitors on every update vs. persisting only updates and applying
184          * them in batches. The size of each monitor grows `O(number of state updates)`
185          * whereas updates are small and `O(1)`.
186          * 
187          * The `update_id` is used to identify this call to [`ChainMonitor::channel_monitor_updated`],
188          * if you return [`ChannelMonitorUpdateStatus::InProgress`].
189          * 
190          * See [`Writeable::write`] on [`ChannelMonitor`] for writing out a `ChannelMonitor`,
191          * [`Writeable::write`] on [`ChannelMonitorUpdate`] for writing out an update, and
192          * [`ChannelMonitorUpdateStatus`] for requirements when returning errors.
193          * 
194          * [`Writeable::write`]: crate::util::ser::Writeable::write
195          * 
196          * Note that update (or a relevant inner pointer) may be NULL or all-0s to represent None
197          */
198         public ChannelMonitorUpdateStatus update_persisted_channel(org.ldk.structs.OutPoint channel_id, org.ldk.structs.ChannelMonitorUpdate update, org.ldk.structs.ChannelMonitor data, org.ldk.structs.MonitorUpdateId update_id) {
199                 ChannelMonitorUpdateStatus ret = bindings.Persist_update_persisted_channel(this.ptr, channel_id == null ? 0 : channel_id.ptr, update == null ? 0 : update.ptr, data == null ? 0 : data.ptr, update_id == null ? 0 : update_id.ptr);
200                 GC.KeepAlive(this);
201                 GC.KeepAlive(channel_id);
202                 GC.KeepAlive(update);
203                 GC.KeepAlive(data);
204                 GC.KeepAlive(update_id);
205                 if (this != null) { this.ptrs_to.AddLast(channel_id); };
206                 if (this != null) { this.ptrs_to.AddLast(update); };
207                 if (this != null) { this.ptrs_to.AddLast(data); };
208                 if (this != null) { this.ptrs_to.AddLast(update_id); };
209                 return ret;
210         }
211
212 }
213 } } }