Merge pull request #120 from TheBlueMatt/main
[ldk-java] / src / main / java / org / ldk / structs / ChannelManager.java
index 33ea282eba908f522a366a278342b12769f54aa9..75a26751229229be7d9e47a91a9c70a8fa79755e 100644 (file)
@@ -68,7 +68,7 @@ public class ChannelManager extends CommonBase {
         * from after `params.latest_hash`.
         */
        public static ChannelManager of(FeeEstimator fee_est, Watch chain_monitor, BroadcasterInterface tx_broadcaster, Logger logger, KeysInterface keys_manager, UserConfig config, ChainParameters params) {
-               long ret = bindings.ChannelManager_new(fee_est == null ? 0 : fee_est.ptr, chain_monitor == null ? 0 : chain_monitor.ptr, tx_broadcaster == null ? 0 : tx_broadcaster.ptr, logger == null ? 0 : logger.ptr, keys_manager == null ? 0 : keys_manager.ptr, config == null ? 0 : config.ptr & ~1, params == null ? 0 : params.ptr & ~1);
+               long ret = bindings.ChannelManager_new(fee_est == null ? 0 : fee_est.ptr, chain_monitor == null ? 0 : chain_monitor.ptr, tx_broadcaster == null ? 0 : tx_broadcaster.ptr, logger == null ? 0 : logger.ptr, keys_manager == null ? 0 : keys_manager.ptr, config == null ? 0 : config.ptr, params == null ? 0 : params.ptr);
                Reference.reachabilityFence(fee_est);
                Reference.reachabilityFence(chain_monitor);
                Reference.reachabilityFence(tx_broadcaster);
@@ -78,24 +78,26 @@ public class ChannelManager extends CommonBase {
                Reference.reachabilityFence(params);
                if (ret >= 0 && ret <= 4096) { return null; }
                org.ldk.structs.ChannelManager ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelManager(null, ret); }
-               ret_hu_conv.ptrs_to.add(ret_hu_conv);
-               ret_hu_conv.ptrs_to.add(fee_est);
-               ret_hu_conv.ptrs_to.add(chain_monitor);
-               ret_hu_conv.ptrs_to.add(tx_broadcaster);
-               ret_hu_conv.ptrs_to.add(logger);
-               ret_hu_conv.ptrs_to.add(keys_manager);
+               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(fee_est); };
+               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(keys_manager); };
+               if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(config); };
+               if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(params); };
                return ret_hu_conv;
        }
 
        /**
-        * Gets the current configuration applied to all new channels,  as
+        * Gets the current configuration applied to all new channels.
         */
        public UserConfig get_current_default_configuration() {
                long ret = bindings.ChannelManager_get_current_default_configuration(this.ptr);
                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); }
-               ret_hu_conv.ptrs_to.add(this);
+               if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
                return ret_hu_conv;
        }
 
@@ -130,7 +132,7 @@ public class ChannelManager extends CommonBase {
         * Note that override_config (or a relevant inner pointer) may be NULL or all-0s to represent None
         */
        public Result__u832APIErrorZ create_channel(byte[] their_network_key, long channel_value_satoshis, long push_msat, long user_channel_id, @Nullable UserConfig override_config) {
-               long ret = bindings.ChannelManager_create_channel(this.ptr, InternalUtils.check_arr_len(their_network_key, 33), channel_value_satoshis, push_msat, user_channel_id, override_config == null ? 0 : override_config.ptr & ~1);
+               long ret = bindings.ChannelManager_create_channel(this.ptr, InternalUtils.check_arr_len(their_network_key, 33), channel_value_satoshis, push_msat, user_channel_id, override_config == null ? 0 : override_config.ptr);
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(their_network_key);
                Reference.reachabilityFence(channel_value_satoshis);
@@ -139,6 +141,7 @@ public class ChannelManager extends CommonBase {
                Reference.reachabilityFence(override_config);
                if (ret >= 0 && ret <= 4096) { return null; }
                Result__u832APIErrorZ ret_hu_conv = Result__u832APIErrorZ.constr_from_ptr(ret);
+               if (this != null) { this.ptrs_to.add(override_config); };
                return ret_hu_conv;
        }
 
@@ -154,7 +157,7 @@ public class ChannelManager extends CommonBase {
                for (int q = 0; q < ret_conv_16_len; q++) {
                        long ret_conv_16 = ret[q];
                        org.ldk.structs.ChannelDetails ret_conv_16_hu_conv = null; if (ret_conv_16 < 0 || ret_conv_16 > 4096) { ret_conv_16_hu_conv = new org.ldk.structs.ChannelDetails(null, ret_conv_16); }
-                       ret_conv_16_hu_conv.ptrs_to.add(this);
+                       if (ret_conv_16_hu_conv != null) { ret_conv_16_hu_conv.ptrs_to.add(this); };
                        ret_conv_16_arr[q] = ret_conv_16_hu_conv;
                }
                return ret_conv_16_arr;
@@ -178,7 +181,7 @@ public class ChannelManager extends CommonBase {
                for (int q = 0; q < ret_conv_16_len; q++) {
                        long ret_conv_16 = ret[q];
                        org.ldk.structs.ChannelDetails ret_conv_16_hu_conv = null; if (ret_conv_16 < 0 || ret_conv_16 > 4096) { ret_conv_16_hu_conv = new org.ldk.structs.ChannelDetails(null, ret_conv_16); }
-                       ret_conv_16_hu_conv.ptrs_to.add(this);
+                       if (ret_conv_16_hu_conv != null) { ret_conv_16_hu_conv.ptrs_to.add(this); };
                        ret_conv_16_arr[q] = ret_conv_16_hu_conv;
                }
                return ret_conv_16_arr;
@@ -317,12 +320,12 @@ public class ChannelManager extends CommonBase {
         * PaymentSendFailure for more info.
         * 
         * In general, a path may raise:
-        * APIError::RouteError when an invalid route or forwarding parameter (cltv_delta, fee,
+        * [`APIError::RouteError`] when an invalid route or forwarding parameter (cltv_delta, fee,
         * node public key) is specified.
-        * APIError::ChannelUnavailable if the next-hop channel is not available for updates
+        * [`APIError::ChannelUnavailable`] if the next-hop channel is not available for updates
         * (including due to previous monitor update failure or new permanent monitor update
         * failure).
-        * APIError::MonitorUpdateFailed if a new monitor update failure prevented sending the
+        * [`APIError::MonitorUpdateInProgress`] if a new monitor update failure prevented sending the
         * relevant updates.
         * 
         * Note that depending on the type of the PaymentSendFailure the HTLC may have been
@@ -341,14 +344,14 @@ public class ChannelManager extends CommonBase {
         * Note that payment_secret (or a relevant inner pointer) may be NULL or all-0s to represent None
         */
        public Result_PaymentIdPaymentSendFailureZ send_payment(Route route, byte[] payment_hash, @Nullable byte[] payment_secret) {
-               long ret = bindings.ChannelManager_send_payment(this.ptr, route == null ? 0 : route.ptr & ~1, InternalUtils.check_arr_len(payment_hash, 32), InternalUtils.check_arr_len(payment_secret, 32));
+               long ret = bindings.ChannelManager_send_payment(this.ptr, route == null ? 0 : route.ptr, InternalUtils.check_arr_len(payment_hash, 32), InternalUtils.check_arr_len(payment_secret, 32));
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(route);
                Reference.reachabilityFence(payment_hash);
                Reference.reachabilityFence(payment_secret);
                if (ret >= 0 && ret <= 4096) { return null; }
                Result_PaymentIdPaymentSendFailureZ ret_hu_conv = Result_PaymentIdPaymentSendFailureZ.constr_from_ptr(ret);
-               this.ptrs_to.add(route);
+               if (this != null) { this.ptrs_to.add(route); };
                return ret_hu_conv;
        }
 
@@ -365,13 +368,13 @@ public class ChannelManager extends CommonBase {
         * [`abandon_payment`]: [`ChannelManager::abandon_payment`]
         */
        public Result_NonePaymentSendFailureZ retry_payment(Route route, byte[] payment_id) {
-               long ret = bindings.ChannelManager_retry_payment(this.ptr, route == null ? 0 : route.ptr & ~1, InternalUtils.check_arr_len(payment_id, 32));
+               long ret = bindings.ChannelManager_retry_payment(this.ptr, route == null ? 0 : route.ptr, InternalUtils.check_arr_len(payment_id, 32));
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(route);
                Reference.reachabilityFence(payment_id);
                if (ret >= 0 && ret <= 4096) { return null; }
                Result_NonePaymentSendFailureZ ret_hu_conv = Result_NonePaymentSendFailureZ.constr_from_ptr(ret);
-               this.ptrs_to.add(route);
+               if (this != null) { this.ptrs_to.add(route); };
                return ret_hu_conv;
        }
 
@@ -416,13 +419,13 @@ public class ChannelManager extends CommonBase {
         * Note that payment_preimage (or a relevant inner pointer) may be NULL or all-0s to represent None
         */
        public Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ send_spontaneous_payment(Route route, @Nullable byte[] payment_preimage) {
-               long ret = bindings.ChannelManager_send_spontaneous_payment(this.ptr, route == null ? 0 : route.ptr & ~1, InternalUtils.check_arr_len(payment_preimage, 32));
+               long ret = bindings.ChannelManager_send_spontaneous_payment(this.ptr, route == null ? 0 : route.ptr, InternalUtils.check_arr_len(payment_preimage, 32));
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(route);
                Reference.reachabilityFence(payment_preimage);
                if (ret >= 0 && ret <= 4096) { return null; }
                Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ.constr_from_ptr(ret);
-               this.ptrs_to.add(route);
+               if (this != null) { this.ptrs_to.add(route); };
                return ret_hu_conv;
        }
 
@@ -432,11 +435,12 @@ public class ChannelManager extends CommonBase {
         * us to easily discern them from real payments.
         */
        public Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ send_probe(RouteHop[] hops) {
-               long ret = bindings.ChannelManager_send_probe(this.ptr, hops != null ? Arrays.stream(hops).mapToLong(hops_conv_10 -> hops_conv_10 == null ? 0 : hops_conv_10.ptr & ~1).toArray() : null);
+               long ret = bindings.ChannelManager_send_probe(this.ptr, hops != null ? Arrays.stream(hops).mapToLong(hops_conv_10 -> hops_conv_10 == null ? 0 : hops_conv_10.ptr).toArray() : null);
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(hops);
                if (ret >= 0 && ret <= 4096) { return null; }
                Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ.constr_from_ptr(ret);
+               for (RouteHop hops_conv_10: hops) { if (this != null) { this.ptrs_to.add(hops_conv_10); }; };
                return ret_hu_conv;
        }
 
@@ -483,34 +487,6 @@ public class ChannelManager extends CommonBase {
                return ret_hu_conv;
        }
 
-       /**
-        * Regenerates channel_announcements and generates a signed node_announcement from the given
-        * arguments, providing them in corresponding events via
-        * [`get_and_clear_pending_msg_events`], if at least one public channel has been confirmed
-        * on-chain. This effectively re-broadcasts all channel announcements and sends our node
-        * announcement to ensure that the lightning P2P network is aware of the channels we have and
-        * our network addresses.
-        * 
-        * `rgb` is a node \"color\" and `alias` is a printable human-readable string to describe this
-        * node to humans. They carry no in-protocol meaning.
-        * 
-        * `addresses` represent the set (possibly empty) of socket addresses on which this node
-        * accepts incoming connections. These will be included in the node_announcement, publicly
-        * tying these addresses together and to this node. If you wish to preserve user privacy,
-        * addresses should likely contain only Tor Onion addresses.
-        * 
-        * Panics if `addresses` is absurdly large (more than 100).
-        * 
-        * [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
-        */
-       public void broadcast_node_announcement(byte[] rgb, byte[] alias, NetAddress[] addresses) {
-               bindings.ChannelManager_broadcast_node_announcement(this.ptr, InternalUtils.check_arr_len(rgb, 3), InternalUtils.check_arr_len(alias, 32), addresses != null ? Arrays.stream(addresses).mapToLong(addresses_conv_12 -> addresses_conv_12.ptr).toArray() : null);
-               Reference.reachabilityFence(this);
-               Reference.reachabilityFence(rgb);
-               Reference.reachabilityFence(alias);
-               Reference.reachabilityFence(addresses);
-       }
-
        /**
         * Atomically updates the [`ChannelConfig`] for the given channels.
         * 
@@ -536,14 +512,14 @@ public class ChannelManager extends CommonBase {
         * [`APIMisuseError`]: APIError::APIMisuseError
         */
        public Result_NoneAPIErrorZ update_channel_config(byte[] counterparty_node_id, byte[][] channel_ids, ChannelConfig config) {
-               long ret = bindings.ChannelManager_update_channel_config(this.ptr, InternalUtils.check_arr_len(counterparty_node_id, 33), channel_ids != null ? Arrays.stream(channel_ids).map(channel_ids_conv_8 -> InternalUtils.check_arr_len(channel_ids_conv_8, 32)).toArray(byte[][]::new) : null, config == null ? 0 : config.ptr & ~1);
+               long ret = bindings.ChannelManager_update_channel_config(this.ptr, InternalUtils.check_arr_len(counterparty_node_id, 33), channel_ids != null ? Arrays.stream(channel_ids).map(channel_ids_conv_8 -> InternalUtils.check_arr_len(channel_ids_conv_8, 32)).toArray(byte[][]::new) : null, config == null ? 0 : config.ptr);
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(counterparty_node_id);
                Reference.reachabilityFence(channel_ids);
                Reference.reachabilityFence(config);
                if (ret >= 0 && ret <= 4096) { return null; }
                Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
-               this.ptrs_to.add(config);
+               if (this != null) { this.ptrs_to.add(config); };
                return ret_hu_conv;
        }
 
@@ -868,7 +844,7 @@ public class ChannelManager extends CommonBase {
                Reference.reachabilityFence(this);
                if (ret >= 0 && ret <= 4096) { return null; }
                org.ldk.structs.PhantomRouteHints ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PhantomRouteHints(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;
        }
 
@@ -881,7 +857,7 @@ public class ChannelManager extends CommonBase {
                Reference.reachabilityFence(this);
                if (ret >= 0 && ret <= 4096) { return null; }
                MessageSendEventsProvider ret_hu_conv = new MessageSendEventsProvider(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;
        }
 
@@ -894,7 +870,7 @@ public class ChannelManager extends CommonBase {
                Reference.reachabilityFence(this);
                if (ret >= 0 && ret <= 4096) { return null; }
                EventsProvider ret_hu_conv = new EventsProvider(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;
        }
 
@@ -907,7 +883,7 @@ public class ChannelManager extends CommonBase {
                Reference.reachabilityFence(this);
                if (ret >= 0 && ret <= 4096) { return null; }
                Listen ret_hu_conv = new Listen(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;
        }
 
@@ -920,7 +896,7 @@ public class ChannelManager extends CommonBase {
                Reference.reachabilityFence(this);
                if (ret >= 0 && ret <= 4096) { return null; }
                Confirm ret_hu_conv = new Confirm(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;
        }
 
@@ -949,6 +925,20 @@ public class ChannelManager extends CommonBase {
                Reference.reachabilityFence(this);
        }
 
+       /**
+        * Gets a [`Future`] that completes when a persistable update is available. Note that
+        * callbacks registered on the [`Future`] MUST NOT call back into this [`ChannelManager`] and
+        * should instead register actions to be taken later.
+        */
+       public Future get_persistable_update_future() {
+               long ret = bindings.ChannelManager_get_persistable_update_future(this.ptr);
+               Reference.reachabilityFence(this);
+               if (ret >= 0 && ret <= 4096) { return null; }
+               org.ldk.structs.Future ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Future(null, ret); }
+               if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
+               return ret_hu_conv;
+       }
+
        /**
         * Gets the latest best block which was connected either via the [`chain::Listen`] or
         * [`chain::Confirm`] interfaces.
@@ -958,7 +948,7 @@ public class ChannelManager extends CommonBase {
                Reference.reachabilityFence(this);
                if (ret >= 0 && ret <= 4096) { return null; }
                org.ldk.structs.BestBlock ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BestBlock(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;
        }
 
@@ -971,7 +961,7 @@ public class ChannelManager extends CommonBase {
                Reference.reachabilityFence(this);
                if (ret >= 0 && ret <= 4096) { return null; }
                ChannelMessageHandler ret_hu_conv = new ChannelMessageHandler(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;
        }
 
@@ -993,7 +983,7 @@ public class ChannelManager extends CommonBase {
                Reference.reachabilityFence(this);
                if (ret >= 0 && ret <= 4096) { return null; }
                Payer ret_hu_conv = new Payer(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;
        }