[Java] Update auto-generated Java bindings to LDK 0.0.121
[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/lightning/bolts/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                 org.ldk.structs.ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ShutdownScript(null, ret); }
39                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
40                 return ret_hu_conv;
41         }
42
43         /**
44          * Checks if two ShutdownScripts contain equal inner contents.
45          * This ignores pointers and is_owned flags and looks at the values in fields.
46          * Two objects with NULL inner values will be considered "equal" here.
47          */
48         public boolean eq(org.ldk.structs.ShutdownScript b) {
49                 boolean ret = bindings.ShutdownScript_eq(this.ptr, b == null ? 0 : b.ptr);
50                 Reference.reachabilityFence(this);
51                 Reference.reachabilityFence(b);
52                 if (this != null) { this.ptrs_to.add(b); };
53                 return ret;
54         }
55
56         @Override public boolean equals(Object o) {
57                 if (!(o instanceof ShutdownScript)) return false;
58                 return this.eq((ShutdownScript)o);
59         }
60         /**
61          * Serialize the ShutdownScript object into a byte array which can be read by ShutdownScript_read
62          */
63         public byte[] write() {
64                 byte[] ret = bindings.ShutdownScript_write(this.ptr);
65                 Reference.reachabilityFence(this);
66                 return ret;
67         }
68
69         /**
70          * Read a ShutdownScript from a byte array, created by ShutdownScript_write
71          */
72         public static Result_ShutdownScriptDecodeErrorZ read(byte[] ser) {
73                 long ret = bindings.ShutdownScript_read(ser);
74                 Reference.reachabilityFence(ser);
75                 if (ret >= 0 && ret <= 4096) { return null; }
76                 Result_ShutdownScriptDecodeErrorZ ret_hu_conv = Result_ShutdownScriptDecodeErrorZ.constr_from_ptr(ret);
77                 return ret_hu_conv;
78         }
79
80         /**
81          * Generates a P2WPKH script pubkey from the given [`WPubkeyHash`].
82          */
83         public static ShutdownScript new_p2wpkh(byte[] pubkey_hash) {
84                 long ret = bindings.ShutdownScript_new_p2wpkh(InternalUtils.check_arr_len(pubkey_hash, 20));
85                 Reference.reachabilityFence(pubkey_hash);
86                 if (ret >= 0 && ret <= 4096) { return null; }
87                 org.ldk.structs.ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ShutdownScript(null, ret); }
88                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
89                 return ret_hu_conv;
90         }
91
92         /**
93          * Generates a P2WSH script pubkey from the given [`WScriptHash`].
94          */
95         public static ShutdownScript new_p2wsh(byte[] script_hash) {
96                 long ret = bindings.ShutdownScript_new_p2wsh(InternalUtils.check_arr_len(script_hash, 32));
97                 Reference.reachabilityFence(script_hash);
98                 if (ret >= 0 && ret <= 4096) { return null; }
99                 org.ldk.structs.ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ShutdownScript(null, ret); }
100                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
101                 return ret_hu_conv;
102         }
103
104         /**
105          * Generates a witness script pubkey from the given segwit version and program.
106          * 
107          * Note for version-zero witness scripts you must use [`ShutdownScript::new_p2wpkh`] or
108          * [`ShutdownScript::new_p2wsh`] instead.
109          * 
110          * # Errors
111          * 
112          * This function may return an error if `program` is invalid for the segwit `version`.
113          */
114         public static Result_ShutdownScriptInvalidShutdownScriptZ new_witness_program(org.ldk.structs.WitnessProgram witness_program) {
115                 long ret = bindings.ShutdownScript_new_witness_program(witness_program.ptr);
116                 Reference.reachabilityFence(witness_program);
117                 if (ret >= 0 && ret <= 4096) { return null; }
118                 Result_ShutdownScriptInvalidShutdownScriptZ ret_hu_conv = Result_ShutdownScriptInvalidShutdownScriptZ.constr_from_ptr(ret);
119                 return ret_hu_conv;
120         }
121
122         /**
123          * Converts the shutdown script into the underlying [`ScriptBuf`].
124          */
125         public byte[] into_inner() {
126                 byte[] ret = bindings.ShutdownScript_into_inner(this.ptr);
127                 Reference.reachabilityFence(this);
128                 if (this != null) { this.ptrs_to.add(this); };
129                 return ret;
130         }
131
132         /**
133          * Returns the [`PublicKey`] used for a P2WPKH shutdown script if constructed directly from it.
134          * 
135          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
136          */
137         @Nullable
138         public byte[] as_legacy_pubkey() {
139                 byte[] ret = bindings.ShutdownScript_as_legacy_pubkey(this.ptr);
140                 Reference.reachabilityFence(this);
141                 return ret;
142         }
143
144         /**
145          * Returns whether the shutdown script is compatible with the features as defined by BOLT #2.
146          * 
147          * Specifically, checks for compliance with feature `option_shutdown_anysegwit`.
148          */
149         public boolean is_compatible(org.ldk.structs.InitFeatures features) {
150                 boolean ret = bindings.ShutdownScript_is_compatible(this.ptr, features == null ? 0 : features.ptr);
151                 Reference.reachabilityFence(this);
152                 Reference.reachabilityFence(features);
153                 if (this != null) { this.ptrs_to.add(features); };
154                 return ret;
155         }
156
157 }