[C#] Update auto-generated C# bindings
[ldk-java] / c_sharp / src / org / ldk / structs / ShutdownScript.cs
1 using org.ldk.impl;
2 using org.ldk.enums;
3 using org.ldk.util;
4 using System;
5
6 namespace org { namespace ldk { namespace structs {
7
8
9 /**
10  * A script pubkey for shutting down a channel as defined by [BOLT #2].
11  * 
12  * [BOLT #2]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md
13  */
14 public class ShutdownScript : CommonBase {
15         internal ShutdownScript(object _dummy, long ptr) : base(ptr) { }
16         ~ShutdownScript() {
17                 if (ptr != 0) { bindings.ShutdownScript_free(ptr); }
18         }
19
20         internal long clone_ptr() {
21                 long ret = bindings.ShutdownScript_clone_ptr(this.ptr);
22                 GC.KeepAlive(this);
23                 return ret;
24         }
25
26         /**
27          * Creates a copy of the ShutdownScript
28          */
29         public ShutdownScript clone() {
30                 long ret = bindings.ShutdownScript_clone(this.ptr);
31                 GC.KeepAlive(this);
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); };
35                 return ret_hu_conv;
36         }
37
38         /**
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.
42          */
43         public bool eq(org.ldk.structs.ShutdownScript b) {
44                 bool ret = bindings.ShutdownScript_eq(this.ptr, b == null ? 0 : b.ptr);
45                 GC.KeepAlive(this);
46                 GC.KeepAlive(b);
47                 if (this != null) { this.ptrs_to.AddLast(b); };
48                 return ret;
49         }
50
51         public override bool Equals(object o) {
52                 if (!(o is ShutdownScript)) return false;
53                 return this.eq((ShutdownScript)o);
54         }
55         /**
56          * Serialize the ShutdownScript object into a byte array which can be read by ShutdownScript_read
57          */
58         public byte[] write() {
59                 long ret = bindings.ShutdownScript_write(this.ptr);
60                 GC.KeepAlive(this);
61                 if (ret >= 0 && ret <= 4096) { return null; }
62                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
63                 return ret_conv;
64         }
65
66         /**
67          * Read a ShutdownScript from a byte array, created by ShutdownScript_write
68          */
69         public static Result_ShutdownScriptDecodeErrorZ read(byte[] ser) {
70                 long ret = bindings.ShutdownScript_read(InternalUtils.encodeUint8Array(ser));
71                 GC.KeepAlive(ser);
72                 if (ret >= 0 && ret <= 4096) { return null; }
73                 Result_ShutdownScriptDecodeErrorZ ret_hu_conv = Result_ShutdownScriptDecodeErrorZ.constr_from_ptr(ret);
74                 return ret_hu_conv;
75         }
76
77         /**
78          * Generates a P2WPKH script pubkey from the given [`WPubkeyHash`].
79          */
80         public static ShutdownScript new_p2wpkh(byte[] pubkey_hash) {
81                 long ret = bindings.ShutdownScript_new_p2wpkh(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(pubkey_hash, 20)));
82                 GC.KeepAlive(pubkey_hash);
83                 if (ret >= 0 && ret <= 4096) { return null; }
84                 org.ldk.structs.ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ShutdownScript(null, ret); }
85                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
86                 return ret_hu_conv;
87         }
88
89         /**
90          * Generates a P2WSH script pubkey from the given [`WScriptHash`].
91          */
92         public static ShutdownScript new_p2wsh(byte[] script_hash) {
93                 long ret = bindings.ShutdownScript_new_p2wsh(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(script_hash, 32)));
94                 GC.KeepAlive(script_hash);
95                 if (ret >= 0 && ret <= 4096) { return null; }
96                 org.ldk.structs.ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ShutdownScript(null, ret); }
97                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
98                 return ret_hu_conv;
99         }
100
101         /**
102          * Generates a witness script pubkey from the given segwit version and program.
103          * 
104          * Note for version-zero witness scripts you must use [`ShutdownScript::new_p2wpkh`] or
105          * [`ShutdownScript::new_p2wsh`] instead.
106          * 
107          * # Errors
108          * 
109          * This function may return an error if `program` is invalid for the segwit `version`.
110          */
111         public static Result_ShutdownScriptInvalidShutdownScriptZ new_witness_program(org.ldk.structs.WitnessProgram witness_program) {
112                 long ret = bindings.ShutdownScript_new_witness_program(witness_program.ptr);
113                 GC.KeepAlive(witness_program);
114                 if (ret >= 0 && ret <= 4096) { return null; }
115                 Result_ShutdownScriptInvalidShutdownScriptZ ret_hu_conv = Result_ShutdownScriptInvalidShutdownScriptZ.constr_from_ptr(ret);
116                 return ret_hu_conv;
117         }
118
119         /**
120          * Converts the shutdown script into the underlying [`ScriptBuf`].
121          */
122         public byte[] into_inner() {
123                 long ret = bindings.ShutdownScript_into_inner(this.ptr);
124                 GC.KeepAlive(this);
125                 if (ret >= 0 && ret <= 4096) { return null; }
126                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
127                 if (this != null) { this.ptrs_to.AddLast(this); };
128                 return ret_conv;
129         }
130
131         /**
132          * Returns the [`PublicKey`] used for a P2WPKH shutdown script if constructed directly from it.
133          * 
134          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
135          */
136         public byte[] as_legacy_pubkey() {
137                 long ret = bindings.ShutdownScript_as_legacy_pubkey(this.ptr);
138                 GC.KeepAlive(this);
139                 if (ret >= 0 && ret <= 4096) { return null; }
140                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
141                 return ret_conv;
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 bool is_compatible(org.ldk.structs.InitFeatures features) {
150                 bool ret = bindings.ShutdownScript_is_compatible(this.ptr, features == null ? 0 : features.ptr);
151                 GC.KeepAlive(this);
152                 GC.KeepAlive(features);
153                 if (this != null) { this.ptrs_to.AddLast(features); };
154                 return ret;
155         }
156
157 }
158 } } }