X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FRoute.java;h=74a08d98e909ac063dd36162b05f73b69d238a6c;hb=6fe917116a65d7b62123226c4240d77ea2719783;hp=6aad4ee74d3e865bd2d8d4ec3527aa8a7da3e170;hpb=8c0814bf345323be8f16e075a9af0bd43d9400ee;p=ldk-java diff --git a/src/main/java/org/ldk/structs/Route.java b/src/main/java/org/ldk/structs/Route.java index 6aad4ee7..74a08d98 100644 --- a/src/main/java/org/ldk/structs/Route.java +++ b/src/main/java/org/ldk/structs/Route.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; @@ -30,13 +31,16 @@ public class Route extends CommonBase { */ public RouteHop[][] get_paths() { long[][] ret = bindings.Route_get_paths(this.ptr); - RouteHop[][] ret_conv_12_arr = new RouteHop[ret.length][]; - for (int m = 0; m < ret.length; m++) { + Reference.reachabilityFence(this); + int ret_conv_12_len = ret.length; + RouteHop[][] ret_conv_12_arr = new RouteHop[ret_conv_12_len][]; + for (int m = 0; m < ret_conv_12_len; m++) { long[] ret_conv_12 = ret[m]; - RouteHop[] ret_conv_12_conv_10_arr = new RouteHop[ret_conv_12.length]; - for (int k = 0; k < ret_conv_12.length; k++) { + int ret_conv_12_conv_10_len = ret_conv_12.length; + RouteHop[] ret_conv_12_conv_10_arr = new RouteHop[ret_conv_12_conv_10_len]; + for (int k = 0; k < ret_conv_12_conv_10_len; k++) { long ret_conv_12_conv_10 = ret_conv_12[k]; - RouteHop ret_conv_12_conv_10_hu_conv = new RouteHop(null, ret_conv_12_conv_10); + RouteHop ret_conv_12_conv_10_hu_conv = null; if (ret_conv_12_conv_10 < 0 || ret_conv_12_conv_10 > 4096) { ret_conv_12_conv_10_hu_conv = new RouteHop(null, ret_conv_12_conv_10); } ret_conv_12_conv_10_hu_conv.ptrs_to.add(this); ret_conv_12_conv_10_arr[k] = ret_conv_12_conv_10_hu_conv; } @@ -55,26 +59,71 @@ public class Route extends CommonBase { */ public void set_paths(RouteHop[][] val) { bindings.Route_set_paths(this.ptr, val != null ? Arrays.stream(val).map(val_conv_12 -> val_conv_12 != null ? Arrays.stream(val_conv_12).mapToLong(val_conv_12_conv_10 -> val_conv_12_conv_10 == null ? 0 : val_conv_12_conv_10.ptr & ~1).toArray() : null).toArray(long[][]::new) : null); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); + } + + /** + * The `payment_params` parameter passed to [`find_route`]. + * This is used by `ChannelManager` to track information which may be required for retries, + * provided back to you via [`Event::PaymentPathFailed`]. + * + * [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed + * + * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None + */ + @Nullable + public PaymentParameters get_payment_params() { + long ret = bindings.Route_get_payment_params(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); + return ret_hu_conv; + } + + /** + * The `payment_params` parameter passed to [`find_route`]. + * This is used by `ChannelManager` to track information which may be required for retries, + * provided back to you via [`Event::PaymentPathFailed`]. + * + * [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed + * + * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None + */ + public void set_payment_params(@Nullable PaymentParameters val) { + bindings.Route_set_payment_params(this.ptr, val == null ? 0 : val.ptr & ~1); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); } /** * Constructs a new Route given each field */ - public static Route of(RouteHop[][] paths_arg) { - long ret = bindings.Route_new(paths_arg != null ? Arrays.stream(paths_arg).map(paths_arg_conv_12 -> paths_arg_conv_12 != null ? Arrays.stream(paths_arg_conv_12).mapToLong(paths_arg_conv_12_conv_10 -> paths_arg_conv_12_conv_10 == null ? 0 : paths_arg_conv_12_conv_10.ptr & ~1).toArray() : null).toArray(long[][]::new) : null); - if (ret < 1024) { return null; } - Route ret_hu_conv = new Route(null, ret); + public static Route of(RouteHop[][] paths_arg, PaymentParameters payment_params_arg) { + long ret = bindings.Route_new(paths_arg != null ? Arrays.stream(paths_arg).map(paths_arg_conv_12 -> paths_arg_conv_12 != null ? Arrays.stream(paths_arg_conv_12).mapToLong(paths_arg_conv_12_conv_10 -> paths_arg_conv_12_conv_10 == null ? 0 : paths_arg_conv_12_conv_10.ptr & ~1).toArray() : null).toArray(long[][]::new) : null, payment_params_arg == null ? 0 : payment_params_arg.ptr & ~1); + Reference.reachabilityFence(paths_arg); + Reference.reachabilityFence(payment_params_arg); + if (ret >= 0 && ret <= 4096) { return null; } + Route ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new Route(null, ret); } ret_hu_conv.ptrs_to.add(ret_hu_conv); return ret_hu_conv; } + long clone_ptr() { + long ret = bindings.Route_clone_ptr(this.ptr); + Reference.reachabilityFence(this); + return ret; + } + /** * Creates a copy of the Route */ public Route clone() { long ret = bindings.Route_clone(this.ptr); - if (ret < 1024) { return null; } - Route ret_hu_conv = new Route(null, ret); + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } + Route ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new Route(null, ret); } ret_hu_conv.ptrs_to.add(this); return ret_hu_conv; } @@ -84,9 +133,13 @@ public class Route extends CommonBase { */ public long hash() { long ret = bindings.Route_hash(this.ptr); + Reference.reachabilityFence(this); return ret; } + @Override public int hashCode() { + return (int)this.hash(); + } /** * Checks if two Routes contain equal inner contents. * This ignores pointers and is_owned flags and looks at the values in fields. @@ -94,18 +147,25 @@ public class Route extends CommonBase { */ public boolean eq(Route b) { boolean ret = bindings.Route_eq(this.ptr, b == null ? 0 : b.ptr & ~1); + Reference.reachabilityFence(this); + Reference.reachabilityFence(b); this.ptrs_to.add(b); return ret; } + @Override public boolean equals(Object o) { + if (!(o instanceof Route)) return false; + return this.eq((Route)o); + } /** * Returns the total amount of fees paid on this [`Route`]. * * This doesn't include any extra payment made to the recipient, which can happen in excess of - * the amount passed to [`get_route`]'s `final_value_msat`. + * the amount passed to [`find_route`]'s `params.final_value_msat`. */ public long get_total_fees() { long ret = bindings.Route_get_total_fees(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -114,6 +174,7 @@ public class Route extends CommonBase { */ public long get_total_amount() { long ret = bindings.Route_get_total_amount(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -122,6 +183,7 @@ public class Route extends CommonBase { */ public byte[] write() { byte[] ret = bindings.Route_write(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -130,7 +192,8 @@ public class Route extends CommonBase { */ public static Result_RouteDecodeErrorZ read(byte[] ser) { long ret = bindings.Route_read(ser); - if (ret < 1024) { return null; } + Reference.reachabilityFence(ser); + if (ret >= 0 && ret <= 4096) { return null; } Result_RouteDecodeErrorZ ret_hu_conv = Result_RouteDecodeErrorZ.constr_from_ptr(ret); return ret_hu_conv; }