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         /**
25          * Creates a copy of the ShutdownScript
26          */
27         public ShutdownScript clone() {
28                 long ret = bindings.ShutdownScript_clone(this.ptr);
29                 if (ret < 1024) { return null; }
30                 ShutdownScript ret_hu_conv = new ShutdownScript(null, ret);
31                 ret_hu_conv.ptrs_to.add(this);
32                 return ret_hu_conv;
33         }
34
35         /**
36          * Serialize the ShutdownScript object into a byte array which can be read by ShutdownScript_read
37          */
38         public byte[] write() {
39                 byte[] ret = bindings.ShutdownScript_write(this.ptr);
40                 return ret;
41         }
42
43         /**
44          * Read a ShutdownScript from a byte array, created by ShutdownScript_write
45          */
46         public static Result_ShutdownScriptDecodeErrorZ read(byte[] ser) {
47                 long ret = bindings.ShutdownScript_read(ser);
48                 if (ret < 1024) { return null; }
49                 Result_ShutdownScriptDecodeErrorZ ret_hu_conv = Result_ShutdownScriptDecodeErrorZ.constr_from_ptr(ret);
50                 return ret_hu_conv;
51         }
52
53         /**
54          * Generates a P2PKH script pubkey from the given [`PubkeyHash`].
55          */
56         public static ShutdownScript new_p2pkh(byte[] pubkey_hash) {
57                 long ret = bindings.ShutdownScript_new_p2pkh(pubkey_hash);
58                 if (ret < 1024) { return null; }
59                 ShutdownScript ret_hu_conv = new ShutdownScript(null, ret);
60                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
61                 return ret_hu_conv;
62         }
63
64         /**
65          * Generates a P2SH script pubkey from the given [`ScriptHash`].
66          */
67         public static ShutdownScript new_p2sh(byte[] script_hash) {
68                 long ret = bindings.ShutdownScript_new_p2sh(script_hash);
69                 if (ret < 1024) { return null; }
70                 ShutdownScript 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 P2WPKH script pubkey from the given [`WPubkeyHash`].
77          */
78         public static ShutdownScript new_p2wpkh(byte[] pubkey_hash) {
79                 long ret = bindings.ShutdownScript_new_p2wpkh(pubkey_hash);
80                 if (ret < 1024) { return null; }
81                 ShutdownScript ret_hu_conv = new ShutdownScript(null, ret);
82                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
83                 return ret_hu_conv;
84         }
85
86         /**
87          * Generates a P2WSH script pubkey from the given [`WScriptHash`].
88          */
89         public static ShutdownScript new_p2wsh(byte[] script_hash) {
90                 long ret = bindings.ShutdownScript_new_p2wsh(script_hash);
91                 if (ret < 1024) { return null; }
92                 ShutdownScript ret_hu_conv = new ShutdownScript(null, ret);
93                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
94                 return ret_hu_conv;
95         }
96
97         /**
98          * Generates a witness script pubkey from the given segwit version and program.
99          * 
100          * Note for version-zero witness scripts you must use [`ShutdownScript::new_p2wpkh`] or
101          * [`ShutdownScript::new_p2wsh`] instead.
102          * 
103          * # Errors
104          * 
105          * This function may return an error if `program` is invalid for the segwit `version`.
106          */
107         public static Result_ShutdownScriptInvalidShutdownScriptZ new_witness_program(byte version, byte[] program) {
108                 long ret = bindings.ShutdownScript_new_witness_program(version, program);
109                 if (ret < 1024) { return null; }
110                 Result_ShutdownScriptInvalidShutdownScriptZ ret_hu_conv = Result_ShutdownScriptInvalidShutdownScriptZ.constr_from_ptr(ret);
111                 return ret_hu_conv;
112         }
113
114         /**
115          * Converts the shutdown script into the underlying [`Script`].
116          */
117         public byte[] into_inner() {
118                 byte[] ret = bindings.ShutdownScript_into_inner(this.ptr);
119                 ;
120                 return ret;
121         }
122
123         /**
124          * Returns the [`PublicKey`] used for a P2WPKH shutdown script if constructed directly from it.
125          * 
126          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
127          */
128         @Nullable
129         public byte[] as_legacy_pubkey() {
130                 byte[] ret = bindings.ShutdownScript_as_legacy_pubkey(this.ptr);
131                 return ret;
132         }
133
134         /**
135          * Returns whether the shutdown script is compatible with the features as defined by BOLT #2.
136          * 
137          * Specifically, checks for compliance with feature `option_shutdown_anysegwit`.
138          */
139         public boolean is_compatible(InitFeatures features) {
140                 boolean ret = bindings.ShutdownScript_is_compatible(this.ptr, features == null ? 0 : features.ptr & ~1);
141                 this.ptrs_to.add(features);
142                 return ret;
143         }
144
145 }