X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FRouteHint.java;h=849ea62385ff06c03016769db01dea1d81cba9be;hb=1854b5cebef22ace9e9e4dd191f609818df9ce08;hp=71fdc7fee9a79cf5fcefe4de6e13c936ace49926;hpb=2ed9081562d00a8645604b07629e963231d49e0f;p=ldk-java diff --git a/src/main/java/org/ldk/structs/RouteHint.java b/src/main/java/org/ldk/structs/RouteHint.java index 71fdc7fe..849ea623 100644 --- a/src/main/java/org/ldk/structs/RouteHint.java +++ b/src/main/java/org/ldk/structs/RouteHint.java @@ -2,78 +2,120 @@ package org.ldk.structs; 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 list of hops along a payment path terminating with a channel to the recipient. + */ +@SuppressWarnings("unchecked") // We correctly assign various generic arrays public class RouteHint extends CommonBase { RouteHint(Object _dummy, long ptr) { super(ptr); } @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { - bindings.RouteHint_free(ptr); super.finalize(); + super.finalize(); + if (ptr != 0) { bindings.RouteHint_free(ptr); } } - public RouteHint(RouteHint orig) { - super(bindings.RouteHint_clone(orig == null ? 0 : orig.ptr & ~1)); - this.ptrs_to.add(orig); + public RouteHintHop[] get_a() { + long[] ret = bindings.RouteHint_get_a(this.ptr); + Reference.reachabilityFence(this); + RouteHintHop[] ret_conv_14_arr = new RouteHintHop[ret.length]; + for (int o = 0; o < ret.length; o++) { + long ret_conv_14 = ret[o]; + RouteHintHop ret_conv_14_hu_conv = null; if (ret_conv_14 < 0 || ret_conv_14 > 4096) { ret_conv_14_hu_conv = new RouteHintHop(null, ret_conv_14); } + ret_conv_14_hu_conv.ptrs_to.add(this); + ret_conv_14_arr[o] = ret_conv_14_hu_conv; + } + return ret_conv_14_arr; } - public byte[] get_src_node_id(RouteHint this_ptr) { - byte[] ret = bindings.RouteHint_get_src_node_id(this_ptr == null ? 0 : this_ptr.ptr & ~1); - this.ptrs_to.add(this_ptr); - return ret; + public void set_a(RouteHintHop[] val) { + bindings.RouteHint_set_a(this.ptr, val != null ? Arrays.stream(val).mapToLong(val_conv_14 -> val_conv_14 == null ? 0 : val_conv_14.ptr & ~1).toArray() : null); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); } - public void set_src_node_id(RouteHint this_ptr, byte[] val) { - bindings.RouteHint_set_src_node_id(this_ptr == null ? 0 : this_ptr.ptr & ~1, val); - this.ptrs_to.add(this_ptr); + /** + * Constructs a new RouteHint given each field + */ + public static RouteHint of(RouteHintHop[] a_arg) { + long ret = bindings.RouteHint_new(a_arg != null ? Arrays.stream(a_arg).mapToLong(a_arg_conv_14 -> a_arg_conv_14 == null ? 0 : a_arg_conv_14.ptr & ~1).toArray() : null); + Reference.reachabilityFence(a_arg); + if (ret >= 0 && ret <= 4096) { return null; } + RouteHint ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new RouteHint(null, ret); } + ret_hu_conv.ptrs_to.add(ret_hu_conv); + return ret_hu_conv; } - public long get_short_channel_id(RouteHint this_ptr) { - long ret = bindings.RouteHint_get_short_channel_id(this_ptr == null ? 0 : this_ptr.ptr & ~1); - this.ptrs_to.add(this_ptr); + long clone_ptr() { + long ret = bindings.RouteHint_clone_ptr(this.ptr); + Reference.reachabilityFence(this); return ret; } - public void set_short_channel_id(RouteHint this_ptr, long val) { - bindings.RouteHint_set_short_channel_id(this_ptr == null ? 0 : this_ptr.ptr & ~1, val); - this.ptrs_to.add(this_ptr); + /** + * Creates a copy of the RouteHint + */ + public RouteHint clone() { + long ret = bindings.RouteHint_clone(this.ptr); + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } + RouteHint ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new RouteHint(null, ret); } + ret_hu_conv.ptrs_to.add(this); + return ret_hu_conv; } - public RoutingFees get_fees(RouteHint this_ptr) { - RoutingFees ret = new RoutingFees(null, bindings.RouteHint_get_fees(this_ptr == null ? 0 : this_ptr.ptr & ~1)); - this.ptrs_to.add(this_ptr); + /** + * Checks if two RouteHints contain equal inner contents. + */ + public long hash() { + long ret = bindings.RouteHint_hash(this.ptr); + Reference.reachabilityFence(this); return ret; } - public void set_fees(RouteHint this_ptr, RoutingFees val) { - bindings.RouteHint_set_fees(this_ptr == null ? 0 : this_ptr.ptr & ~1, val == null ? 0 : val.ptr & ~1); - this.ptrs_to.add(this_ptr); - this.ptrs_to.add(val); + @Override public int hashCode() { + return (int)this.hash(); } - - public short get_cltv_expiry_delta(RouteHint this_ptr) { - short ret = bindings.RouteHint_get_cltv_expiry_delta(this_ptr == null ? 0 : this_ptr.ptr & ~1); - this.ptrs_to.add(this_ptr); + /** + * Checks if two RouteHints 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(RouteHint b) { + boolean ret = bindings.RouteHint_eq(this.ptr, b == null ? 0 : b.ptr & ~1); + Reference.reachabilityFence(this); + Reference.reachabilityFence(b); + this.ptrs_to.add(b); return ret; } - public void set_cltv_expiry_delta(RouteHint this_ptr, short val) { - bindings.RouteHint_set_cltv_expiry_delta(this_ptr == null ? 0 : this_ptr.ptr & ~1, val); - this.ptrs_to.add(this_ptr); + @Override public boolean equals(Object o) { + if (!(o instanceof RouteHint)) return false; + return this.eq((RouteHint)o); } - - public long get_htlc_minimum_msat(RouteHint this_ptr) { - long ret = bindings.RouteHint_get_htlc_minimum_msat(this_ptr == null ? 0 : this_ptr.ptr & ~1); - this.ptrs_to.add(this_ptr); + /** + * Serialize the RouteHint object into a byte array which can be read by RouteHint_read + */ + public byte[] write() { + byte[] ret = bindings.RouteHint_write(this.ptr); + Reference.reachabilityFence(this); return ret; } - public void set_htlc_minimum_msat(RouteHint this_ptr, long val) { - bindings.RouteHint_set_htlc_minimum_msat(this_ptr == null ? 0 : this_ptr.ptr & ~1, val); - this.ptrs_to.add(this_ptr); - } - - public RouteHint(byte[] src_node_id_arg, long short_channel_id_arg, RoutingFees fees_arg, short cltv_expiry_delta_arg, long htlc_minimum_msat_arg) { - super(bindings.RouteHint_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)); - this.ptrs_to.add(fees_arg); + /** + * Read a RouteHint from a byte array, created by RouteHint_write + */ + public static Result_RouteHintDecodeErrorZ read(byte[] ser) { + long ret = bindings.RouteHint_read(ser); + Reference.reachabilityFence(ser); + if (ret >= 0 && ret <= 4096) { return null; } + Result_RouteHintDecodeErrorZ ret_hu_conv = Result_RouteHintDecodeErrorZ.constr_from_ptr(ret); + return ret_hu_conv; } }