1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
11 * This class tracks the per-transaction information needed to build a commitment transaction and to
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.
15 * This class can be used inside a signer implementation to generate a signature given the relevant
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 {
24 if (ptr != 0) { bindings.CommitmentTransaction_free(ptr); }
28 * Creates a copy of the CommitmentTransaction
30 public CommitmentTransaction clone() {
31 long ret = bindings.CommitmentTransaction_clone(this.ptr);
32 if (ret < 1024) { return null; }
33 CommitmentTransaction ret_hu_conv = new CommitmentTransaction(null, ret);
34 ret_hu_conv.ptrs_to.add(this);
39 * Serialize the CommitmentTransaction object into a byte array which can be read by CommitmentTransaction_read
41 public byte[] write() {
42 byte[] ret = bindings.CommitmentTransaction_write(this.ptr);
47 * Read a CommitmentTransaction from a byte array, created by CommitmentTransaction_write
49 public static Result_CommitmentTransactionDecodeErrorZ read(byte[] ser) {
50 long ret = bindings.CommitmentTransaction_read(ser);
51 if (ret < 1024) { return null; }
52 Result_CommitmentTransactionDecodeErrorZ ret_hu_conv = Result_CommitmentTransactionDecodeErrorZ.constr_from_ptr(ret);
57 * The backwards-counting commitment number
59 public long commitment_number() {
60 long ret = bindings.CommitmentTransaction_commitment_number(this.ptr);
65 * The value to be sent to the broadcaster
67 public long to_broadcaster_value_sat() {
68 long ret = bindings.CommitmentTransaction_to_broadcaster_value_sat(this.ptr);
73 * The value to be sent to the counterparty
75 public long to_countersignatory_value_sat() {
76 long ret = bindings.CommitmentTransaction_to_countersignatory_value_sat(this.ptr);
81 * The feerate paid per 1000-weight-unit in this commitment transaction.
83 public int feerate_per_kw() {
84 int ret = bindings.CommitmentTransaction_feerate_per_kw(this.ptr);
89 * Trust our pre-built transaction and derived transaction creation public keys.
91 * Applies a wrapper which allows access to these fields.
93 * This should only be used if you fully trust the builder of this object. It should not
94 * \tbe used by an external signer - instead use the verify function.
96 public TrustedCommitmentTransaction trust() {
97 long ret = bindings.CommitmentTransaction_trust(this.ptr);
98 if (ret < 1024) { return null; }
99 TrustedCommitmentTransaction ret_hu_conv = new TrustedCommitmentTransaction(null, ret);
100 ret_hu_conv.ptrs_to.add(this);
105 * Verify our pre-built transaction and derived transaction creation public keys.
107 * Applies a wrapper which allows access to these fields.
109 * An external validating signer must call this method before signing
110 * or using the built transaction.
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 < 1024) { 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);