[C#] Check in initial 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                 byte[] ret = bindings.ShutdownScript_write(this.ptr);
60                 GC.KeepAlive(this);
61                 return ret;
62         }
63
64         /**
65          * Read a ShutdownScript from a byte array, created by ShutdownScript_write
66          */
67         public static Result_ShutdownScriptDecodeErrorZ read(byte[] ser) {
68                 long ret = bindings.ShutdownScript_read(ser);
69                 GC.KeepAlive(ser);
70                 if (ret >= 0 && ret <= 4096) { return null; }
71                 Result_ShutdownScriptDecodeErrorZ ret_hu_conv = Result_ShutdownScriptDecodeErrorZ.constr_from_ptr(ret);
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(InternalUtils.check_arr_len(pubkey_hash, 20));
80                 GC.KeepAlive(pubkey_hash);
81                 if (ret >= 0 && ret <= 4096) { return null; }
82                 org.ldk.structs.ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ShutdownScript(null, ret); }
83                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
84                 return ret_hu_conv;
85         }
86
87         /**
88          * Generates a P2WSH script pubkey from the given [`WScriptHash`].
89          */
90         public static ShutdownScript new_p2wsh(byte[] script_hash) {
91                 long ret = bindings.ShutdownScript_new_p2wsh(InternalUtils.check_arr_len(script_hash, 32));
92                 GC.KeepAlive(script_hash);
93                 if (ret >= 0 && ret <= 4096) { return null; }
94                 org.ldk.structs.ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ShutdownScript(null, ret); }
95                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
96                 return ret_hu_conv;
97         }
98
99         /**
100          * Generates a witness script pubkey from the given segwit version and program.
101          * 
102          * Note for version-zero witness scripts you must use [`ShutdownScript::new_p2wpkh`] or
103          * [`ShutdownScript::new_p2wsh`] instead.
104          * 
105          * # Errors
106          * 
107          * This function may return an error if `program` is invalid for the segwit `version`.
108          */
109         public static Result_ShutdownScriptInvalidShutdownScriptZ new_witness_program(org.ldk.util.WitnessVersion version, byte[] program) {
110                 long ret = bindings.ShutdownScript_new_witness_program(version.getVal(), program);
111                 GC.KeepAlive(version);
112                 GC.KeepAlive(program);
113                 if (ret >= 0 && ret <= 4096) { return null; }
114                 Result_ShutdownScriptInvalidShutdownScriptZ ret_hu_conv = Result_ShutdownScriptInvalidShutdownScriptZ.constr_from_ptr(ret);
115                 return ret_hu_conv;
116         }
117
118         /**
119          * Converts the shutdown script into the underlying [`Script`].
120          */
121         public byte[] into_inner() {
122                 byte[] ret = bindings.ShutdownScript_into_inner(this.ptr);
123                 GC.KeepAlive(this);
124                 if (this != null) { this.ptrs_to.AddLast(this); };
125                 return ret;
126         }
127
128         /**
129          * Returns the [`PublicKey`] used for a P2WPKH shutdown script if constructed directly from it.
130          * 
131          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
132          */
133         public byte[] as_legacy_pubkey() {
134                 byte[] ret = bindings.ShutdownScript_as_legacy_pubkey(this.ptr);
135                 GC.KeepAlive(this);
136                 return ret;
137         }
138
139         /**
140          * Returns whether the shutdown script is compatible with the features as defined by BOLT #2.
141          * 
142          * Specifically, checks for compliance with feature `option_shutdown_anysegwit`.
143          */
144         public bool is_compatible(org.ldk.structs.InitFeatures features) {
145                 bool ret = bindings.ShutdownScript_is_compatible(this.ptr, features == null ? 0 : features.ptr);
146                 GC.KeepAlive(this);
147                 GC.KeepAlive(features);
148                 if (this != null) { this.ptrs_to.AddLast(features); };
149                 return ret;
150         }
151
152 }
153 } } }