39b2893c8a08fd39414d0f53ae1fac3e92a14a95
[ldk-java] / c_sharp / src / org / ldk / structs / ChannelManagerReadArgs.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 /**
10  * Arguments for the creation of a ChannelManager that are not deserialized.
11  * 
12  * At a high-level, the process for deserializing a ChannelManager and resuming normal operation
13  * is:
14  * 1) Deserialize all stored [`ChannelMonitor`]s.
15  * 2) Deserialize the [`ChannelManager`] by filling in this struct and calling:
16  * `<(BlockHash, ChannelManager)>::read(reader, args)`
17  * This may result in closing some channels if the [`ChannelMonitor`] is newer than the stored
18  * [`ChannelManager`] state to ensure no loss of funds. Thus, transactions may be broadcasted.
19  * 3) If you are not fetching full blocks, register all relevant [`ChannelMonitor`] outpoints the
20  * same way you would handle a [`chain::Filter`] call using
21  * [`ChannelMonitor::get_outputs_to_watch`] and [`ChannelMonitor::get_funding_txo`].
22  * 4) Reconnect blocks on your [`ChannelMonitor`]s.
23  * 5) Disconnect/connect blocks on the [`ChannelManager`].
24  * 6) Re-persist the [`ChannelMonitor`]s to ensure the latest state is on disk.
25  * Note that if you're using a [`ChainMonitor`] for your [`chain::Watch`] implementation, you
26  * will likely accomplish this as a side-effect of calling [`chain::Watch::watch_channel`] in
27  * the next step.
28  * 7) Move the [`ChannelMonitor`]s into your local [`chain::Watch`]. If you're using a
29  * [`ChainMonitor`], this is done by calling [`chain::Watch::watch_channel`].
30  * 
31  * Note that the ordering of #4-7 is not of importance, however all four must occur before you
32  * call any other methods on the newly-deserialized [`ChannelManager`].
33  * 
34  * Note that because some channels may be closed during deserialization, it is critical that you
35  * always deserialize only the latest version of a ChannelManager and ChannelMonitors available to
36  * you. If you deserialize an old ChannelManager (during which force-closure transactions may be
37  * broadcast), and then later deserialize a newer version of the same ChannelManager (which will
38  * not force-close the same channels but consider them live), you may end up revoking a state for
39  * which you've already broadcasted the transaction.
40  * 
41  * [`ChainMonitor`]: crate::chain::chainmonitor::ChainMonitor
42  */
43 public class ChannelManagerReadArgs : CommonBase {
44         internal ChannelManagerReadArgs(object _dummy, long ptr) : base(ptr) { }
45         ~ChannelManagerReadArgs() {
46                 if (ptr != 0) { bindings.ChannelManagerReadArgs_free(ptr); }
47         }
48
49         /**
50          * The keys provider which will give us relevant keys. Some keys will be loaded during
51          * deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
52          * signing data.
53          */
54         public KeysInterface get_keys_manager() {
55                 long ret = bindings.ChannelManagerReadArgs_get_keys_manager(this.ptr);
56                 GC.KeepAlive(this);
57                 if (ret >= 0 && ret <= 4096) { return null; }
58                 KeysInterface ret_hu_conv = new KeysInterface(null, ret);
59                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
60                 return ret_hu_conv;
61         }
62
63         /**
64          * The keys provider which will give us relevant keys. Some keys will be loaded during
65          * deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
66          * signing data.
67          */
68         public void set_keys_manager(org.ldk.structs.KeysInterface val) {
69                 bindings.ChannelManagerReadArgs_set_keys_manager(this.ptr, val == null ? 0 : val.ptr);
70                 GC.KeepAlive(this);
71                 GC.KeepAlive(val);
72                 if (this != null) { this.ptrs_to.AddLast(val); };
73         }
74
75         /**
76          * The fee_estimator for use in the ChannelManager in the future.
77          * 
78          * No calls to the FeeEstimator will be made during deserialization.
79          */
80         public FeeEstimator get_fee_estimator() {
81                 long ret = bindings.ChannelManagerReadArgs_get_fee_estimator(this.ptr);
82                 GC.KeepAlive(this);
83                 if (ret >= 0 && ret <= 4096) { return null; }
84                 FeeEstimator ret_hu_conv = new FeeEstimator(null, ret);
85                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
86                 return ret_hu_conv;
87         }
88
89         /**
90          * The fee_estimator for use in the ChannelManager in the future.
91          * 
92          * No calls to the FeeEstimator will be made during deserialization.
93          */
94         public void set_fee_estimator(org.ldk.structs.FeeEstimator val) {
95                 bindings.ChannelManagerReadArgs_set_fee_estimator(this.ptr, val == null ? 0 : val.ptr);
96                 GC.KeepAlive(this);
97                 GC.KeepAlive(val);
98                 if (this != null) { this.ptrs_to.AddLast(val); };
99         }
100
101         /**
102          * The chain::Watch for use in the ChannelManager in the future.
103          * 
104          * No calls to the chain::Watch will be made during deserialization. It is assumed that
105          * you have deserialized ChannelMonitors separately and will add them to your
106          * chain::Watch after deserializing this ChannelManager.
107          */
108         public Watch get_chain_monitor() {
109                 long ret = bindings.ChannelManagerReadArgs_get_chain_monitor(this.ptr);
110                 GC.KeepAlive(this);
111                 if (ret >= 0 && ret <= 4096) { return null; }
112                 Watch ret_hu_conv = new Watch(null, ret);
113                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
114                 return ret_hu_conv;
115         }
116
117         /**
118          * The chain::Watch for use in the ChannelManager in the future.
119          * 
120          * No calls to the chain::Watch will be made during deserialization. It is assumed that
121          * you have deserialized ChannelMonitors separately and will add them to your
122          * chain::Watch after deserializing this ChannelManager.
123          */
124         public void set_chain_monitor(org.ldk.structs.Watch val) {
125                 bindings.ChannelManagerReadArgs_set_chain_monitor(this.ptr, val == null ? 0 : val.ptr);
126                 GC.KeepAlive(this);
127                 GC.KeepAlive(val);
128                 if (this != null) { this.ptrs_to.AddLast(val); };
129         }
130
131         /**
132          * The BroadcasterInterface which will be used in the ChannelManager in the future and may be
133          * used to broadcast the latest local commitment transactions of channels which must be
134          * force-closed during deserialization.
135          */
136         public BroadcasterInterface get_tx_broadcaster() {
137                 long ret = bindings.ChannelManagerReadArgs_get_tx_broadcaster(this.ptr);
138                 GC.KeepAlive(this);
139                 if (ret >= 0 && ret <= 4096) { return null; }
140                 BroadcasterInterface ret_hu_conv = new BroadcasterInterface(null, ret);
141                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
142                 return ret_hu_conv;
143         }
144
145         /**
146          * The BroadcasterInterface which will be used in the ChannelManager in the future and may be
147          * used to broadcast the latest local commitment transactions of channels which must be
148          * force-closed during deserialization.
149          */
150         public void set_tx_broadcaster(org.ldk.structs.BroadcasterInterface val) {
151                 bindings.ChannelManagerReadArgs_set_tx_broadcaster(this.ptr, val == null ? 0 : val.ptr);
152                 GC.KeepAlive(this);
153                 GC.KeepAlive(val);
154                 if (this != null) { this.ptrs_to.AddLast(val); };
155         }
156
157         /**
158          * The Logger for use in the ChannelManager and which may be used to log information during
159          * deserialization.
160          */
161         public Logger get_logger() {
162                 long ret = bindings.ChannelManagerReadArgs_get_logger(this.ptr);
163                 GC.KeepAlive(this);
164                 if (ret >= 0 && ret <= 4096) { return null; }
165                 Logger ret_hu_conv = new Logger(null, ret);
166                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
167                 return ret_hu_conv;
168         }
169
170         /**
171          * The Logger for use in the ChannelManager and which may be used to log information during
172          * deserialization.
173          */
174         public void set_logger(org.ldk.structs.Logger val) {
175                 bindings.ChannelManagerReadArgs_set_logger(this.ptr, val == null ? 0 : val.ptr);
176                 GC.KeepAlive(this);
177                 GC.KeepAlive(val);
178                 if (this != null) { this.ptrs_to.AddLast(val); };
179         }
180
181         /**
182          * Default settings used for new channels. Any existing channels will continue to use the
183          * runtime settings which were stored when the ChannelManager was serialized.
184          */
185         public UserConfig get_default_config() {
186                 long ret = bindings.ChannelManagerReadArgs_get_default_config(this.ptr);
187                 GC.KeepAlive(this);
188                 if (ret >= 0 && ret <= 4096) { return null; }
189                 org.ldk.structs.UserConfig ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.UserConfig(null, ret); }
190                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
191                 return ret_hu_conv;
192         }
193
194         /**
195          * Default settings used for new channels. Any existing channels will continue to use the
196          * runtime settings which were stored when the ChannelManager was serialized.
197          */
198         public void set_default_config(org.ldk.structs.UserConfig val) {
199                 bindings.ChannelManagerReadArgs_set_default_config(this.ptr, val == null ? 0 : val.ptr);
200                 GC.KeepAlive(this);
201                 GC.KeepAlive(val);
202                 if (this != null) { this.ptrs_to.AddLast(val); };
203         }
204
205         /**
206          * Simple utility function to create a ChannelManagerReadArgs which creates the monitor
207          * HashMap for you. This is primarily useful for C bindings where it is not practical to
208          * populate a HashMap directly from C.
209          */
210         public static ChannelManagerReadArgs of(org.ldk.structs.KeysInterface keys_manager, org.ldk.structs.FeeEstimator fee_estimator, org.ldk.structs.Watch chain_monitor, org.ldk.structs.BroadcasterInterface tx_broadcaster, org.ldk.structs.Logger logger, org.ldk.structs.UserConfig default_config, ChannelMonitor[] channel_monitors) {
211                 long ret = bindings.ChannelManagerReadArgs_new(keys_manager == null ? 0 : keys_manager.ptr, fee_estimator == null ? 0 : fee_estimator.ptr, chain_monitor == null ? 0 : chain_monitor.ptr, tx_broadcaster == null ? 0 : tx_broadcaster.ptr, logger == null ? 0 : logger.ptr, default_config == null ? 0 : default_config.ptr, channel_monitors != null ? InternalUtils.mapArray(channel_monitors, channel_monitors_conv_16 => channel_monitors_conv_16 == null ? 0 : channel_monitors_conv_16.ptr) : null);
212                 GC.KeepAlive(keys_manager);
213                 GC.KeepAlive(fee_estimator);
214                 GC.KeepAlive(chain_monitor);
215                 GC.KeepAlive(tx_broadcaster);
216                 GC.KeepAlive(logger);
217                 GC.KeepAlive(default_config);
218                 GC.KeepAlive(channel_monitors);
219                 if (ret >= 0 && ret <= 4096) { return null; }
220                 org.ldk.structs.ChannelManagerReadArgs ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelManagerReadArgs(null, ret); }
221                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
222                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(keys_manager); };
223                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(fee_estimator); };
224                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(chain_monitor); };
225                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(tx_broadcaster); };
226                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(logger); };
227                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(default_config); };
228                 foreach (ChannelMonitor channel_monitors_conv_16 in channel_monitors) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(channel_monitors_conv_16); }; };
229                 return ret_hu_conv;
230         }
231
232 }
233 } } }