Update auto-generated bindings to 0.0.103
[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         /**
28          * Creates a copy of the CommitmentTransaction
29          */
30         public CommitmentTransaction clone() {
31                 long ret = bindings.CommitmentTransaction_clone(this.ptr);
32                 if (ret >= 0 && ret <= 4096) { return null; }
33                 CommitmentTransaction ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new CommitmentTransaction(null, ret); }
34                 ret_hu_conv.ptrs_to.add(this);
35                 return ret_hu_conv;
36         }
37
38         /**
39          * Serialize the CommitmentTransaction object into a byte array which can be read by CommitmentTransaction_read
40          */
41         public byte[] write() {
42                 byte[] ret = bindings.CommitmentTransaction_write(this.ptr);
43                 return ret;
44         }
45
46         /**
47          * Read a CommitmentTransaction from a byte array, created by CommitmentTransaction_write
48          */
49         public static Result_CommitmentTransactionDecodeErrorZ read(byte[] ser) {
50                 long ret = bindings.CommitmentTransaction_read(ser);
51                 if (ret >= 0 && ret <= 4096) { return null; }
52                 Result_CommitmentTransactionDecodeErrorZ ret_hu_conv = Result_CommitmentTransactionDecodeErrorZ.constr_from_ptr(ret);
53                 return ret_hu_conv;
54         }
55
56         /**
57          * The backwards-counting commitment number
58          */
59         public long commitment_number() {
60                 long ret = bindings.CommitmentTransaction_commitment_number(this.ptr);
61                 return ret;
62         }
63
64         /**
65          * The value to be sent to the broadcaster
66          */
67         public long to_broadcaster_value_sat() {
68                 long ret = bindings.CommitmentTransaction_to_broadcaster_value_sat(this.ptr);
69                 return ret;
70         }
71
72         /**
73          * The value to be sent to the counterparty
74          */
75         public long to_countersignatory_value_sat() {
76                 long ret = bindings.CommitmentTransaction_to_countersignatory_value_sat(this.ptr);
77                 return ret;
78         }
79
80         /**
81          * The feerate paid per 1000-weight-unit in this commitment transaction.
82          */
83         public int feerate_per_kw() {
84                 int ret = bindings.CommitmentTransaction_feerate_per_kw(this.ptr);
85                 return ret;
86         }
87
88         /**
89          * Trust our pre-built transaction and derived transaction creation public keys.
90          * 
91          * Applies a wrapper which allows access to these fields.
92          * 
93          * This should only be used if you fully trust the builder of this object.  It should not
94          * be used by an external signer - instead use the verify function.
95          */
96         public TrustedCommitmentTransaction trust() {
97                 long ret = bindings.CommitmentTransaction_trust(this.ptr);
98                 if (ret >= 0 && ret <= 4096) { return null; }
99                 TrustedCommitmentTransaction ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new TrustedCommitmentTransaction(null, ret); }
100                 ret_hu_conv.ptrs_to.add(this);
101                 return ret_hu_conv;
102         }
103
104         /**
105          * Verify our pre-built transaction and derived transaction creation public keys.
106          * 
107          * Applies a wrapper which allows access to these fields.
108          * 
109          * An external validating signer must call this method before signing
110          * or using the built transaction.
111          */
112         public Result_TrustedCommitmentTransactionNoneZ verify(DirectedChannelTransactionParameters channel_parameters, ChannelPublicKeys broadcaster_keys, ChannelPublicKeys countersignatory_keys) {
113                 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);
114                 if (ret >= 0 && ret <= 4096) { return null; }
115                 Result_TrustedCommitmentTransactionNoneZ ret_hu_conv = Result_TrustedCommitmentTransactionNoneZ.constr_from_ptr(ret);
116                 this.ptrs_to.add(channel_parameters);
117                 this.ptrs_to.add(broadcaster_keys);
118                 this.ptrs_to.add(countersignatory_keys);
119                 return ret_hu_conv;
120         }
121
122 }