3cea8cde0d0834dcf80783a8fc38bb030fe8ba30
[ldk-java] / src / main / java / org / ldk / structs / ClaimedHTLC.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  * Information about an HTLC that is part of a payment that can be claimed.
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class ClaimedHTLC extends CommonBase {
16         ClaimedHTLC(Object _dummy, long ptr) { super(ptr); }
17         @Override @SuppressWarnings("deprecation")
18         protected void finalize() throws Throwable {
19                 super.finalize();
20                 if (ptr != 0) { bindings.ClaimedHTLC_free(ptr); }
21         }
22
23         /**
24          * The `channel_id` of the channel over which the HTLC was received.
25          */
26         public byte[] get_channel_id() {
27                 byte[] ret = bindings.ClaimedHTLC_get_channel_id(this.ptr);
28                 Reference.reachabilityFence(this);
29                 return ret;
30         }
31
32         /**
33          * The `channel_id` of the channel over which the HTLC was received.
34          */
35         public void set_channel_id(byte[] val) {
36                 bindings.ClaimedHTLC_set_channel_id(this.ptr, InternalUtils.check_arr_len(val, 32));
37                 Reference.reachabilityFence(this);
38                 Reference.reachabilityFence(val);
39         }
40
41         /**
42          * The `user_channel_id` of the channel over which the HTLC was received. This is the value
43          * passed in to [`ChannelManager::create_channel`] for outbound channels, or to
44          * [`ChannelManager::accept_inbound_channel`] for inbound channels if
45          * [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
46          * `user_channel_id` will be randomized for an inbound channel.
47          * 
48          * This field will be zero for a payment that was serialized prior to LDK version 0.0.117. (This
49          * should only happen in the case that a payment was claimable prior to LDK version 0.0.117, but
50          * was not actually claimed until after upgrading.)
51          * 
52          * [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
53          * [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
54          * [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
55          */
56         public UInt128 get_user_channel_id() {
57                 byte[] ret = bindings.ClaimedHTLC_get_user_channel_id(this.ptr);
58                 Reference.reachabilityFence(this);
59                 org.ldk.util.UInt128 ret_conv = new org.ldk.util.UInt128(ret);
60                 return ret_conv;
61         }
62
63         /**
64          * The `user_channel_id` of the channel over which the HTLC was received. This is the value
65          * passed in to [`ChannelManager::create_channel`] for outbound channels, or to
66          * [`ChannelManager::accept_inbound_channel`] for inbound channels if
67          * [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
68          * `user_channel_id` will be randomized for an inbound channel.
69          * 
70          * This field will be zero for a payment that was serialized prior to LDK version 0.0.117. (This
71          * should only happen in the case that a payment was claimable prior to LDK version 0.0.117, but
72          * was not actually claimed until after upgrading.)
73          * 
74          * [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
75          * [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
76          * [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
77          */
78         public void set_user_channel_id(org.ldk.util.UInt128 val) {
79                 bindings.ClaimedHTLC_set_user_channel_id(this.ptr, val.getLEBytes());
80                 Reference.reachabilityFence(this);
81                 Reference.reachabilityFence(val);
82         }
83
84         /**
85          * The block height at which this HTLC expires.
86          */
87         public int get_cltv_expiry() {
88                 int ret = bindings.ClaimedHTLC_get_cltv_expiry(this.ptr);
89                 Reference.reachabilityFence(this);
90                 return ret;
91         }
92
93         /**
94          * The block height at which this HTLC expires.
95          */
96         public void set_cltv_expiry(int val) {
97                 bindings.ClaimedHTLC_set_cltv_expiry(this.ptr, val);
98                 Reference.reachabilityFence(this);
99                 Reference.reachabilityFence(val);
100         }
101
102         /**
103          * The amount (in msats) of this part of an MPP.
104          */
105         public long get_value_msat() {
106                 long ret = bindings.ClaimedHTLC_get_value_msat(this.ptr);
107                 Reference.reachabilityFence(this);
108                 return ret;
109         }
110
111         /**
112          * The amount (in msats) of this part of an MPP.
113          */
114         public void set_value_msat(long val) {
115                 bindings.ClaimedHTLC_set_value_msat(this.ptr, val);
116                 Reference.reachabilityFence(this);
117                 Reference.reachabilityFence(val);
118         }
119
120         /**
121          * Constructs a new ClaimedHTLC given each field
122          */
123         public static ClaimedHTLC of(byte[] channel_id_arg, org.ldk.util.UInt128 user_channel_id_arg, int cltv_expiry_arg, long value_msat_arg) {
124                 long ret = bindings.ClaimedHTLC_new(InternalUtils.check_arr_len(channel_id_arg, 32), user_channel_id_arg.getLEBytes(), cltv_expiry_arg, value_msat_arg);
125                 Reference.reachabilityFence(channel_id_arg);
126                 Reference.reachabilityFence(user_channel_id_arg);
127                 Reference.reachabilityFence(cltv_expiry_arg);
128                 Reference.reachabilityFence(value_msat_arg);
129                 if (ret >= 0 && ret <= 4096) { return null; }
130                 org.ldk.structs.ClaimedHTLC ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ClaimedHTLC(null, ret); }
131                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
132                 return ret_hu_conv;
133         }
134
135         long clone_ptr() {
136                 long ret = bindings.ClaimedHTLC_clone_ptr(this.ptr);
137                 Reference.reachabilityFence(this);
138                 return ret;
139         }
140
141         /**
142          * Creates a copy of the ClaimedHTLC
143          */
144         public ClaimedHTLC clone() {
145                 long ret = bindings.ClaimedHTLC_clone(this.ptr);
146                 Reference.reachabilityFence(this);
147                 if (ret >= 0 && ret <= 4096) { return null; }
148                 org.ldk.structs.ClaimedHTLC ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ClaimedHTLC(null, ret); }
149                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
150                 return ret_hu_conv;
151         }
152
153         /**
154          * Checks if two ClaimedHTLCs contain equal inner contents.
155          * This ignores pointers and is_owned flags and looks at the values in fields.
156          * Two objects with NULL inner values will be considered "equal" here.
157          */
158         public boolean eq(org.ldk.structs.ClaimedHTLC b) {
159                 boolean ret = bindings.ClaimedHTLC_eq(this.ptr, b == null ? 0 : b.ptr);
160                 Reference.reachabilityFence(this);
161                 Reference.reachabilityFence(b);
162                 if (this != null) { this.ptrs_to.add(b); };
163                 return ret;
164         }
165
166         @Override public boolean equals(Object o) {
167                 if (!(o instanceof ClaimedHTLC)) return false;
168                 return this.eq((ClaimedHTLC)o);
169         }
170         /**
171          * Serialize the ClaimedHTLC object into a byte array which can be read by ClaimedHTLC_read
172          */
173         public byte[] write() {
174                 byte[] ret = bindings.ClaimedHTLC_write(this.ptr);
175                 Reference.reachabilityFence(this);
176                 return ret;
177         }
178
179         /**
180          * Read a ClaimedHTLC from a byte array, created by ClaimedHTLC_write
181          */
182         public static Result_ClaimedHTLCDecodeErrorZ read(byte[] ser) {
183                 long ret = bindings.ClaimedHTLC_read(ser);
184                 Reference.reachabilityFence(ser);
185                 if (ret >= 0 && ret <= 4096) { return null; }
186                 Result_ClaimedHTLCDecodeErrorZ ret_hu_conv = Result_ClaimedHTLCDecodeErrorZ.constr_from_ptr(ret);
187                 return ret_hu_conv;
188         }
189
190 }