1590d438c6d2054bed30846eb187117bdc0907d8
[ldk-java] / src / main / java / org / ldk / structs / TrustedCommitmentTransaction.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 wrapper on CommitmentTransaction indicating that the derived fields (the built bitcoin
13  * transaction and the transaction creation keys) are trusted.
14  * 
15  * See trust() and verify() functions on CommitmentTransaction.
16  * 
17  * This structure implements Deref.
18  */
19 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
20 public class TrustedCommitmentTransaction extends CommonBase {
21         TrustedCommitmentTransaction(Object _dummy, long ptr) { super(ptr); }
22         @Override @SuppressWarnings("deprecation")
23         protected void finalize() throws Throwable {
24                 super.finalize();
25                 if (ptr != 0) { bindings.TrustedCommitmentTransaction_free(ptr); }
26         }
27
28         /**
29          * The transaction ID of the built Bitcoin transaction
30          */
31         public byte[] txid() {
32                 byte[] ret = bindings.TrustedCommitmentTransaction_txid(this.ptr);
33                 Reference.reachabilityFence(this);
34                 return ret;
35         }
36
37         /**
38          * The pre-built Bitcoin commitment transaction
39          */
40         public BuiltCommitmentTransaction built_transaction() {
41                 long ret = bindings.TrustedCommitmentTransaction_built_transaction(this.ptr);
42                 Reference.reachabilityFence(this);
43                 if (ret >= 0 && ret <= 4096) { return null; }
44                 BuiltCommitmentTransaction ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new BuiltCommitmentTransaction(null, ret); }
45                 ret_hu_conv.ptrs_to.add(this);
46                 return ret_hu_conv;
47         }
48
49         /**
50          * The pre-calculated transaction creation public keys.
51          */
52         public TxCreationKeys keys() {
53                 long ret = bindings.TrustedCommitmentTransaction_keys(this.ptr);
54                 Reference.reachabilityFence(this);
55                 if (ret >= 0 && ret <= 4096) { return null; }
56                 TxCreationKeys ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new TxCreationKeys(null, ret); }
57                 ret_hu_conv.ptrs_to.add(this);
58                 return ret_hu_conv;
59         }
60
61         /**
62          * Should anchors be used.
63          */
64         public boolean opt_anchors() {
65                 boolean ret = bindings.TrustedCommitmentTransaction_opt_anchors(this.ptr);
66                 Reference.reachabilityFence(this);
67                 return ret;
68         }
69
70         /**
71          * Get a signature for each HTLC which was included in the commitment transaction (ie for
72          * which HTLCOutputInCommitment::transaction_output_index.is_some()).
73          * 
74          * The returned Vec has one entry for each HTLC, and in the same order.
75          */
76         public Result_CVec_SignatureZNoneZ get_htlc_sigs(byte[] htlc_base_key, DirectedChannelTransactionParameters channel_parameters) {
77                 long ret = bindings.TrustedCommitmentTransaction_get_htlc_sigs(this.ptr, InternalUtils.check_arr_len(htlc_base_key, 32), channel_parameters == null ? 0 : channel_parameters.ptr & ~1);
78                 Reference.reachabilityFence(this);
79                 Reference.reachabilityFence(htlc_base_key);
80                 Reference.reachabilityFence(channel_parameters);
81                 if (ret >= 0 && ret <= 4096) { return null; }
82                 Result_CVec_SignatureZNoneZ ret_hu_conv = Result_CVec_SignatureZNoneZ.constr_from_ptr(ret);
83                 this.ptrs_to.add(channel_parameters);
84                 return ret_hu_conv;
85         }
86
87 }