X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FCommitmentSigned.java;h=adce70a4749179344745d7d7590541b083326b85;hb=f3e670e9341decac613d33fc52febf19cea32f20;hp=8ef67b84686d96f01459c2e5ca9bb5424a22b25b;hpb=d063d65c20bf007f42dc2ae52bd62dc1c2ef51e4;p=ldk-java diff --git a/src/main/java/org/ldk/structs/CommitmentSigned.java b/src/main/java/org/ldk/structs/CommitmentSigned.java index 8ef67b84..adce70a4 100644 --- a/src/main/java/org/ldk/structs/CommitmentSigned.java +++ b/src/main/java/org/ldk/structs/CommitmentSigned.java @@ -2,43 +2,103 @@ package org.ldk.structs; import org.ldk.impl.bindings; import org.ldk.enums.*; +import org.ldk.util.*; +import java.util.Arrays; +import javax.annotation.Nullable; + +/** + * A commitment_signed message to be sent or received from a peer + */ +@SuppressWarnings("unchecked") // We correctly assign various generic arrays public class CommitmentSigned extends CommonBase { CommitmentSigned(Object _dummy, long ptr) { super(ptr); } @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { - bindings.CommitmentSigned_free(ptr); super.finalize(); + super.finalize(); + if (ptr != 0) { bindings.CommitmentSigned_free(ptr); } + } + + /** + * The channel ID + */ + public byte[] get_channel_id() { + byte[] ret = bindings.CommitmentSigned_get_channel_id(this.ptr); + return ret; + } + + /** + * The channel ID + */ + public void set_channel_id(byte[] val) { + bindings.CommitmentSigned_set_channel_id(this.ptr, InternalUtils.check_arr_len(val, 32)); + } + + /** + * A signature on the commitment transaction + */ + public byte[] get_signature() { + byte[] ret = bindings.CommitmentSigned_get_signature(this.ptr); + return ret; + } + + /** + * A signature on the commitment transaction + */ + public void set_signature(byte[] val) { + bindings.CommitmentSigned_set_signature(this.ptr, InternalUtils.check_arr_len(val, 64)); + } + + /** + * Signatures on the HTLC transactions + */ + public void set_htlc_signatures(byte[][] val) { + bindings.CommitmentSigned_set_htlc_signatures(this.ptr, val != null ? Arrays.stream(val).map(val_conv_8 -> InternalUtils.check_arr_len(val_conv_8, 64)).toArray(byte[][]::new) : null); } - public CommitmentSigned(CommitmentSigned orig) { - super(bindings.CommitmentSigned_clone(orig.ptr & ~1)); - this.ptrs_to.add(orig); + /** + * Constructs a new CommitmentSigned given each field + */ + public static CommitmentSigned of(byte[] channel_id_arg, byte[] signature_arg, byte[][] htlc_signatures_arg) { + long ret = bindings.CommitmentSigned_new(InternalUtils.check_arr_len(channel_id_arg, 32), InternalUtils.check_arr_len(signature_arg, 64), htlc_signatures_arg != null ? Arrays.stream(htlc_signatures_arg).map(htlc_signatures_arg_conv_8 -> InternalUtils.check_arr_len(htlc_signatures_arg_conv_8, 64)).toArray(byte[][]::new) : null); + if (ret >= 0 && ret <= 4096) { return null; } + CommitmentSigned ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new CommitmentSigned(null, ret); } + ret_hu_conv.ptrs_to.add(ret_hu_conv); + return ret_hu_conv; } - public byte[] get_channel_id(CommitmentSigned this_ptr) { - byte[] ret = bindings.CommitmentSigned_get_channel_id(this_ptr.ptr & ~1); - this.ptrs_to.add(this_ptr); + long clone_ptr() { + long ret = bindings.CommitmentSigned_clone_ptr(this.ptr); return ret; } - public void set_channel_id(CommitmentSigned this_ptr, byte[] val) { - bindings.CommitmentSigned_set_channel_id(this_ptr.ptr & ~1, val); - this.ptrs_to.add(this_ptr); + /** + * Creates a copy of the CommitmentSigned + */ + public CommitmentSigned clone() { + long ret = bindings.CommitmentSigned_clone(this.ptr); + if (ret >= 0 && ret <= 4096) { return null; } + CommitmentSigned ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new CommitmentSigned(null, ret); } + ret_hu_conv.ptrs_to.add(this); + return ret_hu_conv; } - public byte[] get_signature(CommitmentSigned this_ptr) { - byte[] ret = bindings.CommitmentSigned_get_signature(this_ptr.ptr & ~1); - this.ptrs_to.add(this_ptr); + /** + * Serialize the CommitmentSigned object into a byte array which can be read by CommitmentSigned_read + */ + public byte[] write() { + byte[] ret = bindings.CommitmentSigned_write(this.ptr); return ret; } - public void set_signature(CommitmentSigned this_ptr, byte[] val) { - bindings.CommitmentSigned_set_signature(this_ptr.ptr & ~1, val); - this.ptrs_to.add(this_ptr); + /** + * Read a CommitmentSigned from a byte array, created by CommitmentSigned_write + */ + public static Result_CommitmentSignedDecodeErrorZ read(byte[] ser) { + long ret = bindings.CommitmentSigned_read(ser); + if (ret >= 0 && ret <= 4096) { return null; } + Result_CommitmentSignedDecodeErrorZ ret_hu_conv = Result_CommitmentSignedDecodeErrorZ.constr_from_ptr(ret); + return ret_hu_conv; } - // Skipped CommitmentSigned_set_htlc_signatures - // Skipped CommitmentSigned_new - // Skipped CommitmentSigned_write - // Skipped CommitmentSigned_read }