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 ChannelMonitors.
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 same
21 * way you would handle a `chain::Filter` call using ChannelMonitor::get_outputs_to_watch() and
22 * ChannelMonitor::get_funding_txo().
23 * 4) Reconnect blocks on your ChannelMonitors.
24 * 5) Disconnect/connect blocks on the ChannelManager.
25 * 6) Move the ChannelMonitors into your local chain::Watch.
27 * Note that the ordering of #4-6 is not of importance, however all three must occur before you
28 * call any other methods on the newly-deserialized ChannelManager.
30 * Note that because some channels may be closed during deserialization, it is critical that you
31 * always deserialize only the latest version of a ChannelManager and ChannelMonitors available to
32 * you. If you deserialize an old ChannelManager (during which force-closure transactions may be
33 * broadcast), and then later deserialize a newer version of the same ChannelManager (which will
34 * not force-close the same channels but consider them live), you may end up revoking a state for
35 * which you've already broadcasted the transaction.
37 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
38 public class ChannelManagerReadArgs extends CommonBase {
39 ChannelManagerReadArgs(Object _dummy, long ptr) { super(ptr); }
40 @Override @SuppressWarnings("deprecation")
41 protected void finalize() throws Throwable {
43 if (ptr != 0) { bindings.ChannelManagerReadArgs_free(ptr); }
47 * The keys provider which will give us relevant keys. Some keys will be loaded during
48 * deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
51 public KeysInterface get_keys_manager() {
52 long ret = bindings.ChannelManagerReadArgs_get_keys_manager(this.ptr);
53 if (ret < 1024) { return null; }
54 KeysInterface ret_hu_conv = new KeysInterface(null, ret);
55 ret_hu_conv.ptrs_to.add(this);
60 * The keys provider which will give us relevant keys. Some keys will be loaded during
61 * deserialization and KeysInterface::read_chan_signer will be used to read per-Channel
64 public void set_keys_manager(KeysInterface val) {
65 bindings.ChannelManagerReadArgs_set_keys_manager(this.ptr, val == null ? 0 : val.ptr);
66 this.ptrs_to.add(val);
70 * The fee_estimator for use in the ChannelManager in the future.
72 * No calls to the FeeEstimator will be made during deserialization.
74 public FeeEstimator get_fee_estimator() {
75 long ret = bindings.ChannelManagerReadArgs_get_fee_estimator(this.ptr);
76 if (ret < 1024) { return null; }
77 FeeEstimator ret_hu_conv = new FeeEstimator(null, ret);
78 ret_hu_conv.ptrs_to.add(this);
83 * The fee_estimator for use in the ChannelManager in the future.
85 * No calls to the FeeEstimator will be made during deserialization.
87 public void set_fee_estimator(FeeEstimator val) {
88 bindings.ChannelManagerReadArgs_set_fee_estimator(this.ptr, val == null ? 0 : val.ptr);
89 this.ptrs_to.add(val);
93 * The chain::Watch for use in the ChannelManager in the future.
95 * No calls to the chain::Watch will be made during deserialization. It is assumed that
96 * you have deserialized ChannelMonitors separately and will add them to your
97 * chain::Watch after deserializing this ChannelManager.
99 public Watch get_chain_monitor() {
100 long ret = bindings.ChannelManagerReadArgs_get_chain_monitor(this.ptr);
101 if (ret < 1024) { return null; }
102 Watch ret_hu_conv = new Watch(null, ret);
103 ret_hu_conv.ptrs_to.add(this);
108 * The chain::Watch for use in the ChannelManager in the future.
110 * No calls to the chain::Watch will be made during deserialization. It is assumed that
111 * you have deserialized ChannelMonitors separately and will add them to your
112 * chain::Watch after deserializing this ChannelManager.
114 public void set_chain_monitor(Watch val) {
115 bindings.ChannelManagerReadArgs_set_chain_monitor(this.ptr, val == null ? 0 : val.ptr);
116 this.ptrs_to.add(val);
120 * The BroadcasterInterface which will be used in the ChannelManager in the future and may be
121 * used to broadcast the latest local commitment transactions of channels which must be
122 * force-closed during deserialization.
124 public BroadcasterInterface get_tx_broadcaster() {
125 long ret = bindings.ChannelManagerReadArgs_get_tx_broadcaster(this.ptr);
126 if (ret < 1024) { return null; }
127 BroadcasterInterface ret_hu_conv = new BroadcasterInterface(null, ret);
128 ret_hu_conv.ptrs_to.add(this);
133 * The BroadcasterInterface which will be used in the ChannelManager in the future and may be
134 * used to broadcast the latest local commitment transactions of channels which must be
135 * force-closed during deserialization.
137 public void set_tx_broadcaster(BroadcasterInterface val) {
138 bindings.ChannelManagerReadArgs_set_tx_broadcaster(this.ptr, val == null ? 0 : val.ptr);
139 this.ptrs_to.add(val);
143 * The Logger for use in the ChannelManager and which may be used to log information during
146 public Logger get_logger() {
147 long ret = bindings.ChannelManagerReadArgs_get_logger(this.ptr);
148 if (ret < 1024) { return null; }
149 Logger ret_hu_conv = new Logger(null, ret);
150 ret_hu_conv.ptrs_to.add(this);
155 * The Logger for use in the ChannelManager and which may be used to log information during
158 public void set_logger(Logger val) {
159 bindings.ChannelManagerReadArgs_set_logger(this.ptr, val == null ? 0 : val.ptr);
160 this.ptrs_to.add(val);
164 * Default settings used for new channels. Any existing channels will continue to use the
165 * runtime settings which were stored when the ChannelManager was serialized.
167 public UserConfig get_default_config() {
168 long ret = bindings.ChannelManagerReadArgs_get_default_config(this.ptr);
169 if (ret < 1024) { return null; }
170 UserConfig ret_hu_conv = new UserConfig(null, ret);
171 ret_hu_conv.ptrs_to.add(this);
176 * Default settings used for new channels. Any existing channels will continue to use the
177 * runtime settings which were stored when the ChannelManager was serialized.
179 public void set_default_config(UserConfig val) {
180 bindings.ChannelManagerReadArgs_set_default_config(this.ptr, val == null ? 0 : val.ptr & ~1);
181 this.ptrs_to.add(val);
185 * Simple utility function to create a ChannelManagerReadArgs which creates the monitor
186 * HashMap for you. This is primarily useful for C bindings where it is not practical to
187 * populate a HashMap directly from C.
189 public static ChannelManagerReadArgs of(KeysInterface keys_manager, FeeEstimator fee_estimator, Watch chain_monitor, BroadcasterInterface tx_broadcaster, Logger logger, UserConfig default_config, ChannelMonitor[] channel_monitors) {
190 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);
191 if (ret < 1024) { return null; }
192 ChannelManagerReadArgs ret_hu_conv = new ChannelManagerReadArgs(null, ret);
193 ret_hu_conv.ptrs_to.add(ret_hu_conv);
194 ret_hu_conv.ptrs_to.add(keys_manager);
195 ret_hu_conv.ptrs_to.add(fee_estimator);
196 ret_hu_conv.ptrs_to.add(chain_monitor);
197 ret_hu_conv.ptrs_to.add(tx_broadcaster);
198 ret_hu_conv.ptrs_to.add(logger);
199 ret_hu_conv.ptrs_to.add(default_config);
200 /* TODO 2 ChannelMonitor */;