1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
11 * Arguments for the creation of a ChannelManager that are not deserialized.
13 * At a high-level, the process for deserializing a ChannelManager and resuming normal operation
15 * 1) Deserialize all stored [`ChannelMonitor`]s.
16 * 2) Deserialize the [`ChannelManager`] by filling in this struct and calling:
17 * `<(BlockHash, ChannelManager)>::read(reader, args)`
18 * This may result in closing some channels if the [`ChannelMonitor`] is newer than the stored
19 * [`ChannelManager`] state to ensure no loss of funds. Thus, transactions may be broadcasted.
20 * 3) If you are not fetching full blocks, register all relevant [`ChannelMonitor`] outpoints the
21 * same way you would handle a [`chain::Filter`] call using
22 * [`ChannelMonitor::get_outputs_to_watch`] and [`ChannelMonitor::get_funding_txo`].
23 * 4) Reconnect blocks on your [`ChannelMonitor`]s.
24 * 5) Disconnect/connect blocks on the [`ChannelManager`].
25 * 6) Re-persist the [`ChannelMonitor`]s to ensure the latest state is on disk.
26 * Note that if you're using a [`ChainMonitor`] for your [`chain::Watch`] implementation, you
27 * will likely accomplish this as a side-effect of calling [`chain::Watch::watch_channel`] in
29 * 7) Move the [`ChannelMonitor`]s into your local [`chain::Watch`]. If you're using a
30 * [`ChainMonitor`], this is done by calling [`chain::Watch::watch_channel`].
32 * Note that the ordering of #4-7 is not of importance, however all four must occur before you
33 * call any other methods on the newly-deserialized [`ChannelManager`].
35 * Note that because some channels may be closed during deserialization, it is critical that you
36 * always deserialize only the latest version of a ChannelManager and ChannelMonitors available to
37 * you. If you deserialize an old ChannelManager (during which force-closure transactions may be
38 * broadcast), and then later deserialize a newer version of the same ChannelManager (which will
39 * not force-close the same channels but consider them live), you may end up revoking a state for
40 * which you've already broadcasted the transaction.
42 * [`ChainMonitor`]: crate::chain::chainmonitor::ChainMonitor
44 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
45 public class ChannelManagerReadArgs extends CommonBase {
46 ChannelManagerReadArgs(Object _dummy, long ptr) { super(ptr); }
47 @Override @SuppressWarnings("deprecation")
48 protected void finalize() throws Throwable {
50 if (ptr != 0) { bindings.ChannelManagerReadArgs_free(ptr); }
54 * The keys provider which will give us relevant keys. Some keys will be loaded during
55 * deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
58 public KeysInterface get_keys_manager() {
59 long ret = bindings.ChannelManagerReadArgs_get_keys_manager(this.ptr);
60 if (ret >= 0 && ret <= 4096) { return null; }
61 KeysInterface ret_hu_conv = new KeysInterface(null, ret);
62 ret_hu_conv.ptrs_to.add(this);
67 * The keys provider which will give us relevant keys. Some keys will be loaded during
68 * deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
71 public void set_keys_manager(KeysInterface val) {
72 bindings.ChannelManagerReadArgs_set_keys_manager(this.ptr, val == null ? 0 : val.ptr);
73 this.ptrs_to.add(val);
77 * The fee_estimator for use in the ChannelManager in the future.
79 * No calls to the FeeEstimator will be made during deserialization.
81 public FeeEstimator get_fee_estimator() {
82 long ret = bindings.ChannelManagerReadArgs_get_fee_estimator(this.ptr);
83 if (ret >= 0 && ret <= 4096) { return null; }
84 FeeEstimator ret_hu_conv = new FeeEstimator(null, ret);
85 ret_hu_conv.ptrs_to.add(this);
90 * The fee_estimator for use in the ChannelManager in the future.
92 * No calls to the FeeEstimator will be made during deserialization.
94 public void set_fee_estimator(FeeEstimator val) {
95 bindings.ChannelManagerReadArgs_set_fee_estimator(this.ptr, val == null ? 0 : val.ptr);
96 this.ptrs_to.add(val);
100 * The chain::Watch for use in the ChannelManager in the future.
102 * No calls to the chain::Watch will be made during deserialization. It is assumed that
103 * you have deserialized ChannelMonitors separately and will add them to your
104 * chain::Watch after deserializing this ChannelManager.
106 public Watch get_chain_monitor() {
107 long ret = bindings.ChannelManagerReadArgs_get_chain_monitor(this.ptr);
108 if (ret >= 0 && ret <= 4096) { return null; }
109 Watch ret_hu_conv = new Watch(null, ret);
110 ret_hu_conv.ptrs_to.add(this);
115 * The chain::Watch for use in the ChannelManager in the future.
117 * No calls to the chain::Watch will be made during deserialization. It is assumed that
118 * you have deserialized ChannelMonitors separately and will add them to your
119 * chain::Watch after deserializing this ChannelManager.
121 public void set_chain_monitor(Watch val) {
122 bindings.ChannelManagerReadArgs_set_chain_monitor(this.ptr, val == null ? 0 : val.ptr);
123 this.ptrs_to.add(val);
127 * The BroadcasterInterface which will be used in the ChannelManager in the future and may be
128 * used to broadcast the latest local commitment transactions of channels which must be
129 * force-closed during deserialization.
131 public BroadcasterInterface get_tx_broadcaster() {
132 long ret = bindings.ChannelManagerReadArgs_get_tx_broadcaster(this.ptr);
133 if (ret >= 0 && ret <= 4096) { return null; }
134 BroadcasterInterface ret_hu_conv = new BroadcasterInterface(null, ret);
135 ret_hu_conv.ptrs_to.add(this);
140 * The BroadcasterInterface which will be used in the ChannelManager in the future and may be
141 * used to broadcast the latest local commitment transactions of channels which must be
142 * force-closed during deserialization.
144 public void set_tx_broadcaster(BroadcasterInterface val) {
145 bindings.ChannelManagerReadArgs_set_tx_broadcaster(this.ptr, val == null ? 0 : val.ptr);
146 this.ptrs_to.add(val);
150 * The Logger for use in the ChannelManager and which may be used to log information during
153 public Logger get_logger() {
154 long ret = bindings.ChannelManagerReadArgs_get_logger(this.ptr);
155 if (ret >= 0 && ret <= 4096) { return null; }
156 Logger ret_hu_conv = new Logger(null, ret);
157 ret_hu_conv.ptrs_to.add(this);
162 * The Logger for use in the ChannelManager and which may be used to log information during
165 public void set_logger(Logger val) {
166 bindings.ChannelManagerReadArgs_set_logger(this.ptr, val == null ? 0 : val.ptr);
167 this.ptrs_to.add(val);
171 * Default settings used for new channels. Any existing channels will continue to use the
172 * runtime settings which were stored when the ChannelManager was serialized.
174 public UserConfig get_default_config() {
175 long ret = bindings.ChannelManagerReadArgs_get_default_config(this.ptr);
176 if (ret >= 0 && ret <= 4096) { return null; }
177 UserConfig ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new UserConfig(null, ret); }
178 ret_hu_conv.ptrs_to.add(this);
183 * Default settings used for new channels. Any existing channels will continue to use the
184 * runtime settings which were stored when the ChannelManager was serialized.
186 public void set_default_config(UserConfig val) {
187 bindings.ChannelManagerReadArgs_set_default_config(this.ptr, val == null ? 0 : val.ptr & ~1);
191 * Simple utility function to create a ChannelManagerReadArgs which creates the monitor
192 * HashMap for you. This is primarily useful for C bindings where it is not practical to
193 * populate a HashMap directly from C.
195 public static ChannelManagerReadArgs of(KeysInterface keys_manager, FeeEstimator fee_estimator, Watch chain_monitor, BroadcasterInterface tx_broadcaster, Logger logger, UserConfig default_config, ChannelMonitor[] channel_monitors) {
196 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);
197 if (ret >= 0 && ret <= 4096) { return null; }
198 ChannelManagerReadArgs ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ChannelManagerReadArgs(null, ret); }
199 ret_hu_conv.ptrs_to.add(ret_hu_conv);
200 ret_hu_conv.ptrs_to.add(keys_manager);
201 ret_hu_conv.ptrs_to.add(fee_estimator);
202 ret_hu_conv.ptrs_to.add(chain_monitor);
203 ret_hu_conv.ptrs_to.add(tx_broadcaster);
204 ret_hu_conv.ptrs_to.add(logger);
205 for (ChannelMonitor channel_monitors_conv_16: channel_monitors) { ret_hu_conv.ptrs_to.add(channel_monitors_conv_16); };