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 descriptor used to sign for a commitment transaction's HTLC output.
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class HTLCDescriptor extends CommonBase {
16 HTLCDescriptor(Object _dummy, long ptr) { super(ptr); }
17 @Override @SuppressWarnings("deprecation")
18 protected void finalize() throws Throwable {
20 if (ptr != 0) { bindings.HTLCDescriptor_free(ptr); }
24 * The parameters required to derive the signer for the HTLC input.
26 public ChannelDerivationParameters get_channel_derivation_parameters() {
27 long ret = bindings.HTLCDescriptor_get_channel_derivation_parameters(this.ptr);
28 Reference.reachabilityFence(this);
29 if (ret >= 0 && ret <= 4096) { return null; }
30 org.ldk.structs.ChannelDerivationParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelDerivationParameters(null, ret); }
31 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
36 * The parameters required to derive the signer for the HTLC input.
38 public void set_channel_derivation_parameters(org.ldk.structs.ChannelDerivationParameters val) {
39 bindings.HTLCDescriptor_set_channel_derivation_parameters(this.ptr, val.ptr);
40 Reference.reachabilityFence(this);
41 Reference.reachabilityFence(val);
42 if (this != null) { this.ptrs_to.add(val); };
46 * The txid of the commitment transaction in which the HTLC output lives.
48 public byte[] get_commitment_txid() {
49 byte[] ret = bindings.HTLCDescriptor_get_commitment_txid(this.ptr);
50 Reference.reachabilityFence(this);
55 * The txid of the commitment transaction in which the HTLC output lives.
57 public void set_commitment_txid(byte[] val) {
58 bindings.HTLCDescriptor_set_commitment_txid(this.ptr, InternalUtils.check_arr_len(val, 32));
59 Reference.reachabilityFence(this);
60 Reference.reachabilityFence(val);
64 * The number of the commitment transaction in which the HTLC output lives.
66 public long get_per_commitment_number() {
67 long ret = bindings.HTLCDescriptor_get_per_commitment_number(this.ptr);
68 Reference.reachabilityFence(this);
73 * The number of the commitment transaction in which the HTLC output lives.
75 public void set_per_commitment_number(long val) {
76 bindings.HTLCDescriptor_set_per_commitment_number(this.ptr, val);
77 Reference.reachabilityFence(this);
78 Reference.reachabilityFence(val);
82 * The key tweak corresponding to the number of the commitment transaction in which the HTLC
83 * output lives. This tweak is applied to all the basepoints for both parties in the channel to
84 * arrive at unique keys per commitment.
86 * See <https://github.com/lightning/bolts/blob/master/03-transactions.md#keys> for more info.
88 public byte[] get_per_commitment_point() {
89 byte[] ret = bindings.HTLCDescriptor_get_per_commitment_point(this.ptr);
90 Reference.reachabilityFence(this);
95 * The key tweak corresponding to the number of the commitment transaction in which the HTLC
96 * output lives. This tweak is applied to all the basepoints for both parties in the channel to
97 * arrive at unique keys per commitment.
99 * See <https://github.com/lightning/bolts/blob/master/03-transactions.md#keys> for more info.
101 public void set_per_commitment_point(byte[] val) {
102 bindings.HTLCDescriptor_set_per_commitment_point(this.ptr, InternalUtils.check_arr_len(val, 33));
103 Reference.reachabilityFence(this);
104 Reference.reachabilityFence(val);
108 * The feerate to use on the HTLC claiming transaction. This is always `0` for HTLCs
109 * originating from a channel supporting anchor outputs, otherwise it is the channel's
110 * negotiated feerate at the time the commitment transaction was built.
112 public int get_feerate_per_kw() {
113 int ret = bindings.HTLCDescriptor_get_feerate_per_kw(this.ptr);
114 Reference.reachabilityFence(this);
119 * The feerate to use on the HTLC claiming transaction. This is always `0` for HTLCs
120 * originating from a channel supporting anchor outputs, otherwise it is the channel's
121 * negotiated feerate at the time the commitment transaction was built.
123 public void set_feerate_per_kw(int val) {
124 bindings.HTLCDescriptor_set_feerate_per_kw(this.ptr, val);
125 Reference.reachabilityFence(this);
126 Reference.reachabilityFence(val);
130 * The details of the HTLC as it appears in the commitment transaction.
132 public HTLCOutputInCommitment get_htlc() {
133 long ret = bindings.HTLCDescriptor_get_htlc(this.ptr);
134 Reference.reachabilityFence(this);
135 if (ret >= 0 && ret <= 4096) { return null; }
136 org.ldk.structs.HTLCOutputInCommitment ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.HTLCOutputInCommitment(null, ret); }
137 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
142 * The details of the HTLC as it appears in the commitment transaction.
144 public void set_htlc(org.ldk.structs.HTLCOutputInCommitment val) {
145 bindings.HTLCDescriptor_set_htlc(this.ptr, val.ptr);
146 Reference.reachabilityFence(this);
147 Reference.reachabilityFence(val);
148 if (this != null) { this.ptrs_to.add(val); };
152 * The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be
155 public Option_ThirtyTwoBytesZ get_preimage() {
156 long ret = bindings.HTLCDescriptor_get_preimage(this.ptr);
157 Reference.reachabilityFence(this);
158 if (ret >= 0 && ret <= 4096) { return null; }
159 org.ldk.structs.Option_ThirtyTwoBytesZ ret_hu_conv = org.ldk.structs.Option_ThirtyTwoBytesZ.constr_from_ptr(ret);
160 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
165 * The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be
168 public void set_preimage(org.ldk.structs.Option_ThirtyTwoBytesZ val) {
169 bindings.HTLCDescriptor_set_preimage(this.ptr, val.ptr);
170 Reference.reachabilityFence(this);
171 Reference.reachabilityFence(val);
172 if (this != null) { this.ptrs_to.add(val); };
176 * The counterparty's signature required to spend the HTLC output.
178 public byte[] get_counterparty_sig() {
179 byte[] ret = bindings.HTLCDescriptor_get_counterparty_sig(this.ptr);
180 Reference.reachabilityFence(this);
185 * The counterparty's signature required to spend the HTLC output.
187 public void set_counterparty_sig(byte[] val) {
188 bindings.HTLCDescriptor_set_counterparty_sig(this.ptr, InternalUtils.check_arr_len(val, 64));
189 Reference.reachabilityFence(this);
190 Reference.reachabilityFence(val);
194 * Constructs a new HTLCDescriptor given each field
196 public static HTLCDescriptor of(org.ldk.structs.ChannelDerivationParameters channel_derivation_parameters_arg, byte[] commitment_txid_arg, long per_commitment_number_arg, byte[] per_commitment_point_arg, int feerate_per_kw_arg, org.ldk.structs.HTLCOutputInCommitment htlc_arg, org.ldk.structs.Option_ThirtyTwoBytesZ preimage_arg, byte[] counterparty_sig_arg) {
197 long ret = bindings.HTLCDescriptor_new(channel_derivation_parameters_arg.ptr, InternalUtils.check_arr_len(commitment_txid_arg, 32), per_commitment_number_arg, InternalUtils.check_arr_len(per_commitment_point_arg, 33), feerate_per_kw_arg, htlc_arg.ptr, preimage_arg.ptr, InternalUtils.check_arr_len(counterparty_sig_arg, 64));
198 Reference.reachabilityFence(channel_derivation_parameters_arg);
199 Reference.reachabilityFence(commitment_txid_arg);
200 Reference.reachabilityFence(per_commitment_number_arg);
201 Reference.reachabilityFence(per_commitment_point_arg);
202 Reference.reachabilityFence(feerate_per_kw_arg);
203 Reference.reachabilityFence(htlc_arg);
204 Reference.reachabilityFence(preimage_arg);
205 Reference.reachabilityFence(counterparty_sig_arg);
206 if (ret >= 0 && ret <= 4096) { return null; }
207 org.ldk.structs.HTLCDescriptor ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.HTLCDescriptor(null, ret); }
208 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
209 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channel_derivation_parameters_arg); };
210 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(htlc_arg); };
211 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(preimage_arg); };
216 long ret = bindings.HTLCDescriptor_clone_ptr(this.ptr);
217 Reference.reachabilityFence(this);
222 * Creates a copy of the HTLCDescriptor
224 public HTLCDescriptor clone() {
225 long ret = bindings.HTLCDescriptor_clone(this.ptr);
226 Reference.reachabilityFence(this);
227 if (ret >= 0 && ret <= 4096) { return null; }
228 org.ldk.structs.HTLCDescriptor ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.HTLCDescriptor(null, ret); }
229 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
234 * Checks if two HTLCDescriptors contain equal inner contents.
235 * This ignores pointers and is_owned flags and looks at the values in fields.
236 * Two objects with NULL inner values will be considered "equal" here.
238 public boolean eq(org.ldk.structs.HTLCDescriptor b) {
239 boolean ret = bindings.HTLCDescriptor_eq(this.ptr, b.ptr);
240 Reference.reachabilityFence(this);
241 Reference.reachabilityFence(b);
242 if (this != null) { this.ptrs_to.add(b); };
246 @Override public boolean equals(Object o) {
247 if (!(o instanceof HTLCDescriptor)) return false;
248 return this.eq((HTLCDescriptor)o);
251 * Serialize the HTLCDescriptor object into a byte array which can be read by HTLCDescriptor_read
253 public byte[] write() {
254 byte[] ret = bindings.HTLCDescriptor_write(this.ptr);
255 Reference.reachabilityFence(this);
260 * Read a HTLCDescriptor from a byte array, created by HTLCDescriptor_write
262 public static Result_HTLCDescriptorDecodeErrorZ read(byte[] ser) {
263 long ret = bindings.HTLCDescriptor_read(ser);
264 Reference.reachabilityFence(ser);
265 if (ret >= 0 && ret <= 4096) { return null; }
266 Result_HTLCDescriptorDecodeErrorZ ret_hu_conv = Result_HTLCDescriptorDecodeErrorZ.constr_from_ptr(ret);
271 * Returns the outpoint of the HTLC output in the commitment transaction. This is the outpoint
272 * being spent by the HTLC input in the HTLC transaction.
274 public OutPoint outpoint() {
275 long ret = bindings.HTLCDescriptor_outpoint(this.ptr);
276 Reference.reachabilityFence(this);
277 if (ret >= 0 && ret <= 4096) { return null; }
278 org.ldk.structs.OutPoint ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OutPoint(null, ret); }
279 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
284 * Returns the UTXO to be spent by the HTLC input, which can be obtained via
285 * [`Self::unsigned_tx_input`].
287 public TxOut previous_utxo() {
288 long ret = bindings.HTLCDescriptor_previous_utxo(this.ptr);
289 Reference.reachabilityFence(this);
290 if (ret >= 0 && ret <= 4096) { return null; }
291 TxOut ret_conv = new TxOut(null, ret);
296 * Returns the unsigned transaction input spending the HTLC output in the commitment
299 public TxIn unsigned_tx_input() {
300 long ret = bindings.HTLCDescriptor_unsigned_tx_input(this.ptr);
301 Reference.reachabilityFence(this);
302 if (ret >= 0 && ret <= 4096) { return null; }
303 TxIn ret_conv = new TxIn(null, ret);
308 * Returns the delayed output created as a result of spending the HTLC output in the commitment
311 public TxOut tx_output() {
312 long ret = bindings.HTLCDescriptor_tx_output(this.ptr);
313 Reference.reachabilityFence(this);
314 if (ret >= 0 && ret <= 4096) { return null; }
315 TxOut ret_conv = new TxOut(null, ret);
320 * Returns the witness script of the HTLC output in the commitment transaction.
322 public byte[] witness_script() {
323 byte[] ret = bindings.HTLCDescriptor_witness_script(this.ptr);
324 Reference.reachabilityFence(this);
329 * Returns the fully signed witness required to spend the HTLC output in the commitment
332 public byte[] tx_input_witness(byte[] signature, byte[] witness_script) {
333 byte[] ret = bindings.HTLCDescriptor_tx_input_witness(this.ptr, InternalUtils.check_arr_len(signature, 64), witness_script);
334 Reference.reachabilityFence(this);
335 Reference.reachabilityFence(signature);
336 Reference.reachabilityFence(witness_script);
341 * Derives the channel signer required to sign the HTLC input.
343 public WriteableEcdsaChannelSigner derive_channel_signer(org.ldk.structs.SignerProvider signer_provider) {
344 long ret = bindings.HTLCDescriptor_derive_channel_signer(this.ptr, signer_provider.ptr);
345 Reference.reachabilityFence(this);
346 Reference.reachabilityFence(signer_provider);
347 if (ret >= 0 && ret <= 4096) { return null; }
348 WriteableEcdsaChannelSigner ret_hu_conv = new WriteableEcdsaChannelSigner(null, ret);
349 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
350 if (this != null) { this.ptrs_to.add(signer_provider); };