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 byte[] ret = bindings.ShutdownScript_write(this.ptr);
65 * Read a ShutdownScript from a byte array, created by ShutdownScript_write
67 public static Result_ShutdownScriptDecodeErrorZ read(byte[] ser) {
68 long ret = bindings.ShutdownScript_read(ser);
70 if (ret >= 0 && ret <= 4096) { return null; }
71 Result_ShutdownScriptDecodeErrorZ ret_hu_conv = Result_ShutdownScriptDecodeErrorZ.constr_from_ptr(ret);
76 * Generates a P2WPKH script pubkey from the given [`WPubkeyHash`].
78 public static ShutdownScript new_p2wpkh(byte[] pubkey_hash) {
79 long ret = bindings.ShutdownScript_new_p2wpkh(InternalUtils.check_arr_len(pubkey_hash, 20));
80 GC.KeepAlive(pubkey_hash);
81 if (ret >= 0 && ret <= 4096) { return null; }
82 org.ldk.structs.ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ShutdownScript(null, ret); }
83 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
88 * Generates a P2WSH script pubkey from the given [`WScriptHash`].
90 public static ShutdownScript new_p2wsh(byte[] script_hash) {
91 long ret = bindings.ShutdownScript_new_p2wsh(InternalUtils.check_arr_len(script_hash, 32));
92 GC.KeepAlive(script_hash);
93 if (ret >= 0 && ret <= 4096) { return null; }
94 org.ldk.structs.ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ShutdownScript(null, ret); }
95 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
100 * Generates a witness script pubkey from the given segwit version and program.
102 * Note for version-zero witness scripts you must use [`ShutdownScript::new_p2wpkh`] or
103 * [`ShutdownScript::new_p2wsh`] instead.
107 * This function may return an error if `program` is invalid for the segwit `version`.
109 public static Result_ShutdownScriptInvalidShutdownScriptZ new_witness_program(org.ldk.util.WitnessVersion version, byte[] program) {
110 long ret = bindings.ShutdownScript_new_witness_program(version.getVal(), program);
111 GC.KeepAlive(version);
112 GC.KeepAlive(program);
113 if (ret >= 0 && ret <= 4096) { return null; }
114 Result_ShutdownScriptInvalidShutdownScriptZ ret_hu_conv = Result_ShutdownScriptInvalidShutdownScriptZ.constr_from_ptr(ret);
119 * Converts the shutdown script into the underlying [`Script`].
121 public byte[] into_inner() {
122 byte[] ret = bindings.ShutdownScript_into_inner(this.ptr);
124 if (this != null) { this.ptrs_to.AddLast(this); };
129 * Returns the [`PublicKey`] used for a P2WPKH shutdown script if constructed directly from it.
131 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
133 public byte[] as_legacy_pubkey() {
134 byte[] ret = bindings.ShutdownScript_as_legacy_pubkey(this.ptr);
140 * Returns whether the shutdown script is compatible with the features as defined by BOLT #2.
142 * Specifically, checks for compliance with feature `option_shutdown_anysegwit`.
144 public bool is_compatible(org.ldk.structs.InitFeatures features) {
145 bool ret = bindings.ShutdownScript_is_compatible(this.ptr, features == null ? 0 : features.ptr);
147 GC.KeepAlive(features);
148 if (this != null) { this.ptrs_to.AddLast(features); };