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