1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * A script pubkey for shutting down a channel as defined by [BOLT #2].
14 * [BOLT #2]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md
16 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
17 public class ShutdownScript extends CommonBase {
18 ShutdownScript(Object _dummy, long ptr) { super(ptr); }
19 @Override @SuppressWarnings("deprecation")
20 protected void finalize() throws Throwable {
22 if (ptr != 0) { bindings.ShutdownScript_free(ptr); }
26 long ret = bindings.ShutdownScript_clone_ptr(this.ptr);
27 Reference.reachabilityFence(this);
32 * Creates a copy of the ShutdownScript
34 public ShutdownScript clone() {
35 long ret = bindings.ShutdownScript_clone(this.ptr);
36 Reference.reachabilityFence(this);
37 if (ret >= 0 && ret <= 4096) { return null; }
38 org.ldk.structs.ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ShutdownScript(null, ret); }
39 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
44 * Checks if two ShutdownScripts contain equal inner contents.
45 * This ignores pointers and is_owned flags and looks at the values in fields.
46 * Two objects with NULL inner values will be considered "equal" here.
48 public boolean eq(org.ldk.structs.ShutdownScript b) {
49 boolean ret = bindings.ShutdownScript_eq(this.ptr, b == null ? 0 : b.ptr);
50 Reference.reachabilityFence(this);
51 Reference.reachabilityFence(b);
52 if (this != null) { this.ptrs_to.add(b); };
56 @Override public boolean equals(Object o) {
57 if (!(o instanceof ShutdownScript)) return false;
58 return this.eq((ShutdownScript)o);
61 * Serialize the ShutdownScript object into a byte array which can be read by ShutdownScript_read
63 public byte[] write() {
64 byte[] ret = bindings.ShutdownScript_write(this.ptr);
65 Reference.reachabilityFence(this);
70 * Read a ShutdownScript from a byte array, created by ShutdownScript_write
72 public static Result_ShutdownScriptDecodeErrorZ read(byte[] ser) {
73 long ret = bindings.ShutdownScript_read(ser);
74 Reference.reachabilityFence(ser);
75 if (ret >= 0 && ret <= 4096) { return null; }
76 Result_ShutdownScriptDecodeErrorZ ret_hu_conv = Result_ShutdownScriptDecodeErrorZ.constr_from_ptr(ret);
81 * Generates a P2WPKH script pubkey from the given [`WPubkeyHash`].
83 public static ShutdownScript new_p2wpkh(byte[] pubkey_hash) {
84 long ret = bindings.ShutdownScript_new_p2wpkh(InternalUtils.check_arr_len(pubkey_hash, 20));
85 Reference.reachabilityFence(pubkey_hash);
86 if (ret >= 0 && ret <= 4096) { return null; }
87 org.ldk.structs.ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ShutdownScript(null, ret); }
88 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
93 * Generates a P2WSH script pubkey from the given [`WScriptHash`].
95 public static ShutdownScript new_p2wsh(byte[] script_hash) {
96 long ret = bindings.ShutdownScript_new_p2wsh(InternalUtils.check_arr_len(script_hash, 32));
97 Reference.reachabilityFence(script_hash);
98 if (ret >= 0 && ret <= 4096) { return null; }
99 org.ldk.structs.ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ShutdownScript(null, ret); }
100 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
105 * Generates a witness script pubkey from the given segwit version and program.
107 * Note for version-zero witness scripts you must use [`ShutdownScript::new_p2wpkh`] or
108 * [`ShutdownScript::new_p2wsh`] instead.
112 * This function may return an error if `program` is invalid for the segwit `version`.
114 public static Result_ShutdownScriptInvalidShutdownScriptZ new_witness_program(org.ldk.structs.WitnessProgram witness_program) {
115 long ret = bindings.ShutdownScript_new_witness_program(witness_program.ptr);
116 Reference.reachabilityFence(witness_program);
117 if (ret >= 0 && ret <= 4096) { return null; }
118 Result_ShutdownScriptInvalidShutdownScriptZ ret_hu_conv = Result_ShutdownScriptInvalidShutdownScriptZ.constr_from_ptr(ret);
123 * Converts the shutdown script into the underlying [`ScriptBuf`].
125 public byte[] into_inner() {
126 byte[] ret = bindings.ShutdownScript_into_inner(this.ptr);
127 Reference.reachabilityFence(this);
128 if (this != null) { this.ptrs_to.add(this); };
133 * Returns the [`PublicKey`] used for a P2WPKH shutdown script if constructed directly from it.
135 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
138 public byte[] as_legacy_pubkey() {
139 byte[] ret = bindings.ShutdownScript_as_legacy_pubkey(this.ptr);
140 Reference.reachabilityFence(this);
145 * Returns whether the shutdown script is compatible with the features as defined by BOLT #2.
147 * Specifically, checks for compliance with feature `option_shutdown_anysegwit`.
149 public boolean is_compatible(org.ldk.structs.InitFeatures features) {
150 boolean ret = bindings.ShutdownScript_is_compatible(this.ptr, features == null ? 0 : features.ptr);
151 Reference.reachabilityFence(this);
152 Reference.reachabilityFence(features);
153 if (this != null) { this.ptrs_to.add(features); };