X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FHTLCUpdate.java;h=96789c0a81fc95b653bb09802340fc073ee484d2;hb=1854b5cebef22ace9e9e4dd191f609818df9ce08;hp=9ffcbd0fae5a254fefbfa0ea514635e2259eb4b5;hpb=592c4f92dd3011a2f2a7988ce66ed166c3a8f58c;p=ldk-java diff --git a/src/main/java/org/ldk/structs/HTLCUpdate.java b/src/main/java/org/ldk/structs/HTLCUpdate.java index 9ffcbd0f..96789c0a 100644 --- a/src/main/java/org/ldk/structs/HTLCUpdate.java +++ b/src/main/java/org/ldk/structs/HTLCUpdate.java @@ -2,28 +2,62 @@ 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; + +/** + * Simple structure sent back by `chain::Watch` when an HTLC from a forward channel is detected on + * chain. Used to update the corresponding HTLC in the backward channel. Failing to pass the + * preimage claim backward will lead to loss of funds. + */ +@SuppressWarnings("unchecked") // We correctly assign various generic arrays public class HTLCUpdate extends CommonBase { HTLCUpdate(Object _dummy, long ptr) { super(ptr); } @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.HTLCUpdate_free(ptr); + if (ptr != 0) { bindings.HTLCUpdate_free(ptr); } + } + + long clone_ptr() { + long ret = bindings.HTLCUpdate_clone_ptr(this.ptr); + Reference.reachabilityFence(this); + return ret; } - public HTLCUpdate(HTLCUpdate orig) { - super(bindings.HTLCUpdate_clone(orig == null ? 0 : orig.ptr & ~1)); - this.ptrs_to.add(orig); + /** + * Creates a copy of the HTLCUpdate + */ + public HTLCUpdate clone() { + long ret = bindings.HTLCUpdate_clone(this.ptr); + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } + HTLCUpdate ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new HTLCUpdate(null, ret); } + ret_hu_conv.ptrs_to.add(this); + return ret_hu_conv; } - public byte[] write(HTLCUpdate obj) { - byte[] ret = bindings.HTLCUpdate_write(obj == null ? 0 : obj.ptr & ~1); - this.ptrs_to.add(obj); + /** + * Serialize the HTLCUpdate object into a byte array which can be read by HTLCUpdate_read + */ + public byte[] write() { + byte[] ret = bindings.HTLCUpdate_write(this.ptr); + Reference.reachabilityFence(this); return ret; } - public HTLCUpdate(byte[] ser) { - super(bindings.HTLCUpdate_read(ser)); + /** + * Read a HTLCUpdate from a byte array, created by HTLCUpdate_write + */ + public static Result_HTLCUpdateDecodeErrorZ read(byte[] ser) { + long ret = bindings.HTLCUpdate_read(ser); + Reference.reachabilityFence(ser); + if (ret >= 0 && ret <= 4096) { return null; } + Result_HTLCUpdateDecodeErrorZ ret_hu_conv = Result_HTLCUpdateDecodeErrorZ.constr_from_ptr(ret); + return ret_hu_conv; } }