95364b2ca77f32354ce9b2c8319d01e95f50654b
[ldk-java] / src / main / java / org / ldk / structs / ChannelReady.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 [`channel_ready`] message to be sent to or received from a peer.
13  * 
14  * [`channel_ready`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-channel_ready-message
15  */
16 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
17 public class ChannelReady extends CommonBase {
18         ChannelReady(Object _dummy, long ptr) { super(ptr); }
19         @Override @SuppressWarnings("deprecation")
20         protected void finalize() throws Throwable {
21                 super.finalize();
22                 if (ptr != 0) { bindings.ChannelReady_free(ptr); }
23         }
24
25         /**
26          * The channel ID
27          */
28         public ChannelId get_channel_id() {
29                 long ret = bindings.ChannelReady_get_channel_id(this.ptr);
30                 Reference.reachabilityFence(this);
31                 if (ret >= 0 && ret <= 4096) { return null; }
32                 org.ldk.structs.ChannelId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelId(null, ret); }
33                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
34                 return ret_hu_conv;
35         }
36
37         /**
38          * The channel ID
39          */
40         public void set_channel_id(org.ldk.structs.ChannelId val) {
41                 bindings.ChannelReady_set_channel_id(this.ptr, val.ptr);
42                 Reference.reachabilityFence(this);
43                 Reference.reachabilityFence(val);
44                 if (this != null) { this.ptrs_to.add(val); };
45         }
46
47         /**
48          * The per-commitment point of the second commitment transaction
49          */
50         public byte[] get_next_per_commitment_point() {
51                 byte[] ret = bindings.ChannelReady_get_next_per_commitment_point(this.ptr);
52                 Reference.reachabilityFence(this);
53                 return ret;
54         }
55
56         /**
57          * The per-commitment point of the second commitment transaction
58          */
59         public void set_next_per_commitment_point(byte[] val) {
60                 bindings.ChannelReady_set_next_per_commitment_point(this.ptr, InternalUtils.check_arr_len(val, 33));
61                 Reference.reachabilityFence(this);
62                 Reference.reachabilityFence(val);
63         }
64
65         /**
66          * If set, provides a `short_channel_id` alias for this channel.
67          * 
68          * The sender will accept payments to be forwarded over this SCID and forward them to this
69          * messages' recipient.
70          */
71         public Option_u64Z get_short_channel_id_alias() {
72                 long ret = bindings.ChannelReady_get_short_channel_id_alias(this.ptr);
73                 Reference.reachabilityFence(this);
74                 if (ret >= 0 && ret <= 4096) { return null; }
75                 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
76                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
77                 return ret_hu_conv;
78         }
79
80         /**
81          * If set, provides a `short_channel_id` alias for this channel.
82          * 
83          * The sender will accept payments to be forwarded over this SCID and forward them to this
84          * messages' recipient.
85          */
86         public void set_short_channel_id_alias(org.ldk.structs.Option_u64Z val) {
87                 bindings.ChannelReady_set_short_channel_id_alias(this.ptr, val.ptr);
88                 Reference.reachabilityFence(this);
89                 Reference.reachabilityFence(val);
90                 if (this != null) { this.ptrs_to.add(val); };
91         }
92
93         /**
94          * Constructs a new ChannelReady given each field
95          */
96         public static ChannelReady of(org.ldk.structs.ChannelId channel_id_arg, byte[] next_per_commitment_point_arg, org.ldk.structs.Option_u64Z short_channel_id_alias_arg) {
97                 long ret = bindings.ChannelReady_new(channel_id_arg.ptr, InternalUtils.check_arr_len(next_per_commitment_point_arg, 33), short_channel_id_alias_arg.ptr);
98                 Reference.reachabilityFence(channel_id_arg);
99                 Reference.reachabilityFence(next_per_commitment_point_arg);
100                 Reference.reachabilityFence(short_channel_id_alias_arg);
101                 if (ret >= 0 && ret <= 4096) { return null; }
102                 org.ldk.structs.ChannelReady ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelReady(null, ret); }
103                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
104                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channel_id_arg); };
105                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(short_channel_id_alias_arg); };
106                 return ret_hu_conv;
107         }
108
109         long clone_ptr() {
110                 long ret = bindings.ChannelReady_clone_ptr(this.ptr);
111                 Reference.reachabilityFence(this);
112                 return ret;
113         }
114
115         /**
116          * Creates a copy of the ChannelReady
117          */
118         public ChannelReady clone() {
119                 long ret = bindings.ChannelReady_clone(this.ptr);
120                 Reference.reachabilityFence(this);
121                 if (ret >= 0 && ret <= 4096) { return null; }
122                 org.ldk.structs.ChannelReady ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelReady(null, ret); }
123                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
124                 return ret_hu_conv;
125         }
126
127         /**
128          * Generates a non-cryptographic 64-bit hash of the ChannelReady.
129          */
130         public long hash() {
131                 long ret = bindings.ChannelReady_hash(this.ptr);
132                 Reference.reachabilityFence(this);
133                 return ret;
134         }
135
136         @Override public int hashCode() {
137                 return (int)this.hash();
138         }
139         /**
140          * Checks if two ChannelReadys contain equal inner contents.
141          * This ignores pointers and is_owned flags and looks at the values in fields.
142          * Two objects with NULL inner values will be considered "equal" here.
143          */
144         public boolean eq(org.ldk.structs.ChannelReady b) {
145                 boolean ret = bindings.ChannelReady_eq(this.ptr, b.ptr);
146                 Reference.reachabilityFence(this);
147                 Reference.reachabilityFence(b);
148                 if (this != null) { this.ptrs_to.add(b); };
149                 return ret;
150         }
151
152         @Override public boolean equals(Object o) {
153                 if (!(o instanceof ChannelReady)) return false;
154                 return this.eq((ChannelReady)o);
155         }
156         /**
157          * Serialize the ChannelReady object into a byte array which can be read by ChannelReady_read
158          */
159         public byte[] write() {
160                 byte[] ret = bindings.ChannelReady_write(this.ptr);
161                 Reference.reachabilityFence(this);
162                 return ret;
163         }
164
165         /**
166          * Read a ChannelReady from a byte array, created by ChannelReady_write
167          */
168         public static Result_ChannelReadyDecodeErrorZ read(byte[] ser) {
169                 long ret = bindings.ChannelReady_read(ser);
170                 Reference.reachabilityFence(ser);
171                 if (ret >= 0 && ret <= 4096) { return null; }
172                 Result_ChannelReadyDecodeErrorZ ret_hu_conv = Result_ChannelReadyDecodeErrorZ.constr_from_ptr(ret);
173                 return ret_hu_conv;
174         }
175
176 }