6 namespace org { namespace ldk { namespace structs {
10 * A script pubkey for shutting down a channel as defined by [BOLT #2].
12 * [BOLT #2]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md
14 public class ShutdownScript : CommonBase {
15 internal ShutdownScript(object _dummy, long ptr) : base(ptr) { }
17 if (ptr != 0) { bindings.ShutdownScript_free(ptr); }
20 internal long clone_ptr() {
21 long ret = bindings.ShutdownScript_clone_ptr(this.ptr);
27 * Creates a copy of the ShutdownScript
29 public ShutdownScript clone() {
30 long ret = bindings.ShutdownScript_clone(this.ptr);
32 if (ret >= 0 && ret <= 4096) { return null; }
33 org.ldk.structs.ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ShutdownScript(null, ret); }
34 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
39 * Checks if two ShutdownScripts contain equal inner contents.
40 * This ignores pointers and is_owned flags and looks at the values in fields.
41 * Two objects with NULL inner values will be considered "equal" here.
43 public bool eq(org.ldk.structs.ShutdownScript b) {
44 bool ret = bindings.ShutdownScript_eq(this.ptr, b == null ? 0 : b.ptr);
47 if (this != null) { this.ptrs_to.AddLast(b); };
51 public override bool Equals(object o) {
52 if (!(o is ShutdownScript)) return false;
53 return this.eq((ShutdownScript)o);
56 * Serialize the ShutdownScript object into a byte array which can be read by ShutdownScript_read
58 public byte[] write() {
59 long ret = bindings.ShutdownScript_write(this.ptr);
61 if (ret >= 0 && ret <= 4096) { return null; }
62 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
67 * Read a ShutdownScript from a byte array, created by ShutdownScript_write
69 public static Result_ShutdownScriptDecodeErrorZ read(byte[] ser) {
70 long ret = bindings.ShutdownScript_read(InternalUtils.encodeUint8Array(ser));
72 if (ret >= 0 && ret <= 4096) { return null; }
73 Result_ShutdownScriptDecodeErrorZ ret_hu_conv = Result_ShutdownScriptDecodeErrorZ.constr_from_ptr(ret);
78 * Generates a P2WPKH script pubkey from the given [`WPubkeyHash`].
80 public static ShutdownScript new_p2wpkh(byte[] pubkey_hash) {
81 long ret = bindings.ShutdownScript_new_p2wpkh(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(pubkey_hash, 20)));
82 GC.KeepAlive(pubkey_hash);
83 if (ret >= 0 && ret <= 4096) { return null; }
84 org.ldk.structs.ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ShutdownScript(null, ret); }
85 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
90 * Generates a P2WSH script pubkey from the given [`WScriptHash`].
92 public static ShutdownScript new_p2wsh(byte[] script_hash) {
93 long ret = bindings.ShutdownScript_new_p2wsh(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(script_hash, 32)));
94 GC.KeepAlive(script_hash);
95 if (ret >= 0 && ret <= 4096) { return null; }
96 org.ldk.structs.ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ShutdownScript(null, ret); }
97 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
102 * Generates a witness script pubkey from the given segwit version and program.
104 * Note for version-zero witness scripts you must use [`ShutdownScript::new_p2wpkh`] or
105 * [`ShutdownScript::new_p2wsh`] instead.
109 * This function may return an error if `program` is invalid for the segwit `version`.
111 public static Result_ShutdownScriptInvalidShutdownScriptZ new_witness_program(org.ldk.util.WitnessVersion version, byte[] program) {
112 long ret = bindings.ShutdownScript_new_witness_program(version.getVal(), InternalUtils.encodeUint8Array(program));
113 GC.KeepAlive(version);
114 GC.KeepAlive(program);
115 if (ret >= 0 && ret <= 4096) { return null; }
116 Result_ShutdownScriptInvalidShutdownScriptZ ret_hu_conv = Result_ShutdownScriptInvalidShutdownScriptZ.constr_from_ptr(ret);
121 * Converts the shutdown script into the underlying [`Script`].
123 public byte[] into_inner() {
124 long ret = bindings.ShutdownScript_into_inner(this.ptr);
126 if (ret >= 0 && ret <= 4096) { return null; }
127 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
128 if (this != null) { this.ptrs_to.AddLast(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
137 public byte[] as_legacy_pubkey() {
138 long ret = bindings.ShutdownScript_as_legacy_pubkey(this.ptr);
140 if (ret >= 0 && ret <= 4096) { return null; }
141 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
146 * Returns whether the shutdown script is compatible with the features as defined by BOLT #2.
148 * Specifically, checks for compliance with feature `option_shutdown_anysegwit`.
150 public bool is_compatible(org.ldk.structs.InitFeatures features) {
151 bool ret = bindings.ShutdownScript_is_compatible(this.ptr, features == null ? 0 : features.ptr);
153 GC.KeepAlive(features);
154 if (this != null) { this.ptrs_to.AddLast(features); };