X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FWatchedOutput.java;h=f745678a41efa5fb4f86638ca66a5c87778a566c;hb=890e35a4387758c0447aab34166caa579bbf3a08;hp=e8c4f8654abf2413b4455be4f7031650b70cc6a0;hpb=c3ae2d6897e5a809459c8d9a72a4b3aa0052c8c8;p=ldk-java diff --git a/src/main/java/org/ldk/structs/WatchedOutput.java b/src/main/java/org/ldk/structs/WatchedOutput.java index e8c4f865..f745678a 100644 --- a/src/main/java/org/ldk/structs/WatchedOutput.java +++ b/src/main/java/org/ldk/structs/WatchedOutput.java @@ -4,6 +4,8 @@ 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; /** @@ -11,7 +13,7 @@ import java.util.Arrays; * * Used to convey to a [`Filter`] such an output with a given spending condition. Any transaction * spending the output must be given to [`ChannelMonitor::block_connected`] either directly or via - * the return value of [`Filter::register_output`]. + * [`Confirm::transactions_confirmed`]. * * If `block_hash` is `Some`, this indicates the output was created in the corresponding block and * may have been spent there. See [`Filter::register_output`] for details. @@ -30,17 +32,25 @@ public class WatchedOutput extends CommonBase { /** * First block where the transaction output may have been spent. + * + * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None */ + @Nullable public byte[] get_block_hash() { byte[] ret = bindings.WatchedOutput_get_block_hash(this.ptr); + Reference.reachabilityFence(this); return ret; } /** * First block where the transaction output may have been spent. + * + * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None */ - public void set_block_hash(byte[] val) { - bindings.WatchedOutput_set_block_hash(this.ptr, val); + public void set_block_hash(@Nullable byte[] val) { + bindings.WatchedOutput_set_block_hash(this.ptr, InternalUtils.check_arr_len(val, 32)); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); } /** @@ -48,8 +58,10 @@ public class WatchedOutput extends CommonBase { */ public OutPoint get_outpoint() { long ret = bindings.WatchedOutput_get_outpoint(this.ptr); - OutPoint ret_hu_conv = new OutPoint(null, ret); - ret_hu_conv.ptrs_to.add(this); + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.OutPoint ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OutPoint(null, ret); } + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; return ret_hu_conv; } @@ -57,8 +69,10 @@ public class WatchedOutput extends CommonBase { * Outpoint identifying the transaction output. */ public void set_outpoint(OutPoint val) { - bindings.WatchedOutput_set_outpoint(this.ptr, val == null ? 0 : val.ptr & ~1); - this.ptrs_to.add(val); + bindings.WatchedOutput_set_outpoint(this.ptr, val == null ? 0 : val.ptr); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); + if (this != null) { this.ptrs_to.add(val); }; } /** @@ -66,6 +80,7 @@ public class WatchedOutput extends CommonBase { */ public byte[] get_script_pubkey() { byte[] ret = bindings.WatchedOutput_get_script_pubkey(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -74,17 +89,53 @@ public class WatchedOutput extends CommonBase { */ public void set_script_pubkey(byte[] val) { bindings.WatchedOutput_set_script_pubkey(this.ptr, val); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); } /** * Constructs a new WatchedOutput given each field */ - public static WatchedOutput constructor_new(byte[] block_hash_arg, OutPoint outpoint_arg, byte[] script_pubkey_arg) { - long ret = bindings.WatchedOutput_new(block_hash_arg, outpoint_arg == null ? 0 : outpoint_arg.ptr & ~1, script_pubkey_arg); - WatchedOutput ret_hu_conv = new WatchedOutput(null, ret); - ret_hu_conv.ptrs_to.add(ret_hu_conv); - ret_hu_conv.ptrs_to.add(outpoint_arg); + public static WatchedOutput of(byte[] block_hash_arg, OutPoint outpoint_arg, byte[] script_pubkey_arg) { + long ret = bindings.WatchedOutput_new(InternalUtils.check_arr_len(block_hash_arg, 32), outpoint_arg == null ? 0 : outpoint_arg.ptr, script_pubkey_arg); + Reference.reachabilityFence(block_hash_arg); + Reference.reachabilityFence(outpoint_arg); + Reference.reachabilityFence(script_pubkey_arg); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.WatchedOutput ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.WatchedOutput(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(outpoint_arg); }; return ret_hu_conv; } + long clone_ptr() { + long ret = bindings.WatchedOutput_clone_ptr(this.ptr); + Reference.reachabilityFence(this); + return ret; + } + + /** + * Creates a copy of the WatchedOutput + */ + public WatchedOutput clone() { + long ret = bindings.WatchedOutput_clone(this.ptr); + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.WatchedOutput ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.WatchedOutput(null, ret); } + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; + return ret_hu_conv; + } + + /** + * Checks if two WatchedOutputs contain equal inner contents. + */ + public long hash() { + long ret = bindings.WatchedOutput_hash(this.ptr); + Reference.reachabilityFence(this); + return ret; + } + + @Override public int hashCode() { + return (int)this.hash(); + } }