[Java] Handle nullable arrays
[ldk-java] / src / main / java / org / ldk / structs / PaymentParameters.java
index 91e78d6f3f4e62055d81f4aa672a27bf164b0fe2..690f800eb7ec9224a1b14675c2b3bd80f984686c 100644 (file)
@@ -53,8 +53,8 @@ public class PaymentParameters extends CommonBase {
                long ret = bindings.PaymentParameters_get_features(this.ptr);
                Reference.reachabilityFence(this);
                if (ret >= 0 && ret <= 4096) { return null; }
-               InvoiceFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new InvoiceFeatures(null, ret); }
-               ret_hu_conv.ptrs_to.add(this);
+               org.ldk.structs.InvoiceFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InvoiceFeatures(null, ret); }
+               if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
                return ret_hu_conv;
        }
 
@@ -69,9 +69,10 @@ public class PaymentParameters extends CommonBase {
         * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
         */
        public void set_features(@Nullable InvoiceFeatures val) {
-               bindings.PaymentParameters_set_features(this.ptr, val == null ? 0 : val.ptr & ~1);
+               bindings.PaymentParameters_set_features(this.ptr, val == null ? 0 : val.ptr);
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(val);
+               if (this != null) { this.ptrs_to.add(val); };
        }
 
        /**
@@ -84,8 +85,8 @@ public class PaymentParameters extends CommonBase {
                RouteHint[] ret_conv_11_arr = new RouteHint[ret_conv_11_len];
                for (int l = 0; l < ret_conv_11_len; l++) {
                        long ret_conv_11 = ret[l];
-                       RouteHint ret_conv_11_hu_conv = null; if (ret_conv_11 < 0 || ret_conv_11 > 4096) { ret_conv_11_hu_conv = new RouteHint(null, ret_conv_11); }
-                       ret_conv_11_hu_conv.ptrs_to.add(this);
+                       org.ldk.structs.RouteHint ret_conv_11_hu_conv = null; if (ret_conv_11 < 0 || ret_conv_11 > 4096) { ret_conv_11_hu_conv = new org.ldk.structs.RouteHint(null, ret_conv_11); }
+                       if (ret_conv_11_hu_conv != null) { ret_conv_11_hu_conv.ptrs_to.add(this); };
                        ret_conv_11_arr[l] = ret_conv_11_hu_conv;
                }
                return ret_conv_11_arr;
@@ -95,9 +96,10 @@ public class PaymentParameters extends CommonBase {
         * Hints for routing to the payee, containing channels connecting the payee to public nodes.
         */
        public void set_route_hints(RouteHint[] val) {
-               bindings.PaymentParameters_set_route_hints(this.ptr, val != null ? Arrays.stream(val).mapToLong(val_conv_11 -> val_conv_11 == null ? 0 : val_conv_11.ptr & ~1).toArray() : null);
+               bindings.PaymentParameters_set_route_hints(this.ptr, val != null ? Arrays.stream(val).mapToLong(val_conv_11 -> val_conv_11 == null ? 0 : val_conv_11.ptr).toArray() : null);
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(val);
+               for (RouteHint val_conv_11: val) { if (this != null) { this.ptrs_to.add(val_conv_11); }; };
        }
 
        /**
@@ -107,8 +109,8 @@ public class PaymentParameters extends CommonBase {
                long ret = bindings.PaymentParameters_get_expiry_time(this.ptr);
                Reference.reachabilityFence(this);
                if (ret >= 0 && ret <= 4096) { return null; }
-               Option_u64Z ret_hu_conv = Option_u64Z.constr_from_ptr(ret);
-               ret_hu_conv.ptrs_to.add(this);
+               org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
+               if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
                return ret_hu_conv;
        }
 
@@ -123,6 +125,7 @@ public class PaymentParameters extends CommonBase {
 
        /**
         * The maximum total CLTV delta we accept for the route.
+        * Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
         */
        public int get_max_total_cltv_expiry_delta() {
                int ret = bindings.PaymentParameters_get_max_total_cltv_expiry_delta(this.ptr);
@@ -132,6 +135,7 @@ public class PaymentParameters extends CommonBase {
 
        /**
         * The maximum total CLTV delta we accept for the route.
+        * Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
         */
        public void set_max_total_cltv_expiry_delta(int val) {
                bindings.PaymentParameters_set_max_total_cltv_expiry_delta(this.ptr, val);
@@ -139,19 +143,110 @@ public class PaymentParameters extends CommonBase {
                Reference.reachabilityFence(val);
        }
 
+       /**
+        * The maximum number of paths that may be used by (MPP) payments.
+        * Defaults to [`DEFAULT_MAX_PATH_COUNT`].
+        */
+       public byte get_max_path_count() {
+               byte ret = bindings.PaymentParameters_get_max_path_count(this.ptr);
+               Reference.reachabilityFence(this);
+               return ret;
+       }
+
+       /**
+        * The maximum number of paths that may be used by (MPP) payments.
+        * Defaults to [`DEFAULT_MAX_PATH_COUNT`].
+        */
+       public void set_max_path_count(byte val) {
+               bindings.PaymentParameters_set_max_path_count(this.ptr, val);
+               Reference.reachabilityFence(this);
+               Reference.reachabilityFence(val);
+       }
+
+       /**
+        * Selects the maximum share of a channel's total capacity which will be sent over a channel,
+        * as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
+        * a lower value prefers to send larger MPP parts, potentially saturating channels and
+        * increasing failure probability for those paths.
+        * 
+        * Note that this restriction will be relaxed during pathfinding after paths which meet this
+        * restriction have been found. While paths which meet this criteria will be searched for, it
+        * is ultimately up to the scorer to select them over other paths.
+        * 
+        * A value of 0 will allow payments up to and including a channel's total announced usable
+        * capacity, a value of one will only use up to half its capacity, two 1/4, etc.
+        * 
+        * Default value: 2
+        */
+       public byte get_max_channel_saturation_power_of_half() {
+               byte ret = bindings.PaymentParameters_get_max_channel_saturation_power_of_half(this.ptr);
+               Reference.reachabilityFence(this);
+               return ret;
+       }
+
+       /**
+        * Selects the maximum share of a channel's total capacity which will be sent over a channel,
+        * as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
+        * a lower value prefers to send larger MPP parts, potentially saturating channels and
+        * increasing failure probability for those paths.
+        * 
+        * Note that this restriction will be relaxed during pathfinding after paths which meet this
+        * restriction have been found. While paths which meet this criteria will be searched for, it
+        * is ultimately up to the scorer to select them over other paths.
+        * 
+        * A value of 0 will allow payments up to and including a channel's total announced usable
+        * capacity, a value of one will only use up to half its capacity, two 1/4, etc.
+        * 
+        * Default value: 2
+        */
+       public void set_max_channel_saturation_power_of_half(byte val) {
+               bindings.PaymentParameters_set_max_channel_saturation_power_of_half(this.ptr, val);
+               Reference.reachabilityFence(this);
+               Reference.reachabilityFence(val);
+       }
+
+       /**
+        * A list of SCIDs which this payment was previously attempted over and which caused the
+        * payment to fail. Future attempts for the same payment shouldn't be relayed through any of
+        * these SCIDs.
+        * 
+        * Returns a copy of the field.
+        */
+       public long[] get_previously_failed_channels() {
+               long[] ret = bindings.PaymentParameters_get_previously_failed_channels(this.ptr);
+               Reference.reachabilityFence(this);
+               return ret;
+       }
+
+       /**
+        * A list of SCIDs which this payment was previously attempted over and which caused the
+        * payment to fail. Future attempts for the same payment shouldn't be relayed through any of
+        * these SCIDs.
+        */
+       public void set_previously_failed_channels(long[] val) {
+               bindings.PaymentParameters_set_previously_failed_channels(this.ptr, val);
+               Reference.reachabilityFence(this);
+               Reference.reachabilityFence(val);
+       }
+
        /**
         * Constructs a new PaymentParameters given each field
         */
-       public static PaymentParameters of(byte[] payee_pubkey_arg, InvoiceFeatures features_arg, RouteHint[] route_hints_arg, Option_u64Z expiry_time_arg, int max_total_cltv_expiry_delta_arg) {
-               long ret = bindings.PaymentParameters_new(InternalUtils.check_arr_len(payee_pubkey_arg, 33), features_arg == null ? 0 : features_arg.ptr & ~1, route_hints_arg != null ? Arrays.stream(route_hints_arg).mapToLong(route_hints_arg_conv_11 -> route_hints_arg_conv_11 == null ? 0 : route_hints_arg_conv_11.ptr & ~1).toArray() : null, expiry_time_arg.ptr, max_total_cltv_expiry_delta_arg);
+       public static PaymentParameters of(byte[] payee_pubkey_arg, InvoiceFeatures features_arg, RouteHint[] route_hints_arg, Option_u64Z expiry_time_arg, int max_total_cltv_expiry_delta_arg, byte max_path_count_arg, byte max_channel_saturation_power_of_half_arg, long[] previously_failed_channels_arg) {
+               long ret = bindings.PaymentParameters_new(InternalUtils.check_arr_len(payee_pubkey_arg, 33), features_arg == null ? 0 : features_arg.ptr, route_hints_arg != null ? Arrays.stream(route_hints_arg).mapToLong(route_hints_arg_conv_11 -> route_hints_arg_conv_11 == null ? 0 : route_hints_arg_conv_11.ptr).toArray() : null, expiry_time_arg.ptr, max_total_cltv_expiry_delta_arg, max_path_count_arg, max_channel_saturation_power_of_half_arg, previously_failed_channels_arg);
                Reference.reachabilityFence(payee_pubkey_arg);
                Reference.reachabilityFence(features_arg);
                Reference.reachabilityFence(route_hints_arg);
                Reference.reachabilityFence(expiry_time_arg);
                Reference.reachabilityFence(max_total_cltv_expiry_delta_arg);
+               Reference.reachabilityFence(max_path_count_arg);
+               Reference.reachabilityFence(max_channel_saturation_power_of_half_arg);
+               Reference.reachabilityFence(previously_failed_channels_arg);
                if (ret >= 0 && ret <= 4096) { return null; }
-               PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new PaymentParameters(null, ret); }
-               ret_hu_conv.ptrs_to.add(ret_hu_conv);
+               org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(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(features_arg); };
+               for (RouteHint route_hints_arg_conv_11: route_hints_arg) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(route_hints_arg_conv_11); }; };
                return ret_hu_conv;
        }
 
@@ -168,8 +263,8 @@ public class PaymentParameters extends CommonBase {
                long ret = bindings.PaymentParameters_clone(this.ptr);
                Reference.reachabilityFence(this);
                if (ret >= 0 && ret <= 4096) { return null; }
-               PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new PaymentParameters(null, ret); }
-               ret_hu_conv.ptrs_to.add(this);
+               org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
+               if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
                return ret_hu_conv;
        }
 
@@ -191,10 +286,10 @@ public class PaymentParameters extends CommonBase {
         * Two objects with NULL inner values will be considered "equal" here.
         */
        public boolean eq(PaymentParameters b) {
-               boolean ret = bindings.PaymentParameters_eq(this.ptr, b == null ? 0 : b.ptr & ~1);
+               boolean ret = bindings.PaymentParameters_eq(this.ptr, b == null ? 0 : b.ptr);
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(b);
-               this.ptrs_to.add(b);
+               if (this != null) { this.ptrs_to.add(b); };
                return ret;
        }
 
@@ -229,8 +324,8 @@ public class PaymentParameters extends CommonBase {
                long ret = bindings.PaymentParameters_from_node_id(InternalUtils.check_arr_len(payee_pubkey, 33));
                Reference.reachabilityFence(payee_pubkey);
                if (ret >= 0 && ret <= 4096) { return null; }
-               PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new PaymentParameters(null, ret); }
-               ret_hu_conv.ptrs_to.add(ret_hu_conv);
+               org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
+               if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
                return ret_hu_conv;
        }
 
@@ -241,8 +336,8 @@ public class PaymentParameters extends CommonBase {
                long ret = bindings.PaymentParameters_for_keysend(InternalUtils.check_arr_len(payee_pubkey, 33));
                Reference.reachabilityFence(payee_pubkey);
                if (ret >= 0 && ret <= 4096) { return null; }
-               PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new PaymentParameters(null, ret); }
-               ret_hu_conv.ptrs_to.add(ret_hu_conv);
+               org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
+               if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
                return ret_hu_conv;
        }