X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FDataLossProtect.java;h=66a6af4413918b9b93ec83425bc6c5ef62f4895b;hb=b0c50b891cbca28d3bd1d86276c132ff5221d8e4;hp=47f90cf9a0d95e91c8d3eec9a6992fd1eb143113;hpb=2ed9081562d00a8645604b07629e963231d49e0f;p=ldk-java diff --git a/src/main/java/org/ldk/structs/DataLossProtect.java b/src/main/java/org/ldk/structs/DataLossProtect.java index 47f90cf9..66a6af44 100644 --- a/src/main/java/org/ldk/structs/DataLossProtect.java +++ b/src/main/java/org/ldk/structs/DataLossProtect.java @@ -2,43 +2,75 @@ package org.ldk.structs; import org.ldk.impl.bindings; import org.ldk.enums.*; +import org.ldk.util.*; +import java.util.Arrays; + +/** + * Proof that the sender knows the per-commitment secret of the previous commitment transaction. + * This is used to convince the recipient that the channel is at a certain commitment + * number even if they lost that data due to a local failure. Of course, the peer may lie + * and even later commitments may have been revoked. + */ +@SuppressWarnings("unchecked") // We correctly assign various generic arrays public class DataLossProtect extends CommonBase { DataLossProtect(Object _dummy, long ptr) { super(ptr); } @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { - bindings.DataLossProtect_free(ptr); super.finalize(); - } - - public DataLossProtect(DataLossProtect orig) { - super(bindings.DataLossProtect_clone(orig == null ? 0 : orig.ptr & ~1)); - this.ptrs_to.add(orig); + super.finalize(); + if (ptr != 0) { bindings.DataLossProtect_free(ptr); } } - public byte[] get_your_last_per_commitment_secret(DataLossProtect this_ptr) { - byte[] ret = bindings.DataLossProtect_get_your_last_per_commitment_secret(this_ptr == null ? 0 : this_ptr.ptr & ~1); - this.ptrs_to.add(this_ptr); + /** + * Proof that the sender knows the per-commitment secret of a specific commitment transaction + * belonging to the recipient + */ + public byte[] get_your_last_per_commitment_secret() { + byte[] ret = bindings.DataLossProtect_get_your_last_per_commitment_secret(this.ptr); return ret; } - public void set_your_last_per_commitment_secret(DataLossProtect this_ptr, byte[] val) { - bindings.DataLossProtect_set_your_last_per_commitment_secret(this_ptr == null ? 0 : this_ptr.ptr & ~1, val); - this.ptrs_to.add(this_ptr); + /** + * Proof that the sender knows the per-commitment secret of a specific commitment transaction + * belonging to the recipient + */ + public void set_your_last_per_commitment_secret(byte[] val) { + bindings.DataLossProtect_set_your_last_per_commitment_secret(this.ptr, val); } - public byte[] get_my_current_per_commitment_point(DataLossProtect this_ptr) { - byte[] ret = bindings.DataLossProtect_get_my_current_per_commitment_point(this_ptr == null ? 0 : this_ptr.ptr & ~1); - this.ptrs_to.add(this_ptr); + /** + * The sender's per-commitment point for their current commitment transaction + */ + public byte[] get_my_current_per_commitment_point() { + byte[] ret = bindings.DataLossProtect_get_my_current_per_commitment_point(this.ptr); return ret; } - public void set_my_current_per_commitment_point(DataLossProtect this_ptr, byte[] val) { - bindings.DataLossProtect_set_my_current_per_commitment_point(this_ptr == null ? 0 : this_ptr.ptr & ~1, val); - this.ptrs_to.add(this_ptr); + /** + * The sender's per-commitment point for their current commitment transaction + */ + public void set_my_current_per_commitment_point(byte[] val) { + bindings.DataLossProtect_set_my_current_per_commitment_point(this.ptr, val); + } + + /** + * Constructs a new DataLossProtect given each field + */ + public static DataLossProtect of(byte[] your_last_per_commitment_secret_arg, byte[] my_current_per_commitment_point_arg) { + long ret = bindings.DataLossProtect_new(your_last_per_commitment_secret_arg, my_current_per_commitment_point_arg); + DataLossProtect ret_hu_conv = new DataLossProtect(null, ret); + ret_hu_conv.ptrs_to.add(ret_hu_conv); + return ret_hu_conv; } - public DataLossProtect(byte[] your_last_per_commitment_secret_arg, byte[] my_current_per_commitment_point_arg) { - super(bindings.DataLossProtect_new(your_last_per_commitment_secret_arg, my_current_per_commitment_point_arg)); + /** + * Creates a copy of the DataLossProtect + */ + public DataLossProtect clone() { + long ret = bindings.DataLossProtect_clone(this.ptr); + DataLossProtect ret_hu_conv = new DataLossProtect(null, ret); + ret_hu_conv.ptrs_to.add(this); + return ret_hu_conv; } }