Merge pull request #42 from TheBlueMatt/main
[ldk-java] / src / main / java / org / ldk / structs / ChannelManagerReadArgs.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
8
9
10 /**
11  * Arguments for the creation of a ChannelManager that are not deserialized.
12  * 
13  * At a high-level, the process for deserializing a ChannelManager and resuming normal operation
14  * is:
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.
26  * 
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.
29  * 
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.
36  */
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 {
42                 super.finalize();
43                 if (ptr != 0) { bindings.ChannelManagerReadArgs_free(ptr); }
44         }
45
46         /**
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
49          * signing data.
50          */
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);
56                 return ret_hu_conv;
57         }
58
59         /**
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
62          * signing data.
63          */
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);
67         }
68
69         /**
70          * The fee_estimator for use in the ChannelManager in the future.
71          * 
72          * No calls to the FeeEstimator will be made during deserialization.
73          */
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);
79                 return ret_hu_conv;
80         }
81
82         /**
83          * The fee_estimator for use in the ChannelManager in the future.
84          * 
85          * No calls to the FeeEstimator will be made during deserialization.
86          */
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);
90         }
91
92         /**
93          * The chain::Watch for use in the ChannelManager in the future.
94          * 
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.
98          */
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);
104                 return ret_hu_conv;
105         }
106
107         /**
108          * The chain::Watch for use in the ChannelManager in the future.
109          * 
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.
113          */
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);
117         }
118
119         /**
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.
123          */
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);
129                 return ret_hu_conv;
130         }
131
132         /**
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.
136          */
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);
140         }
141
142         /**
143          * The Logger for use in the ChannelManager and which may be used to log information during
144          * deserialization.
145          */
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);
151                 return ret_hu_conv;
152         }
153
154         /**
155          * The Logger for use in the ChannelManager and which may be used to log information during
156          * deserialization.
157          */
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);
161         }
162
163         /**
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.
166          */
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);
172                 return ret_hu_conv;
173         }
174
175         /**
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.
178          */
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);
182         }
183
184         /**
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.
188          */
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  */;
201                 return ret_hu_conv;
202         }
203
204 }