1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * Arguments for the creation of a ChannelManager that are not deserialized.
14 * At a high-level, the process for deserializing a ChannelManager and resuming normal operation
16 * 1) Deserialize all stored [`ChannelMonitor`]s.
17 * 2) Deserialize the [`ChannelManager`] by filling in this struct and calling:
18 * `<(BlockHash, ChannelManager)>::read(reader, args)`
19 * This may result in closing some channels if the [`ChannelMonitor`] is newer than the stored
20 * [`ChannelManager`] state to ensure no loss of funds. Thus, transactions may be broadcasted.
21 * 3) If you are not fetching full blocks, register all relevant [`ChannelMonitor`] outpoints the
22 * same way you would handle a [`chain::Filter`] call using
23 * [`ChannelMonitor::get_outputs_to_watch`] and [`ChannelMonitor::get_funding_txo`].
24 * 4) Reconnect blocks on your [`ChannelMonitor`]s.
25 * 5) Disconnect/connect blocks on the [`ChannelManager`].
26 * 6) Re-persist the [`ChannelMonitor`]s to ensure the latest state is on disk.
27 * Note that if you're using a [`ChainMonitor`] for your [`chain::Watch`] implementation, you
28 * will likely accomplish this as a side-effect of calling [`chain::Watch::watch_channel`] in
30 * 7) Move the [`ChannelMonitor`]s into your local [`chain::Watch`]. If you're using a
31 * [`ChainMonitor`], this is done by calling [`chain::Watch::watch_channel`].
33 * Note that the ordering of #4-7 is not of importance, however all four must occur before you
34 * call any other methods on the newly-deserialized [`ChannelManager`].
36 * Note that because some channels may be closed during deserialization, it is critical that you
37 * always deserialize only the latest version of a ChannelManager and ChannelMonitors available to
38 * you. If you deserialize an old ChannelManager (during which force-closure transactions may be
39 * broadcast), and then later deserialize a newer version of the same ChannelManager (which will
40 * not force-close the same channels but consider them live), you may end up revoking a state for
41 * which you've already broadcasted the transaction.
43 * [`ChainMonitor`]: crate::chain::chainmonitor::ChainMonitor
45 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
46 public class ChannelManagerReadArgs extends CommonBase {
47 ChannelManagerReadArgs(Object _dummy, long ptr) { super(ptr); }
48 @Override @SuppressWarnings("deprecation")
49 protected void finalize() throws Throwable {
51 if (ptr != 0) { bindings.ChannelManagerReadArgs_free(ptr); }
55 * The keys provider which will give us relevant keys. Some keys will be loaded during
56 * deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
59 public KeysInterface get_keys_manager() {
60 long ret = bindings.ChannelManagerReadArgs_get_keys_manager(this.ptr);
61 Reference.reachabilityFence(this);
62 if (ret >= 0 && ret <= 4096) { return null; }
63 KeysInterface ret_hu_conv = new KeysInterface(null, ret);
64 ret_hu_conv.ptrs_to.add(this);
69 * The keys provider which will give us relevant keys. Some keys will be loaded during
70 * deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
73 public void set_keys_manager(KeysInterface val) {
74 bindings.ChannelManagerReadArgs_set_keys_manager(this.ptr, val == null ? 0 : val.ptr);
75 Reference.reachabilityFence(this);
76 Reference.reachabilityFence(val);
77 this.ptrs_to.add(val);
81 * The fee_estimator for use in the ChannelManager in the future.
83 * No calls to the FeeEstimator will be made during deserialization.
85 public FeeEstimator get_fee_estimator() {
86 long ret = bindings.ChannelManagerReadArgs_get_fee_estimator(this.ptr);
87 Reference.reachabilityFence(this);
88 if (ret >= 0 && ret <= 4096) { return null; }
89 FeeEstimator ret_hu_conv = new FeeEstimator(null, ret);
90 ret_hu_conv.ptrs_to.add(this);
95 * The fee_estimator for use in the ChannelManager in the future.
97 * No calls to the FeeEstimator will be made during deserialization.
99 public void set_fee_estimator(FeeEstimator val) {
100 bindings.ChannelManagerReadArgs_set_fee_estimator(this.ptr, val == null ? 0 : val.ptr);
101 Reference.reachabilityFence(this);
102 Reference.reachabilityFence(val);
103 this.ptrs_to.add(val);
107 * The chain::Watch for use in the ChannelManager in the future.
109 * No calls to the chain::Watch will be made during deserialization. It is assumed that
110 * you have deserialized ChannelMonitors separately and will add them to your
111 * chain::Watch after deserializing this ChannelManager.
113 public Watch get_chain_monitor() {
114 long ret = bindings.ChannelManagerReadArgs_get_chain_monitor(this.ptr);
115 Reference.reachabilityFence(this);
116 if (ret >= 0 && ret <= 4096) { return null; }
117 Watch ret_hu_conv = new Watch(null, ret);
118 ret_hu_conv.ptrs_to.add(this);
123 * The chain::Watch for use in the ChannelManager in the future.
125 * No calls to the chain::Watch will be made during deserialization. It is assumed that
126 * you have deserialized ChannelMonitors separately and will add them to your
127 * chain::Watch after deserializing this ChannelManager.
129 public void set_chain_monitor(Watch val) {
130 bindings.ChannelManagerReadArgs_set_chain_monitor(this.ptr, val == null ? 0 : val.ptr);
131 Reference.reachabilityFence(this);
132 Reference.reachabilityFence(val);
133 this.ptrs_to.add(val);
137 * The BroadcasterInterface which will be used in the ChannelManager in the future and may be
138 * used to broadcast the latest local commitment transactions of channels which must be
139 * force-closed during deserialization.
141 public BroadcasterInterface get_tx_broadcaster() {
142 long ret = bindings.ChannelManagerReadArgs_get_tx_broadcaster(this.ptr);
143 Reference.reachabilityFence(this);
144 if (ret >= 0 && ret <= 4096) { return null; }
145 BroadcasterInterface ret_hu_conv = new BroadcasterInterface(null, ret);
146 ret_hu_conv.ptrs_to.add(this);
151 * The BroadcasterInterface which will be used in the ChannelManager in the future and may be
152 * used to broadcast the latest local commitment transactions of channels which must be
153 * force-closed during deserialization.
155 public void set_tx_broadcaster(BroadcasterInterface val) {
156 bindings.ChannelManagerReadArgs_set_tx_broadcaster(this.ptr, val == null ? 0 : val.ptr);
157 Reference.reachabilityFence(this);
158 Reference.reachabilityFence(val);
159 this.ptrs_to.add(val);
163 * The Logger for use in the ChannelManager and which may be used to log information during
166 public Logger get_logger() {
167 long ret = bindings.ChannelManagerReadArgs_get_logger(this.ptr);
168 Reference.reachabilityFence(this);
169 if (ret >= 0 && ret <= 4096) { return null; }
170 Logger ret_hu_conv = new Logger(null, ret);
171 ret_hu_conv.ptrs_to.add(this);
176 * The Logger for use in the ChannelManager and which may be used to log information during
179 public void set_logger(Logger val) {
180 bindings.ChannelManagerReadArgs_set_logger(this.ptr, val == null ? 0 : val.ptr);
181 Reference.reachabilityFence(this);
182 Reference.reachabilityFence(val);
183 this.ptrs_to.add(val);
187 * Default settings used for new channels. Any existing channels will continue to use the
188 * runtime settings which were stored when the ChannelManager was serialized.
190 public UserConfig get_default_config() {
191 long ret = bindings.ChannelManagerReadArgs_get_default_config(this.ptr);
192 Reference.reachabilityFence(this);
193 if (ret >= 0 && ret <= 4096) { return null; }
194 UserConfig ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new UserConfig(null, ret); }
195 ret_hu_conv.ptrs_to.add(this);
200 * Default settings used for new channels. Any existing channels will continue to use the
201 * runtime settings which were stored when the ChannelManager was serialized.
203 public void set_default_config(UserConfig val) {
204 bindings.ChannelManagerReadArgs_set_default_config(this.ptr, val == null ? 0 : val.ptr & ~1);
205 Reference.reachabilityFence(this);
206 Reference.reachabilityFence(val);
210 * Simple utility function to create a ChannelManagerReadArgs which creates the monitor
211 * HashMap for you. This is primarily useful for C bindings where it is not practical to
212 * populate a HashMap directly from C.
214 public static ChannelManagerReadArgs of(KeysInterface keys_manager, FeeEstimator fee_estimator, Watch chain_monitor, BroadcasterInterface tx_broadcaster, Logger logger, UserConfig default_config, ChannelMonitor[] channel_monitors) {
215 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 & ~1, channel_monitors != null ? Arrays.stream(channel_monitors).mapToLong(channel_monitors_conv_16 -> channel_monitors_conv_16 == null ? 0 : channel_monitors_conv_16.ptr & ~1).toArray() : null);
216 Reference.reachabilityFence(keys_manager);
217 Reference.reachabilityFence(fee_estimator);
218 Reference.reachabilityFence(chain_monitor);
219 Reference.reachabilityFence(tx_broadcaster);
220 Reference.reachabilityFence(logger);
221 Reference.reachabilityFence(default_config);
222 Reference.reachabilityFence(channel_monitors);
223 if (ret >= 0 && ret <= 4096) { return null; }
224 ChannelManagerReadArgs ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ChannelManagerReadArgs(null, ret); }
225 ret_hu_conv.ptrs_to.add(ret_hu_conv);
226 ret_hu_conv.ptrs_to.add(keys_manager);
227 ret_hu_conv.ptrs_to.add(fee_estimator);
228 ret_hu_conv.ptrs_to.add(chain_monitor);
229 ret_hu_conv.ptrs_to.add(tx_broadcaster);
230 ret_hu_conv.ptrs_to.add(logger);
231 for (ChannelMonitor channel_monitors_conv_16: channel_monitors) { ret_hu_conv.ptrs_to.add(channel_monitors_conv_16); };