63910b514ea8174055293fcb4a939dfe6867c903
[ldk-java] / src / main / java / org / ldk / structs / CommitmentTransaction.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  * This class tracks the per-transaction information needed to build a commitment transaction and will
13  * actually build it and sign.  It is used for holder transactions that we sign only when needed
14  * and for transactions we sign for the counterparty.
15  * 
16  * This class can be used inside a signer implementation to generate a signature given the relevant
17  * secret key.
18  */
19 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
20 public class CommitmentTransaction extends CommonBase {
21         CommitmentTransaction(Object _dummy, long ptr) { super(ptr); }
22         @Override @SuppressWarnings("deprecation")
23         protected void finalize() throws Throwable {
24                 super.finalize();
25                 if (ptr != 0) { bindings.CommitmentTransaction_free(ptr); }
26         }
27
28         long clone_ptr() {
29                 long ret = bindings.CommitmentTransaction_clone_ptr(this.ptr);
30                 Reference.reachabilityFence(this);
31                 return ret;
32         }
33
34         /**
35          * Creates a copy of the CommitmentTransaction
36          */
37         public CommitmentTransaction clone() {
38                 long ret = bindings.CommitmentTransaction_clone(this.ptr);
39                 Reference.reachabilityFence(this);
40                 if (ret >= 0 && ret <= 4096) { return null; }
41                 org.ldk.structs.CommitmentTransaction ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.CommitmentTransaction(null, ret); }
42                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
43                 return ret_hu_conv;
44         }
45
46         /**
47          * Serialize the CommitmentTransaction object into a byte array which can be read by CommitmentTransaction_read
48          */
49         public byte[] write() {
50                 byte[] ret = bindings.CommitmentTransaction_write(this.ptr);
51                 Reference.reachabilityFence(this);
52                 return ret;
53         }
54
55         /**
56          * Read a CommitmentTransaction from a byte array, created by CommitmentTransaction_write
57          */
58         public static Result_CommitmentTransactionDecodeErrorZ read(byte[] ser) {
59                 long ret = bindings.CommitmentTransaction_read(ser);
60                 Reference.reachabilityFence(ser);
61                 if (ret >= 0 && ret <= 4096) { return null; }
62                 Result_CommitmentTransactionDecodeErrorZ ret_hu_conv = Result_CommitmentTransactionDecodeErrorZ.constr_from_ptr(ret);
63                 return ret_hu_conv;
64         }
65
66         /**
67          * The backwards-counting commitment number
68          */
69         public long commitment_number() {
70                 long ret = bindings.CommitmentTransaction_commitment_number(this.ptr);
71                 Reference.reachabilityFence(this);
72                 return ret;
73         }
74
75         /**
76          * The value to be sent to the broadcaster
77          */
78         public long to_broadcaster_value_sat() {
79                 long ret = bindings.CommitmentTransaction_to_broadcaster_value_sat(this.ptr);
80                 Reference.reachabilityFence(this);
81                 return ret;
82         }
83
84         /**
85          * The value to be sent to the counterparty
86          */
87         public long to_countersignatory_value_sat() {
88                 long ret = bindings.CommitmentTransaction_to_countersignatory_value_sat(this.ptr);
89                 Reference.reachabilityFence(this);
90                 return ret;
91         }
92
93         /**
94          * The feerate paid per 1000-weight-unit in this commitment transaction.
95          */
96         public int feerate_per_kw() {
97                 int ret = bindings.CommitmentTransaction_feerate_per_kw(this.ptr);
98                 Reference.reachabilityFence(this);
99                 return ret;
100         }
101
102         /**
103          * Trust our pre-built transaction and derived transaction creation public keys.
104          * 
105          * Applies a wrapper which allows access to these fields.
106          * 
107          * This should only be used if you fully trust the builder of this object.  It should not
108          * be used by an external signer - instead use the verify function.
109          */
110         public TrustedCommitmentTransaction trust() {
111                 long ret = bindings.CommitmentTransaction_trust(this.ptr);
112                 Reference.reachabilityFence(this);
113                 if (ret >= 0 && ret <= 4096) { return null; }
114                 org.ldk.structs.TrustedCommitmentTransaction ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.TrustedCommitmentTransaction(null, ret); }
115                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
116                 return ret_hu_conv;
117         }
118
119         /**
120          * Verify our pre-built transaction and derived transaction creation public keys.
121          * 
122          * Applies a wrapper which allows access to these fields.
123          * 
124          * An external validating signer must call this method before signing
125          * or using the built transaction.
126          */
127         public Result_TrustedCommitmentTransactionNoneZ verify(org.ldk.structs.DirectedChannelTransactionParameters channel_parameters, org.ldk.structs.ChannelPublicKeys broadcaster_keys, org.ldk.structs.ChannelPublicKeys countersignatory_keys) {
128                 long ret = bindings.CommitmentTransaction_verify(this.ptr, channel_parameters == null ? 0 : channel_parameters.ptr, broadcaster_keys == null ? 0 : broadcaster_keys.ptr, countersignatory_keys == null ? 0 : countersignatory_keys.ptr);
129                 Reference.reachabilityFence(this);
130                 Reference.reachabilityFence(channel_parameters);
131                 Reference.reachabilityFence(broadcaster_keys);
132                 Reference.reachabilityFence(countersignatory_keys);
133                 if (ret >= 0 && ret <= 4096) { return null; }
134                 Result_TrustedCommitmentTransactionNoneZ ret_hu_conv = Result_TrustedCommitmentTransactionNoneZ.constr_from_ptr(ret);
135                 if (this != null) { this.ptrs_to.add(channel_parameters); };
136                 if (this != null) { this.ptrs_to.add(broadcaster_keys); };
137                 if (this != null) { this.ptrs_to.add(countersignatory_keys); };
138                 return ret_hu_conv;
139         }
140
141 }