X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FRouteHintHop.java;h=cc7e19c58c1e1d975f38344aa4ecb55a31fbf099;hb=2bb592fb946e316dba9f4d1123f8ac72ff4e9bf8;hp=86018744e02e99387810cb187d8bb09fb930c008;hpb=99d1a3bd6dc5c7ed1499b30bfc2b4c66ffaf858a;p=ldk-java diff --git a/src/main/java/org/ldk/structs/RouteHintHop.java b/src/main/java/org/ldk/structs/RouteHintHop.java index 86018744..cc7e19c5 100644 --- a/src/main/java/org/ldk/structs/RouteHintHop.java +++ b/src/main/java/org/ldk/structs/RouteHintHop.java @@ -4,11 +4,16 @@ 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; /** * A channel descriptor for a hop along a payment path. + * + * While this generally comes from BOLT 11's `r` field, this struct includes more fields than are + * available in BOLT 11. Thus, encoding and decoding this via `lightning-invoice` is lossy, as + * fields not supported in BOLT 11 will be stripped. */ @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class RouteHintHop extends CommonBase { @@ -24,6 +29,7 @@ public class RouteHintHop extends CommonBase { */ public byte[] get_src_node_id() { byte[] ret = bindings.RouteHintHop_get_src_node_id(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -31,7 +37,9 @@ public class RouteHintHop extends CommonBase { * The node_id of the non-target end of the route */ public void set_src_node_id(byte[] val) { - bindings.RouteHintHop_set_src_node_id(this.ptr, val); + bindings.RouteHintHop_set_src_node_id(this.ptr, InternalUtils.check_arr_len(val, 33)); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); } /** @@ -39,6 +47,7 @@ public class RouteHintHop extends CommonBase { */ public long get_short_channel_id() { long ret = bindings.RouteHintHop_get_short_channel_id(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -47,6 +56,8 @@ public class RouteHintHop extends CommonBase { */ public void set_short_channel_id(long val) { bindings.RouteHintHop_set_short_channel_id(this.ptr, val); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); } /** @@ -54,17 +65,21 @@ public class RouteHintHop extends CommonBase { */ public RoutingFees get_fees() { long ret = bindings.RouteHintHop_get_fees(this.ptr); + Reference.reachabilityFence(this); if (ret >= 0 && ret <= 4096) { return null; } - RoutingFees ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new RoutingFees(null, ret); } - ret_hu_conv.ptrs_to.add(this); + org.ldk.structs.RoutingFees ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RoutingFees(null, ret); } + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; return ret_hu_conv; } /** * The fees which must be paid to use this channel */ - public void set_fees(RoutingFees val) { - bindings.RouteHintHop_set_fees(this.ptr, val == null ? 0 : val.ptr & ~1); + public void set_fees(org.ldk.structs.RoutingFees val) { + bindings.RouteHintHop_set_fees(this.ptr, val == null ? 0 : val.ptr); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); + if (this != null) { this.ptrs_to.add(val); }; } /** @@ -72,6 +87,7 @@ public class RouteHintHop extends CommonBase { */ public short get_cltv_expiry_delta() { short ret = bindings.RouteHintHop_get_cltv_expiry_delta(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -80,6 +96,8 @@ public class RouteHintHop extends CommonBase { */ public void set_cltv_expiry_delta(short val) { bindings.RouteHintHop_set_cltv_expiry_delta(this.ptr, val); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); } /** @@ -87,17 +105,21 @@ public class RouteHintHop extends CommonBase { */ public Option_u64Z get_htlc_minimum_msat() { long ret = bindings.RouteHintHop_get_htlc_minimum_msat(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; } /** * The minimum value, in msat, which must be relayed to the next hop. */ - public void set_htlc_minimum_msat(Option_u64Z val) { + public void set_htlc_minimum_msat(org.ldk.structs.Option_u64Z val) { bindings.RouteHintHop_set_htlc_minimum_msat(this.ptr, val.ptr); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); + if (this != null) { this.ptrs_to.add(val); }; } /** @@ -105,65 +127,96 @@ public class RouteHintHop extends CommonBase { */ public Option_u64Z get_htlc_maximum_msat() { long ret = bindings.RouteHintHop_get_htlc_maximum_msat(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; } /** * The maximum value in msat available for routing with a single HTLC. */ - public void set_htlc_maximum_msat(Option_u64Z val) { + public void set_htlc_maximum_msat(org.ldk.structs.Option_u64Z val) { bindings.RouteHintHop_set_htlc_maximum_msat(this.ptr, val.ptr); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); + if (this != null) { this.ptrs_to.add(val); }; } /** * Constructs a new RouteHintHop given each field */ - public static RouteHintHop of(byte[] src_node_id_arg, long short_channel_id_arg, RoutingFees fees_arg, short cltv_expiry_delta_arg, Option_u64Z htlc_minimum_msat_arg, Option_u64Z htlc_maximum_msat_arg) { - long ret = bindings.RouteHintHop_new(src_node_id_arg, short_channel_id_arg, fees_arg == null ? 0 : fees_arg.ptr & ~1, cltv_expiry_delta_arg, htlc_minimum_msat_arg.ptr, htlc_maximum_msat_arg.ptr); + public static RouteHintHop of(byte[] src_node_id_arg, long short_channel_id_arg, org.ldk.structs.RoutingFees fees_arg, short cltv_expiry_delta_arg, org.ldk.structs.Option_u64Z htlc_minimum_msat_arg, org.ldk.structs.Option_u64Z htlc_maximum_msat_arg) { + long ret = bindings.RouteHintHop_new(InternalUtils.check_arr_len(src_node_id_arg, 33), short_channel_id_arg, fees_arg == null ? 0 : fees_arg.ptr, cltv_expiry_delta_arg, htlc_minimum_msat_arg.ptr, htlc_maximum_msat_arg.ptr); + Reference.reachabilityFence(src_node_id_arg); + Reference.reachabilityFence(short_channel_id_arg); + Reference.reachabilityFence(fees_arg); + Reference.reachabilityFence(cltv_expiry_delta_arg); + Reference.reachabilityFence(htlc_minimum_msat_arg); + Reference.reachabilityFence(htlc_maximum_msat_arg); if (ret >= 0 && ret <= 4096) { return null; } - RouteHintHop ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new RouteHintHop(null, ret); } - ret_hu_conv.ptrs_to.add(ret_hu_conv); + org.ldk.structs.RouteHintHop ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RouteHintHop(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(fees_arg); }; + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(htlc_minimum_msat_arg); }; + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(htlc_maximum_msat_arg); }; return ret_hu_conv; } + long clone_ptr() { + long ret = bindings.RouteHintHop_clone_ptr(this.ptr); + Reference.reachabilityFence(this); + return ret; + } + /** * Creates a copy of the RouteHintHop */ public RouteHintHop clone() { long ret = bindings.RouteHintHop_clone(this.ptr); + Reference.reachabilityFence(this); if (ret >= 0 && ret <= 4096) { return null; } - RouteHintHop ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new RouteHintHop(null, ret); } - ret_hu_conv.ptrs_to.add(this); + org.ldk.structs.RouteHintHop ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RouteHintHop(null, ret); } + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; return ret_hu_conv; } /** - * Checks if two RouteHintHops contain equal inner contents. + * Generates a non-cryptographic 64-bit hash of the RouteHintHop. */ public long hash() { long ret = bindings.RouteHintHop_hash(this.ptr); + Reference.reachabilityFence(this); return ret; } + @Override public int hashCode() { + return (int)this.hash(); + } /** * Checks if two RouteHintHops contain equal inner contents. * This ignores pointers and is_owned flags and looks at the values in fields. * Two objects with NULL inner values will be considered "equal" here. */ - public boolean eq(RouteHintHop b) { - boolean ret = bindings.RouteHintHop_eq(this.ptr, b == null ? 0 : b.ptr & ~1); - this.ptrs_to.add(b); + public boolean eq(org.ldk.structs.RouteHintHop b) { + boolean ret = bindings.RouteHintHop_eq(this.ptr, b == null ? 0 : b.ptr); + Reference.reachabilityFence(this); + Reference.reachabilityFence(b); + if (this != null) { this.ptrs_to.add(b); }; return ret; } + @Override public boolean equals(Object o) { + if (!(o instanceof RouteHintHop)) return false; + return this.eq((RouteHintHop)o); + } /** * Serialize the RouteHintHop object into a byte array which can be read by RouteHintHop_read */ public byte[] write() { byte[] ret = bindings.RouteHintHop_write(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -172,6 +225,7 @@ public class RouteHintHop extends CommonBase { */ public static Result_RouteHintHopDecodeErrorZ read(byte[] ser) { long ret = bindings.RouteHintHop_read(ser); + Reference.reachabilityFence(ser); if (ret >= 0 && ret <= 4096) { return null; } Result_RouteHintHopDecodeErrorZ ret_hu_conv = Result_RouteHintHopDecodeErrorZ.constr_from_ptr(ret); return ret_hu_conv;