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 * An [`update_add_htlc`] message to be sent to or received from a peer.
14 * [`update_add_htlc`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#adding-an-htlc-update_add_htlc
16 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
17 public class UpdateAddHTLC extends CommonBase {
18 UpdateAddHTLC(Object _dummy, long ptr) { super(ptr); }
19 @Override @SuppressWarnings("deprecation")
20 protected void finalize() throws Throwable {
22 if (ptr != 0) { bindings.UpdateAddHTLC_free(ptr); }
28 public byte[] get_channel_id() {
29 byte[] ret = bindings.UpdateAddHTLC_get_channel_id(this.ptr);
30 Reference.reachabilityFence(this);
37 public void set_channel_id(byte[] val) {
38 bindings.UpdateAddHTLC_set_channel_id(this.ptr, InternalUtils.check_arr_len(val, 32));
39 Reference.reachabilityFence(this);
40 Reference.reachabilityFence(val);
46 public long get_htlc_id() {
47 long ret = bindings.UpdateAddHTLC_get_htlc_id(this.ptr);
48 Reference.reachabilityFence(this);
55 public void set_htlc_id(long val) {
56 bindings.UpdateAddHTLC_set_htlc_id(this.ptr, val);
57 Reference.reachabilityFence(this);
58 Reference.reachabilityFence(val);
62 * The HTLC value in milli-satoshi
64 public long get_amount_msat() {
65 long ret = bindings.UpdateAddHTLC_get_amount_msat(this.ptr);
66 Reference.reachabilityFence(this);
71 * The HTLC value in milli-satoshi
73 public void set_amount_msat(long val) {
74 bindings.UpdateAddHTLC_set_amount_msat(this.ptr, val);
75 Reference.reachabilityFence(this);
76 Reference.reachabilityFence(val);
80 * The payment hash, the pre-image of which controls HTLC redemption
82 public byte[] get_payment_hash() {
83 byte[] ret = bindings.UpdateAddHTLC_get_payment_hash(this.ptr);
84 Reference.reachabilityFence(this);
89 * The payment hash, the pre-image of which controls HTLC redemption
91 public void set_payment_hash(byte[] val) {
92 bindings.UpdateAddHTLC_set_payment_hash(this.ptr, InternalUtils.check_arr_len(val, 32));
93 Reference.reachabilityFence(this);
94 Reference.reachabilityFence(val);
98 * The expiry height of the HTLC
100 public int get_cltv_expiry() {
101 int ret = bindings.UpdateAddHTLC_get_cltv_expiry(this.ptr);
102 Reference.reachabilityFence(this);
107 * The expiry height of the HTLC
109 public void set_cltv_expiry(int val) {
110 bindings.UpdateAddHTLC_set_cltv_expiry(this.ptr, val);
111 Reference.reachabilityFence(this);
112 Reference.reachabilityFence(val);
116 * The extra fee skimmed by the sender of this message. See
117 * [`ChannelConfig::accept_underpaying_htlcs`].
119 * [`ChannelConfig::accept_underpaying_htlcs`]: crate::util::config::ChannelConfig::accept_underpaying_htlcs
121 public Option_u64Z get_skimmed_fee_msat() {
122 long ret = bindings.UpdateAddHTLC_get_skimmed_fee_msat(this.ptr);
123 Reference.reachabilityFence(this);
124 if (ret >= 0 && ret <= 4096) { return null; }
125 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
126 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
131 * The extra fee skimmed by the sender of this message. See
132 * [`ChannelConfig::accept_underpaying_htlcs`].
134 * [`ChannelConfig::accept_underpaying_htlcs`]: crate::util::config::ChannelConfig::accept_underpaying_htlcs
136 public void set_skimmed_fee_msat(org.ldk.structs.Option_u64Z val) {
137 bindings.UpdateAddHTLC_set_skimmed_fee_msat(this.ptr, val.ptr);
138 Reference.reachabilityFence(this);
139 Reference.reachabilityFence(val);
140 if (this != null) { this.ptrs_to.add(val); };
144 * The onion routing packet with encrypted data for the next hop.
146 public OnionPacket get_onion_routing_packet() {
147 long ret = bindings.UpdateAddHTLC_get_onion_routing_packet(this.ptr);
148 Reference.reachabilityFence(this);
149 if (ret >= 0 && ret <= 4096) { return null; }
150 org.ldk.structs.OnionPacket ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OnionPacket(null, ret); }
151 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
156 * The onion routing packet with encrypted data for the next hop.
158 public void set_onion_routing_packet(org.ldk.structs.OnionPacket val) {
159 bindings.UpdateAddHTLC_set_onion_routing_packet(this.ptr, val == null ? 0 : val.ptr);
160 Reference.reachabilityFence(this);
161 Reference.reachabilityFence(val);
162 if (this != null) { this.ptrs_to.add(val); };
166 * Provided if we are relaying or receiving a payment within a blinded path, to decrypt the onion
167 * routing packet and the recipient-provided encrypted payload within.
169 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
172 public byte[] get_blinding_point() {
173 byte[] ret = bindings.UpdateAddHTLC_get_blinding_point(this.ptr);
174 Reference.reachabilityFence(this);
179 * Provided if we are relaying or receiving a payment within a blinded path, to decrypt the onion
180 * routing packet and the recipient-provided encrypted payload within.
182 * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
184 public void set_blinding_point(@Nullable byte[] val) {
185 bindings.UpdateAddHTLC_set_blinding_point(this.ptr, InternalUtils.check_arr_len(val, 33));
186 Reference.reachabilityFence(this);
187 Reference.reachabilityFence(val);
191 * Constructs a new UpdateAddHTLC given each field
193 * Note that blinding_point_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
195 public static UpdateAddHTLC of(byte[] channel_id_arg, long htlc_id_arg, long amount_msat_arg, byte[] payment_hash_arg, int cltv_expiry_arg, org.ldk.structs.Option_u64Z skimmed_fee_msat_arg, org.ldk.structs.OnionPacket onion_routing_packet_arg, @Nullable byte[] blinding_point_arg) {
196 long ret = bindings.UpdateAddHTLC_new(InternalUtils.check_arr_len(channel_id_arg, 32), htlc_id_arg, amount_msat_arg, InternalUtils.check_arr_len(payment_hash_arg, 32), cltv_expiry_arg, skimmed_fee_msat_arg.ptr, onion_routing_packet_arg == null ? 0 : onion_routing_packet_arg.ptr, InternalUtils.check_arr_len(blinding_point_arg, 33));
197 Reference.reachabilityFence(channel_id_arg);
198 Reference.reachabilityFence(htlc_id_arg);
199 Reference.reachabilityFence(amount_msat_arg);
200 Reference.reachabilityFence(payment_hash_arg);
201 Reference.reachabilityFence(cltv_expiry_arg);
202 Reference.reachabilityFence(skimmed_fee_msat_arg);
203 Reference.reachabilityFence(onion_routing_packet_arg);
204 Reference.reachabilityFence(blinding_point_arg);
205 if (ret >= 0 && ret <= 4096) { return null; }
206 org.ldk.structs.UpdateAddHTLC ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.UpdateAddHTLC(null, ret); }
207 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
208 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(skimmed_fee_msat_arg); };
209 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(onion_routing_packet_arg); };
214 long ret = bindings.UpdateAddHTLC_clone_ptr(this.ptr);
215 Reference.reachabilityFence(this);
220 * Creates a copy of the UpdateAddHTLC
222 public UpdateAddHTLC clone() {
223 long ret = bindings.UpdateAddHTLC_clone(this.ptr);
224 Reference.reachabilityFence(this);
225 if (ret >= 0 && ret <= 4096) { return null; }
226 org.ldk.structs.UpdateAddHTLC ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.UpdateAddHTLC(null, ret); }
227 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
232 * Generates a non-cryptographic 64-bit hash of the UpdateAddHTLC.
235 long ret = bindings.UpdateAddHTLC_hash(this.ptr);
236 Reference.reachabilityFence(this);
240 @Override public int hashCode() {
241 return (int)this.hash();
244 * Checks if two UpdateAddHTLCs contain equal inner contents.
245 * This ignores pointers and is_owned flags and looks at the values in fields.
246 * Two objects with NULL inner values will be considered "equal" here.
248 public boolean eq(org.ldk.structs.UpdateAddHTLC b) {
249 boolean ret = bindings.UpdateAddHTLC_eq(this.ptr, b == null ? 0 : b.ptr);
250 Reference.reachabilityFence(this);
251 Reference.reachabilityFence(b);
252 if (this != null) { this.ptrs_to.add(b); };
256 @Override public boolean equals(Object o) {
257 if (!(o instanceof UpdateAddHTLC)) return false;
258 return this.eq((UpdateAddHTLC)o);
261 * Serialize the UpdateAddHTLC object into a byte array which can be read by UpdateAddHTLC_read
263 public byte[] write() {
264 byte[] ret = bindings.UpdateAddHTLC_write(this.ptr);
265 Reference.reachabilityFence(this);
270 * Read a UpdateAddHTLC from a byte array, created by UpdateAddHTLC_write
272 public static Result_UpdateAddHTLCDecodeErrorZ read(byte[] ser) {
273 long ret = bindings.UpdateAddHTLC_read(ser);
274 Reference.reachabilityFence(ser);
275 if (ret >= 0 && ret <= 4096) { return null; }
276 Result_UpdateAddHTLCDecodeErrorZ ret_hu_conv = Result_UpdateAddHTLCDecodeErrorZ.constr_from_ptr(ret);