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 ChannelId get_channel_id() {
29 long ret = bindings.UpdateAddHTLC_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); };
40 public void set_channel_id(org.ldk.structs.ChannelId val) {
41 bindings.UpdateAddHTLC_set_channel_id(this.ptr, val.ptr);
42 Reference.reachabilityFence(this);
43 Reference.reachabilityFence(val);
44 if (this != null) { this.ptrs_to.add(val); };
50 public long get_htlc_id() {
51 long ret = bindings.UpdateAddHTLC_get_htlc_id(this.ptr);
52 Reference.reachabilityFence(this);
59 public void set_htlc_id(long val) {
60 bindings.UpdateAddHTLC_set_htlc_id(this.ptr, val);
61 Reference.reachabilityFence(this);
62 Reference.reachabilityFence(val);
66 * The HTLC value in milli-satoshi
68 public long get_amount_msat() {
69 long ret = bindings.UpdateAddHTLC_get_amount_msat(this.ptr);
70 Reference.reachabilityFence(this);
75 * The HTLC value in milli-satoshi
77 public void set_amount_msat(long val) {
78 bindings.UpdateAddHTLC_set_amount_msat(this.ptr, val);
79 Reference.reachabilityFence(this);
80 Reference.reachabilityFence(val);
84 * The payment hash, the pre-image of which controls HTLC redemption
86 public byte[] get_payment_hash() {
87 byte[] ret = bindings.UpdateAddHTLC_get_payment_hash(this.ptr);
88 Reference.reachabilityFence(this);
93 * The payment hash, the pre-image of which controls HTLC redemption
95 public void set_payment_hash(byte[] val) {
96 bindings.UpdateAddHTLC_set_payment_hash(this.ptr, InternalUtils.check_arr_len(val, 32));
97 Reference.reachabilityFence(this);
98 Reference.reachabilityFence(val);
102 * The expiry height of the HTLC
104 public int get_cltv_expiry() {
105 int ret = bindings.UpdateAddHTLC_get_cltv_expiry(this.ptr);
106 Reference.reachabilityFence(this);
111 * The expiry height of the HTLC
113 public void set_cltv_expiry(int val) {
114 bindings.UpdateAddHTLC_set_cltv_expiry(this.ptr, val);
115 Reference.reachabilityFence(this);
116 Reference.reachabilityFence(val);
120 * The extra fee skimmed by the sender of this message. See
121 * [`ChannelConfig::accept_underpaying_htlcs`].
123 * [`ChannelConfig::accept_underpaying_htlcs`]: crate::util::config::ChannelConfig::accept_underpaying_htlcs
125 public Option_u64Z get_skimmed_fee_msat() {
126 long ret = bindings.UpdateAddHTLC_get_skimmed_fee_msat(this.ptr);
127 Reference.reachabilityFence(this);
128 if (ret >= 0 && ret <= 4096) { return null; }
129 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
130 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
135 * The extra fee skimmed by the sender of this message. See
136 * [`ChannelConfig::accept_underpaying_htlcs`].
138 * [`ChannelConfig::accept_underpaying_htlcs`]: crate::util::config::ChannelConfig::accept_underpaying_htlcs
140 public void set_skimmed_fee_msat(org.ldk.structs.Option_u64Z val) {
141 bindings.UpdateAddHTLC_set_skimmed_fee_msat(this.ptr, val.ptr);
142 Reference.reachabilityFence(this);
143 Reference.reachabilityFence(val);
144 if (this != null) { this.ptrs_to.add(val); };
148 * The onion routing packet with encrypted data for the next hop.
150 public OnionPacket get_onion_routing_packet() {
151 long ret = bindings.UpdateAddHTLC_get_onion_routing_packet(this.ptr);
152 Reference.reachabilityFence(this);
153 if (ret >= 0 && ret <= 4096) { return null; }
154 org.ldk.structs.OnionPacket ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OnionPacket(null, ret); }
155 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
160 * The onion routing packet with encrypted data for the next hop.
162 public void set_onion_routing_packet(org.ldk.structs.OnionPacket val) {
163 bindings.UpdateAddHTLC_set_onion_routing_packet(this.ptr, val.ptr);
164 Reference.reachabilityFence(this);
165 Reference.reachabilityFence(val);
166 if (this != null) { this.ptrs_to.add(val); };
170 * Provided if we are relaying or receiving a payment within a blinded path, to decrypt the onion
171 * routing packet and the recipient-provided encrypted payload within.
173 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
176 public byte[] get_blinding_point() {
177 byte[] ret = bindings.UpdateAddHTLC_get_blinding_point(this.ptr);
178 Reference.reachabilityFence(this);
183 * Provided if we are relaying or receiving a payment within a blinded path, to decrypt the onion
184 * routing packet and the recipient-provided encrypted payload within.
186 * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
188 public void set_blinding_point(@Nullable byte[] val) {
189 bindings.UpdateAddHTLC_set_blinding_point(this.ptr, InternalUtils.check_arr_len(val, 33));
190 Reference.reachabilityFence(this);
191 Reference.reachabilityFence(val);
195 * Constructs a new UpdateAddHTLC given each field
197 * Note that blinding_point_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
199 public static UpdateAddHTLC of(org.ldk.structs.ChannelId 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) {
200 long ret = bindings.UpdateAddHTLC_new(channel_id_arg.ptr, 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.ptr, InternalUtils.check_arr_len(blinding_point_arg, 33));
201 Reference.reachabilityFence(channel_id_arg);
202 Reference.reachabilityFence(htlc_id_arg);
203 Reference.reachabilityFence(amount_msat_arg);
204 Reference.reachabilityFence(payment_hash_arg);
205 Reference.reachabilityFence(cltv_expiry_arg);
206 Reference.reachabilityFence(skimmed_fee_msat_arg);
207 Reference.reachabilityFence(onion_routing_packet_arg);
208 Reference.reachabilityFence(blinding_point_arg);
209 if (ret >= 0 && ret <= 4096) { return null; }
210 org.ldk.structs.UpdateAddHTLC ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.UpdateAddHTLC(null, ret); }
211 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
212 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channel_id_arg); };
213 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(skimmed_fee_msat_arg); };
214 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(onion_routing_packet_arg); };
219 long ret = bindings.UpdateAddHTLC_clone_ptr(this.ptr);
220 Reference.reachabilityFence(this);
225 * Creates a copy of the UpdateAddHTLC
227 public UpdateAddHTLC clone() {
228 long ret = bindings.UpdateAddHTLC_clone(this.ptr);
229 Reference.reachabilityFence(this);
230 if (ret >= 0 && ret <= 4096) { return null; }
231 org.ldk.structs.UpdateAddHTLC ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.UpdateAddHTLC(null, ret); }
232 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
237 * Generates a non-cryptographic 64-bit hash of the UpdateAddHTLC.
240 long ret = bindings.UpdateAddHTLC_hash(this.ptr);
241 Reference.reachabilityFence(this);
245 @Override public int hashCode() {
246 return (int)this.hash();
249 * Checks if two UpdateAddHTLCs contain equal inner contents.
250 * This ignores pointers and is_owned flags and looks at the values in fields.
251 * Two objects with NULL inner values will be considered "equal" here.
253 public boolean eq(org.ldk.structs.UpdateAddHTLC b) {
254 boolean ret = bindings.UpdateAddHTLC_eq(this.ptr, b.ptr);
255 Reference.reachabilityFence(this);
256 Reference.reachabilityFence(b);
257 if (this != null) { this.ptrs_to.add(b); };
261 @Override public boolean equals(Object o) {
262 if (!(o instanceof UpdateAddHTLC)) return false;
263 return this.eq((UpdateAddHTLC)o);
266 * Serialize the UpdateAddHTLC object into a byte array which can be read by UpdateAddHTLC_read
268 public byte[] write() {
269 byte[] ret = bindings.UpdateAddHTLC_write(this.ptr);
270 Reference.reachabilityFence(this);
275 * Read a UpdateAddHTLC from a byte array, created by UpdateAddHTLC_write
277 public static Result_UpdateAddHTLCDecodeErrorZ read(byte[] ser) {
278 long ret = bindings.UpdateAddHTLC_read(ser);
279 Reference.reachabilityFence(ser);
280 if (ret >= 0 && ret <= 4096) { return null; }
281 Result_UpdateAddHTLCDecodeErrorZ ret_hu_conv = Result_UpdateAddHTLCDecodeErrorZ.constr_from_ptr(ret);