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 * 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.
16 * This class can be used inside a signer implementation to generate a signature given the relevant
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 {
25 if (ptr != 0) { bindings.CommitmentTransaction_free(ptr); }
29 long ret = bindings.CommitmentTransaction_clone_ptr(this.ptr);
30 Reference.reachabilityFence(this);
35 * Creates a copy of the CommitmentTransaction
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); };
47 * Serialize the CommitmentTransaction object into a byte array which can be read by CommitmentTransaction_read
49 public byte[] write() {
50 byte[] ret = bindings.CommitmentTransaction_write(this.ptr);
51 Reference.reachabilityFence(this);
56 * Read a CommitmentTransaction from a byte array, created by CommitmentTransaction_write
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);
67 * The backwards-counting commitment number
69 public long commitment_number() {
70 long ret = bindings.CommitmentTransaction_commitment_number(this.ptr);
71 Reference.reachabilityFence(this);
76 * The per commitment point used by the broadcaster.
78 public byte[] per_commitment_point() {
79 byte[] ret = bindings.CommitmentTransaction_per_commitment_point(this.ptr);
80 Reference.reachabilityFence(this);
85 * The value to be sent to the broadcaster
87 public long to_broadcaster_value_sat() {
88 long ret = bindings.CommitmentTransaction_to_broadcaster_value_sat(this.ptr);
89 Reference.reachabilityFence(this);
94 * The value to be sent to the counterparty
96 public long to_countersignatory_value_sat() {
97 long ret = bindings.CommitmentTransaction_to_countersignatory_value_sat(this.ptr);
98 Reference.reachabilityFence(this);
103 * The feerate paid per 1000-weight-unit in this commitment transaction.
105 public int feerate_per_kw() {
106 int ret = bindings.CommitmentTransaction_feerate_per_kw(this.ptr);
107 Reference.reachabilityFence(this);
112 * Trust our pre-built transaction and derived transaction creation public keys.
114 * Applies a wrapper which allows access to these fields.
116 * This should only be used if you fully trust the builder of this object. It should not
117 * be used by an external signer - instead use the verify function.
119 public TrustedCommitmentTransaction trust() {
120 long ret = bindings.CommitmentTransaction_trust(this.ptr);
121 Reference.reachabilityFence(this);
122 if (ret >= 0 && ret <= 4096) { return null; }
123 org.ldk.structs.TrustedCommitmentTransaction ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.TrustedCommitmentTransaction(null, ret); }
124 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
129 * Verify our pre-built transaction and derived transaction creation public keys.
131 * Applies a wrapper which allows access to these fields.
133 * An external validating signer must call this method before signing
134 * or using the built transaction.
136 public Result_TrustedCommitmentTransactionNoneZ verify(org.ldk.structs.DirectedChannelTransactionParameters channel_parameters, org.ldk.structs.ChannelPublicKeys broadcaster_keys, org.ldk.structs.ChannelPublicKeys countersignatory_keys) {
137 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);
138 Reference.reachabilityFence(this);
139 Reference.reachabilityFence(channel_parameters);
140 Reference.reachabilityFence(broadcaster_keys);
141 Reference.reachabilityFence(countersignatory_keys);
142 if (ret >= 0 && ret <= 4096) { return null; }
143 Result_TrustedCommitmentTransactionNoneZ ret_hu_conv = Result_TrustedCommitmentTransactionNoneZ.constr_from_ptr(ret);
144 if (this != null) { this.ptrs_to.add(channel_parameters); };
145 if (this != null) { this.ptrs_to.add(broadcaster_keys); };
146 if (this != null) { this.ptrs_to.add(countersignatory_keys); };