Update auto-updated Java files
[ldk-java] / src / main / java / org / ldk / structs / ShutdownScript.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * A script pubkey for shutting down a channel as defined by [BOLT #2].
13  * 
14  * [BOLT #2]: https://github.com/lightningnetwork/lightning-rfc/blob/master/02-peer-protocol.md
15  */
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 {
21                 super.finalize();
22                 if (ptr != 0) { bindings.ShutdownScript_free(ptr); }
23         }
24
25         long clone_ptr() {
26                 long ret = bindings.ShutdownScript_clone_ptr(this.ptr);
27                 Reference.reachabilityFence(this);
28                 return ret;
29         }
30
31         /**
32          * Creates a copy of the ShutdownScript
33          */
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                 ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ShutdownScript(null, ret); }
39                 ret_hu_conv.ptrs_to.add(this);
40                 return ret_hu_conv;
41         }
42
43         /**
44          * Serialize the ShutdownScript object into a byte array which can be read by ShutdownScript_read
45          */
46         public byte[] write() {
47                 byte[] ret = bindings.ShutdownScript_write(this.ptr);
48                 Reference.reachabilityFence(this);
49                 return ret;
50         }
51
52         /**
53          * Read a ShutdownScript from a byte array, created by ShutdownScript_write
54          */
55         public static Result_ShutdownScriptDecodeErrorZ read(byte[] ser) {
56                 long ret = bindings.ShutdownScript_read(ser);
57                 Reference.reachabilityFence(ser);
58                 if (ret >= 0 && ret <= 4096) { return null; }
59                 Result_ShutdownScriptDecodeErrorZ ret_hu_conv = Result_ShutdownScriptDecodeErrorZ.constr_from_ptr(ret);
60                 return ret_hu_conv;
61         }
62
63         /**
64          * Generates a P2WPKH script pubkey from the given [`WPubkeyHash`].
65          */
66         public static ShutdownScript new_p2wpkh(byte[] pubkey_hash) {
67                 long ret = bindings.ShutdownScript_new_p2wpkh(InternalUtils.check_arr_len(pubkey_hash, 20));
68                 Reference.reachabilityFence(pubkey_hash);
69                 if (ret >= 0 && ret <= 4096) { return null; }
70                 ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ShutdownScript(null, ret); }
71                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
72                 return ret_hu_conv;
73         }
74
75         /**
76          * Generates a P2WSH script pubkey from the given [`WScriptHash`].
77          */
78         public static ShutdownScript new_p2wsh(byte[] script_hash) {
79                 long ret = bindings.ShutdownScript_new_p2wsh(InternalUtils.check_arr_len(script_hash, 32));
80                 Reference.reachabilityFence(script_hash);
81                 if (ret >= 0 && ret <= 4096) { return null; }
82                 ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ShutdownScript(null, ret); }
83                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
84                 return ret_hu_conv;
85         }
86
87         /**
88          * Generates a witness script pubkey from the given segwit version and program.
89          * 
90          * Note for version-zero witness scripts you must use [`ShutdownScript::new_p2wpkh`] or
91          * [`ShutdownScript::new_p2wsh`] instead.
92          * 
93          * # Errors
94          * 
95          * This function may return an error if `program` is invalid for the segwit `version`.
96          */
97         public static Result_ShutdownScriptInvalidShutdownScriptZ new_witness_program(byte version, byte[] program) {
98                 long ret = bindings.ShutdownScript_new_witness_program(version, program);
99                 Reference.reachabilityFence(version);
100                 Reference.reachabilityFence(program);
101                 if (ret >= 0 && ret <= 4096) { return null; }
102                 Result_ShutdownScriptInvalidShutdownScriptZ ret_hu_conv = Result_ShutdownScriptInvalidShutdownScriptZ.constr_from_ptr(ret);
103                 return ret_hu_conv;
104         }
105
106         /**
107          * Converts the shutdown script into the underlying [`Script`].
108          */
109         public byte[] into_inner() {
110                 byte[] ret = bindings.ShutdownScript_into_inner(this.ptr);
111                 Reference.reachabilityFence(this);
112                 ;
113                 return ret;
114         }
115
116         /**
117          * Returns the [`PublicKey`] used for a P2WPKH shutdown script if constructed directly from it.
118          * 
119          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
120          */
121         @Nullable
122         public byte[] as_legacy_pubkey() {
123                 byte[] ret = bindings.ShutdownScript_as_legacy_pubkey(this.ptr);
124                 Reference.reachabilityFence(this);
125                 return ret;
126         }
127
128         /**
129          * Returns whether the shutdown script is compatible with the features as defined by BOLT #2.
130          * 
131          * Specifically, checks for compliance with feature `option_shutdown_anysegwit`.
132          */
133         public boolean is_compatible(InitFeatures features) {
134                 boolean ret = bindings.ShutdownScript_is_compatible(this.ptr, features == null ? 0 : features.ptr & ~1);
135                 Reference.reachabilityFence(this);
136                 Reference.reachabilityFence(features);
137                 this.ptrs_to.add(features);
138                 return ret;
139         }
140
141 }