1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * A [`shutdown`] message to be sent to or received from a peer.
14 * [`shutdown`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#closing-initiation-shutdown
16 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
17 public class Shutdown extends CommonBase {
18 Shutdown(Object _dummy, long ptr) { super(ptr); }
19 @Override @SuppressWarnings("deprecation")
20 protected void finalize() throws Throwable {
22 if (ptr != 0) { bindings.Shutdown_free(ptr); }
28 public byte[] get_channel_id() {
29 byte[] ret = bindings.Shutdown_get_channel_id(this.ptr);
30 Reference.reachabilityFence(this);
37 public void set_channel_id(byte[] val) {
38 bindings.Shutdown_set_channel_id(this.ptr, InternalUtils.check_arr_len(val, 32));
39 Reference.reachabilityFence(this);
40 Reference.reachabilityFence(val);
44 * The destination of this peer's funds on closing.
46 * Must be in one of these forms: P2PKH, P2SH, P2WPKH, P2WSH, P2TR.
48 public byte[] get_scriptpubkey() {
49 byte[] ret = bindings.Shutdown_get_scriptpubkey(this.ptr);
50 Reference.reachabilityFence(this);
55 * The destination of this peer's funds on closing.
57 * Must be in one of these forms: P2PKH, P2SH, P2WPKH, P2WSH, P2TR.
59 public void set_scriptpubkey(byte[] val) {
60 bindings.Shutdown_set_scriptpubkey(this.ptr, val);
61 Reference.reachabilityFence(this);
62 Reference.reachabilityFence(val);
66 * Constructs a new Shutdown given each field
68 public static Shutdown of(byte[] channel_id_arg, byte[] scriptpubkey_arg) {
69 long ret = bindings.Shutdown_new(InternalUtils.check_arr_len(channel_id_arg, 32), scriptpubkey_arg);
70 Reference.reachabilityFence(channel_id_arg);
71 Reference.reachabilityFence(scriptpubkey_arg);
72 if (ret >= 0 && ret <= 4096) { return null; }
73 org.ldk.structs.Shutdown ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Shutdown(null, ret); }
74 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
79 long ret = bindings.Shutdown_clone_ptr(this.ptr);
80 Reference.reachabilityFence(this);
85 * Creates a copy of the Shutdown
87 public Shutdown clone() {
88 long ret = bindings.Shutdown_clone(this.ptr);
89 Reference.reachabilityFence(this);
90 if (ret >= 0 && ret <= 4096) { return null; }
91 org.ldk.structs.Shutdown ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Shutdown(null, ret); }
92 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
97 * Checks if two Shutdowns contain equal inner contents.
98 * This ignores pointers and is_owned flags and looks at the values in fields.
99 * Two objects with NULL inner values will be considered "equal" here.
101 public boolean eq(org.ldk.structs.Shutdown b) {
102 boolean ret = bindings.Shutdown_eq(this.ptr, b == null ? 0 : b.ptr);
103 Reference.reachabilityFence(this);
104 Reference.reachabilityFence(b);
105 if (this != null) { this.ptrs_to.add(b); };
109 @Override public boolean equals(Object o) {
110 if (!(o instanceof Shutdown)) return false;
111 return this.eq((Shutdown)o);
114 * Serialize the Shutdown object into a byte array which can be read by Shutdown_read
116 public byte[] write() {
117 byte[] ret = bindings.Shutdown_write(this.ptr);
118 Reference.reachabilityFence(this);
123 * Read a Shutdown from a byte array, created by Shutdown_write
125 public static Result_ShutdownDecodeErrorZ read(byte[] ser) {
126 long ret = bindings.Shutdown_read(ser);
127 Reference.reachabilityFence(ser);
128 if (ret >= 0 && ret <= 4096) { return null; }
129 Result_ShutdownDecodeErrorZ ret_hu_conv = Result_ShutdownDecodeErrorZ.constr_from_ptr(ret);