X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FClosingSigned.java;h=e38d5987b370eb4fb599a6964c842b1a930d72fe;hb=07d5d868dfe064aadb28a7f7ca6002c16be9723d;hp=25edd17cfdde4c1158f6af38e0da38f953cde17b;hpb=166ff04616cfee975ce991607ca0df88857193df;p=ldk-java diff --git a/src/main/java/org/ldk/structs/ClosingSigned.java b/src/main/java/org/ldk/structs/ClosingSigned.java index 25edd17c..e38d5987 100644 --- a/src/main/java/org/ldk/structs/ClosingSigned.java +++ b/src/main/java/org/ldk/structs/ClosingSigned.java @@ -2,59 +2,180 @@ 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 [`closing_signed`] message to be sent to or received from a peer. + * + * [`closing_signed`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#closing-negotiation-closing_signed + */ +@SuppressWarnings("unchecked") // We correctly assign various generic arrays public class ClosingSigned extends CommonBase { ClosingSigned(Object _dummy, long ptr) { super(ptr); } @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { - bindings.ClosingSigned_free(ptr); super.finalize(); + super.finalize(); + if (ptr != 0) { bindings.ClosingSigned_free(ptr); } + } + + /** + * The channel ID + */ + public byte[] get_channel_id() { + byte[] ret = bindings.ClosingSigned_get_channel_id(this.ptr); + Reference.reachabilityFence(this); + return ret; } - public ClosingSigned(ClosingSigned orig) { - super(bindings.ClosingSigned_clone(orig.ptr & ~1)); - this.ptrs_to.add(orig); + /** + * The channel ID + */ + public void set_channel_id(byte[] val) { + bindings.ClosingSigned_set_channel_id(this.ptr, InternalUtils.check_arr_len(val, 32)); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); } - public byte[] get_channel_id(ClosingSigned this_ptr) { - byte[] ret = bindings.ClosingSigned_get_channel_id(this_ptr.ptr & ~1); - this.ptrs_to.add(this_ptr); + /** + * The proposed total fee for the closing transaction + */ + public long get_fee_satoshis() { + long ret = bindings.ClosingSigned_get_fee_satoshis(this.ptr); + Reference.reachabilityFence(this); return ret; } - public void set_channel_id(ClosingSigned this_ptr, byte[] val) { - bindings.ClosingSigned_set_channel_id(this_ptr.ptr & ~1, val); - this.ptrs_to.add(this_ptr); + /** + * The proposed total fee for the closing transaction + */ + public void set_fee_satoshis(long val) { + bindings.ClosingSigned_set_fee_satoshis(this.ptr, val); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); } - public long get_fee_satoshis(ClosingSigned this_ptr) { - long ret = bindings.ClosingSigned_get_fee_satoshis(this_ptr.ptr & ~1); - this.ptrs_to.add(this_ptr); + /** + * A signature on the closing transaction + */ + public byte[] get_signature() { + byte[] ret = bindings.ClosingSigned_get_signature(this.ptr); + Reference.reachabilityFence(this); return ret; } - public void set_fee_satoshis(ClosingSigned this_ptr, long val) { - bindings.ClosingSigned_set_fee_satoshis(this_ptr.ptr & ~1, val); - this.ptrs_to.add(this_ptr); + /** + * A signature on the closing transaction + */ + public void set_signature(byte[] val) { + bindings.ClosingSigned_set_signature(this.ptr, InternalUtils.check_arr_len(val, 64)); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); + } + + /** + * The minimum and maximum fees which the sender is willing to accept, provided only by new + * nodes. + * + * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None + */ + @Nullable + public ClosingSignedFeeRange get_fee_range() { + long ret = bindings.ClosingSigned_get_fee_range(this.ptr); + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.ClosingSignedFeeRange ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ClosingSignedFeeRange(null, ret); } + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; + return ret_hu_conv; + } + + /** + * The minimum and maximum fees which the sender is willing to accept, provided only by new + * nodes. + * + * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None + */ + public void set_fee_range(@Nullable org.ldk.structs.ClosingSignedFeeRange val) { + bindings.ClosingSigned_set_fee_range(this.ptr, val == null ? 0 : val.ptr); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); + if (this != null) { this.ptrs_to.add(val); }; } - public byte[] get_signature(ClosingSigned this_ptr) { - byte[] ret = bindings.ClosingSigned_get_signature(this_ptr.ptr & ~1); - this.ptrs_to.add(this_ptr); + /** + * Constructs a new ClosingSigned given each field + * + * Note that fee_range_arg (or a relevant inner pointer) may be NULL or all-0s to represent None + */ + public static ClosingSigned of(byte[] channel_id_arg, long fee_satoshis_arg, byte[] signature_arg, @Nullable org.ldk.structs.ClosingSignedFeeRange fee_range_arg) { + long ret = bindings.ClosingSigned_new(InternalUtils.check_arr_len(channel_id_arg, 32), fee_satoshis_arg, InternalUtils.check_arr_len(signature_arg, 64), fee_range_arg == null ? 0 : fee_range_arg.ptr); + Reference.reachabilityFence(channel_id_arg); + Reference.reachabilityFence(fee_satoshis_arg); + Reference.reachabilityFence(signature_arg); + Reference.reachabilityFence(fee_range_arg); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.ClosingSigned ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ClosingSigned(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(fee_range_arg); }; + return ret_hu_conv; + } + + long clone_ptr() { + long ret = bindings.ClosingSigned_clone_ptr(this.ptr); + Reference.reachabilityFence(this); return ret; } - public void set_signature(ClosingSigned this_ptr, byte[] val) { - bindings.ClosingSigned_set_signature(this_ptr.ptr & ~1, val); - this.ptrs_to.add(this_ptr); + /** + * Creates a copy of the ClosingSigned + */ + public ClosingSigned clone() { + long ret = bindings.ClosingSigned_clone(this.ptr); + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.ClosingSigned ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ClosingSigned(null, ret); } + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; + return ret_hu_conv; } - public ClosingSigned(byte[] channel_id_arg, long fee_satoshis_arg, byte[] signature_arg) { - super(bindings.ClosingSigned_new(channel_id_arg, fee_satoshis_arg, signature_arg)); + /** + * Checks if two ClosingSigneds 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(org.ldk.structs.ClosingSigned b) { + boolean ret = bindings.ClosingSigned_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 ClosingSigned)) return false; + return this.eq((ClosingSigned)o); + } + /** + * Serialize the ClosingSigned object into a byte array which can be read by ClosingSigned_read + */ + public byte[] write() { + byte[] ret = bindings.ClosingSigned_write(this.ptr); + Reference.reachabilityFence(this); + return ret; } - // Skipped ClosingSigned_write - public ClosingSigned(byte[] ser) { - super(bindings.ClosingSigned_read(ser)); + /** + * Read a ClosingSigned from a byte array, created by ClosingSigned_write + */ + public static Result_ClosingSignedDecodeErrorZ read(byte[] ser) { + long ret = bindings.ClosingSigned_read(ser); + Reference.reachabilityFence(ser); + if (ret >= 0 && ret <= 4096) { return null; } + Result_ClosingSignedDecodeErrorZ ret_hu_conv = Result_ClosingSignedDecodeErrorZ.constr_from_ptr(ret); + return ret_hu_conv; } }