X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FShutdownScript.java;h=c40b2b77a564f3e17e045aec3ebd5bc9e54655e5;hb=890e35a4387758c0447aab34166caa579bbf3a08;hp=f6343a16847dd115c0322482a96f613ed00d8cd7;hpb=9d146759e11191b55130be7a1b6988d3f289a168;p=ldk-java diff --git a/src/main/java/org/ldk/structs/ShutdownScript.java b/src/main/java/org/ldk/structs/ShutdownScript.java index f6343a16..c40b2b77 100644 --- a/src/main/java/org/ldk/structs/ShutdownScript.java +++ b/src/main/java/org/ldk/structs/ShutdownScript.java @@ -4,13 +4,14 @@ 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 script pubkey for shutting down a channel as defined by [BOLT #2]. * - * [BOLT #2]: https://github.com/lightningnetwork/lightning-rfc/blob/master/02-peer-protocol.md + * [BOLT #2]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md */ @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class ShutdownScript extends CommonBase { @@ -21,14 +22,21 @@ public class ShutdownScript extends CommonBase { if (ptr != 0) { bindings.ShutdownScript_free(ptr); } } + long clone_ptr() { + long ret = bindings.ShutdownScript_clone_ptr(this.ptr); + Reference.reachabilityFence(this); + return ret; + } + /** * Creates a copy of the ShutdownScript */ public ShutdownScript clone() { long ret = bindings.ShutdownScript_clone(this.ptr); - if (ret < 1024) { return null; } - ShutdownScript ret_hu_conv = new ShutdownScript(null, ret); - ret_hu_conv.ptrs_to.add(this); + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ShutdownScript(null, ret); } + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; return ret_hu_conv; } @@ -37,6 +45,7 @@ public class ShutdownScript extends CommonBase { */ public byte[] write() { byte[] ret = bindings.ShutdownScript_write(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -45,41 +54,21 @@ public class ShutdownScript extends CommonBase { */ public static Result_ShutdownScriptDecodeErrorZ read(byte[] ser) { long ret = bindings.ShutdownScript_read(ser); - if (ret < 1024) { return null; } + Reference.reachabilityFence(ser); + if (ret >= 0 && ret <= 4096) { return null; } Result_ShutdownScriptDecodeErrorZ ret_hu_conv = Result_ShutdownScriptDecodeErrorZ.constr_from_ptr(ret); return ret_hu_conv; } - /** - * Generates a P2PKH script pubkey from the given [`PubkeyHash`]. - */ - public static ShutdownScript new_p2pkh(byte[] pubkey_hash) { - long ret = bindings.ShutdownScript_new_p2pkh(pubkey_hash); - if (ret < 1024) { return null; } - ShutdownScript ret_hu_conv = new ShutdownScript(null, ret); - ret_hu_conv.ptrs_to.add(ret_hu_conv); - return ret_hu_conv; - } - - /** - * Generates a P2SH script pubkey from the given [`ScriptHash`]. - */ - public static ShutdownScript new_p2sh(byte[] script_hash) { - long ret = bindings.ShutdownScript_new_p2sh(script_hash); - if (ret < 1024) { return null; } - ShutdownScript ret_hu_conv = new ShutdownScript(null, ret); - ret_hu_conv.ptrs_to.add(ret_hu_conv); - return ret_hu_conv; - } - /** * Generates a P2WPKH script pubkey from the given [`WPubkeyHash`]. */ public static ShutdownScript new_p2wpkh(byte[] pubkey_hash) { - long ret = bindings.ShutdownScript_new_p2wpkh(pubkey_hash); - if (ret < 1024) { return null; } - ShutdownScript ret_hu_conv = new ShutdownScript(null, ret); - ret_hu_conv.ptrs_to.add(ret_hu_conv); + long ret = bindings.ShutdownScript_new_p2wpkh(InternalUtils.check_arr_len(pubkey_hash, 20)); + Reference.reachabilityFence(pubkey_hash); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ShutdownScript(null, ret); } + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; return ret_hu_conv; } @@ -87,10 +76,11 @@ public class ShutdownScript extends CommonBase { * Generates a P2WSH script pubkey from the given [`WScriptHash`]. */ public static ShutdownScript new_p2wsh(byte[] script_hash) { - long ret = bindings.ShutdownScript_new_p2wsh(script_hash); - if (ret < 1024) { return null; } - ShutdownScript ret_hu_conv = new ShutdownScript(null, ret); - ret_hu_conv.ptrs_to.add(ret_hu_conv); + long ret = bindings.ShutdownScript_new_p2wsh(InternalUtils.check_arr_len(script_hash, 32)); + Reference.reachabilityFence(script_hash); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ShutdownScript(null, ret); } + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; return ret_hu_conv; } @@ -104,9 +94,11 @@ public class ShutdownScript extends CommonBase { * * This function may return an error if `program` is invalid for the segwit `version`. */ - public static Result_ShutdownScriptInvalidShutdownScriptZ new_witness_program(byte version, byte[] program) { - long ret = bindings.ShutdownScript_new_witness_program(version, program); - if (ret < 1024) { return null; } + public static Result_ShutdownScriptInvalidShutdownScriptZ new_witness_program(WitnessVersion version, byte[] program) { + long ret = bindings.ShutdownScript_new_witness_program(version.getVal(), program); + Reference.reachabilityFence(version); + Reference.reachabilityFence(program); + if (ret >= 0 && ret <= 4096) { return null; } Result_ShutdownScriptInvalidShutdownScriptZ ret_hu_conv = Result_ShutdownScriptInvalidShutdownScriptZ.constr_from_ptr(ret); return ret_hu_conv; } @@ -116,7 +108,8 @@ public class ShutdownScript extends CommonBase { */ public byte[] into_inner() { byte[] ret = bindings.ShutdownScript_into_inner(this.ptr); - ; + Reference.reachabilityFence(this); + if (this != null) { this.ptrs_to.add(this); }; return ret; } @@ -128,6 +121,7 @@ public class ShutdownScript extends CommonBase { @Nullable public byte[] as_legacy_pubkey() { byte[] ret = bindings.ShutdownScript_as_legacy_pubkey(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -137,8 +131,10 @@ public class ShutdownScript extends CommonBase { * Specifically, checks for compliance with feature `option_shutdown_anysegwit`. */ public boolean is_compatible(InitFeatures features) { - boolean ret = bindings.ShutdownScript_is_compatible(this.ptr, features == null ? 0 : features.ptr & ~1); - this.ptrs_to.add(features); + boolean ret = bindings.ShutdownScript_is_compatible(this.ptr, features == null ? 0 : features.ptr); + Reference.reachabilityFence(this); + Reference.reachabilityFence(features); + if (this != null) { this.ptrs_to.add(features); }; return ret; }