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