X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FChannelManagerReadArgs.java;h=376661e7002e7d04fde06762a89d68618acca789;hb=890e35a4387758c0447aab34166caa579bbf3a08;hp=1f5d32164e07e9cea6c2859f115e5b7313fa1457;hpb=8c0814bf345323be8f16e075a9af0bd43d9400ee;p=ldk-java diff --git a/src/main/java/org/ldk/structs/ChannelManagerReadArgs.java b/src/main/java/org/ldk/structs/ChannelManagerReadArgs.java index 1f5d3216..376661e7 100644 --- a/src/main/java/org/ldk/structs/ChannelManagerReadArgs.java +++ b/src/main/java/org/ldk/structs/ChannelManagerReadArgs.java @@ -4,6 +4,7 @@ import org.ldk.impl.bindings; import org.ldk.enums.*; import org.ldk.util.*; import java.util.Arrays; +import java.lang.ref.Reference; import javax.annotation.Nullable; @@ -12,20 +13,25 @@ import javax.annotation.Nullable; * * At a high-level, the process for deserializing a ChannelManager and resuming normal operation * is: - * 1) Deserialize all stored ChannelMonitors. - * 2) Deserialize the ChannelManager by filling in this struct and calling: - * <(BlockHash, ChannelManager)>::read(reader, args) - * This may result in closing some Channels if the ChannelMonitor is newer than the stored - * ChannelManager state to ensure no loss of funds. Thus, transactions may be broadcasted. - * 3) If you are not fetching full blocks, register all relevant ChannelMonitor outpoints the same - * way you would handle a `chain::Filter` call using ChannelMonitor::get_outputs_to_watch() and - * ChannelMonitor::get_funding_txo(). - * 4) Reconnect blocks on your ChannelMonitors. - * 5) Disconnect/connect blocks on the ChannelManager. - * 6) Move the ChannelMonitors into your local chain::Watch. + * 1) Deserialize all stored [`ChannelMonitor`]s. + * 2) Deserialize the [`ChannelManager`] by filling in this struct and calling: + * `<(BlockHash, ChannelManager)>::read(reader, args)` + * This may result in closing some channels if the [`ChannelMonitor`] is newer than the stored + * [`ChannelManager`] state to ensure no loss of funds. Thus, transactions may be broadcasted. + * 3) If you are not fetching full blocks, register all relevant [`ChannelMonitor`] outpoints the + * same way you would handle a [`chain::Filter`] call using + * [`ChannelMonitor::get_outputs_to_watch`] and [`ChannelMonitor::get_funding_txo`]. + * 4) Reconnect blocks on your [`ChannelMonitor`]s. + * 5) Disconnect/connect blocks on the [`ChannelManager`]. + * 6) Re-persist the [`ChannelMonitor`]s to ensure the latest state is on disk. + * Note that if you're using a [`ChainMonitor`] for your [`chain::Watch`] implementation, you + * will likely accomplish this as a side-effect of calling [`chain::Watch::watch_channel`] in + * the next step. + * 7) Move the [`ChannelMonitor`]s into your local [`chain::Watch`]. If you're using a + * [`ChainMonitor`], this is done by calling [`chain::Watch::watch_channel`]. * - * Note that the ordering of #4-6 is not of importance, however all three must occur before you - * call any other methods on the newly-deserialized ChannelManager. + * Note that the ordering of #4-7 is not of importance, however all four must occur before you + * call any other methods on the newly-deserialized [`ChannelManager`]. * * Note that because some channels may be closed during deserialization, it is critical that you * always deserialize only the latest version of a ChannelManager and ChannelMonitors available to @@ -33,6 +39,8 @@ import javax.annotation.Nullable; * broadcast), and then later deserialize a newer version of the same ChannelManager (which will * not force-close the same channels but consider them live), you may end up revoking a state for * which you've already broadcasted the transaction. + * + * [`ChainMonitor`]: crate::chain::chainmonitor::ChainMonitor */ @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class ChannelManagerReadArgs extends CommonBase { @@ -50,9 +58,10 @@ public class ChannelManagerReadArgs extends CommonBase { */ public KeysInterface get_keys_manager() { long ret = bindings.ChannelManagerReadArgs_get_keys_manager(this.ptr); - if (ret < 1024) { return null; } + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } KeysInterface ret_hu_conv = new KeysInterface(null, ret); - ret_hu_conv.ptrs_to.add(this); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; return ret_hu_conv; } @@ -63,7 +72,9 @@ public class ChannelManagerReadArgs extends CommonBase { */ public void set_keys_manager(KeysInterface val) { bindings.ChannelManagerReadArgs_set_keys_manager(this.ptr, val == null ? 0 : val.ptr); - this.ptrs_to.add(val); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); + if (this != null) { this.ptrs_to.add(val); }; } /** @@ -73,9 +84,10 @@ public class ChannelManagerReadArgs extends CommonBase { */ public FeeEstimator get_fee_estimator() { long ret = bindings.ChannelManagerReadArgs_get_fee_estimator(this.ptr); - if (ret < 1024) { return null; } + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } FeeEstimator ret_hu_conv = new FeeEstimator(null, ret); - ret_hu_conv.ptrs_to.add(this); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; return ret_hu_conv; } @@ -86,7 +98,9 @@ public class ChannelManagerReadArgs extends CommonBase { */ public void set_fee_estimator(FeeEstimator val) { bindings.ChannelManagerReadArgs_set_fee_estimator(this.ptr, val == null ? 0 : val.ptr); - this.ptrs_to.add(val); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); + if (this != null) { this.ptrs_to.add(val); }; } /** @@ -98,9 +112,10 @@ public class ChannelManagerReadArgs extends CommonBase { */ public Watch get_chain_monitor() { long ret = bindings.ChannelManagerReadArgs_get_chain_monitor(this.ptr); - if (ret < 1024) { return null; } + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } Watch ret_hu_conv = new Watch(null, ret); - ret_hu_conv.ptrs_to.add(this); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; return ret_hu_conv; } @@ -113,7 +128,9 @@ public class ChannelManagerReadArgs extends CommonBase { */ public void set_chain_monitor(Watch val) { bindings.ChannelManagerReadArgs_set_chain_monitor(this.ptr, val == null ? 0 : val.ptr); - this.ptrs_to.add(val); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); + if (this != null) { this.ptrs_to.add(val); }; } /** @@ -123,9 +140,10 @@ public class ChannelManagerReadArgs extends CommonBase { */ public BroadcasterInterface get_tx_broadcaster() { long ret = bindings.ChannelManagerReadArgs_get_tx_broadcaster(this.ptr); - if (ret < 1024) { return null; } + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } BroadcasterInterface ret_hu_conv = new BroadcasterInterface(null, ret); - ret_hu_conv.ptrs_to.add(this); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; return ret_hu_conv; } @@ -136,7 +154,9 @@ public class ChannelManagerReadArgs extends CommonBase { */ public void set_tx_broadcaster(BroadcasterInterface val) { bindings.ChannelManagerReadArgs_set_tx_broadcaster(this.ptr, val == null ? 0 : val.ptr); - this.ptrs_to.add(val); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); + if (this != null) { this.ptrs_to.add(val); }; } /** @@ -145,9 +165,10 @@ public class ChannelManagerReadArgs extends CommonBase { */ public Logger get_logger() { long ret = bindings.ChannelManagerReadArgs_get_logger(this.ptr); - if (ret < 1024) { return null; } + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } Logger ret_hu_conv = new Logger(null, ret); - ret_hu_conv.ptrs_to.add(this); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; return ret_hu_conv; } @@ -157,7 +178,9 @@ public class ChannelManagerReadArgs extends CommonBase { */ public void set_logger(Logger val) { bindings.ChannelManagerReadArgs_set_logger(this.ptr, val == null ? 0 : val.ptr); - this.ptrs_to.add(val); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); + if (this != null) { this.ptrs_to.add(val); }; } /** @@ -166,9 +189,10 @@ public class ChannelManagerReadArgs extends CommonBase { */ public UserConfig get_default_config() { long ret = bindings.ChannelManagerReadArgs_get_default_config(this.ptr); - if (ret < 1024) { return null; } - UserConfig ret_hu_conv = new UserConfig(null, ret); - ret_hu_conv.ptrs_to.add(this); + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.UserConfig ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.UserConfig(null, ret); } + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; return ret_hu_conv; } @@ -177,7 +201,10 @@ public class ChannelManagerReadArgs extends CommonBase { * runtime settings which were stored when the ChannelManager was serialized. */ public void set_default_config(UserConfig val) { - bindings.ChannelManagerReadArgs_set_default_config(this.ptr, val == null ? 0 : val.ptr & ~1); + bindings.ChannelManagerReadArgs_set_default_config(this.ptr, val == null ? 0 : val.ptr); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); + if (this != null) { this.ptrs_to.add(val); }; } /** @@ -186,16 +213,24 @@ public class ChannelManagerReadArgs extends CommonBase { * populate a HashMap directly from C. */ public static ChannelManagerReadArgs of(KeysInterface keys_manager, FeeEstimator fee_estimator, Watch chain_monitor, BroadcasterInterface tx_broadcaster, Logger logger, UserConfig default_config, ChannelMonitor[] channel_monitors) { - 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); - if (ret < 1024) { return null; } - ChannelManagerReadArgs ret_hu_conv = new ChannelManagerReadArgs(null, ret); - ret_hu_conv.ptrs_to.add(ret_hu_conv); - ret_hu_conv.ptrs_to.add(keys_manager); - ret_hu_conv.ptrs_to.add(fee_estimator); - ret_hu_conv.ptrs_to.add(chain_monitor); - ret_hu_conv.ptrs_to.add(tx_broadcaster); - ret_hu_conv.ptrs_to.add(logger); - for (ChannelMonitor channel_monitors_conv_16: channel_monitors) { ret_hu_conv.ptrs_to.add(channel_monitors_conv_16); }; + 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 ? Arrays.stream(channel_monitors).mapToLong(channel_monitors_conv_16 -> channel_monitors_conv_16 == null ? 0 : channel_monitors_conv_16.ptr).toArray() : null); + Reference.reachabilityFence(keys_manager); + Reference.reachabilityFence(fee_estimator); + Reference.reachabilityFence(chain_monitor); + Reference.reachabilityFence(tx_broadcaster); + Reference.reachabilityFence(logger); + Reference.reachabilityFence(default_config); + Reference.reachabilityFence(channel_monitors); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.ChannelManagerReadArgs ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelManagerReadArgs(null, ret); } + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(keys_manager); }; + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(fee_estimator); }; + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(chain_monitor); }; + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(tx_broadcaster); }; + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); }; + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(default_config); }; + for (ChannelMonitor channel_monitors_conv_16: channel_monitors) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channel_monitors_conv_16); }; }; return ret_hu_conv; }