1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
10 * This class tracks the per-transaction information needed to build a commitment transaction and to
11 * actually build it and sign. It is used for holder transactions that we sign only when needed
12 * and for transactions we sign for the counterparty.
14 * This class can be used inside a signer implementation to generate a signature given the relevant
17 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
18 public class CommitmentTransaction extends CommonBase {
19 CommitmentTransaction(Object _dummy, long ptr) { super(ptr); }
20 @Override @SuppressWarnings("deprecation")
21 protected void finalize() throws Throwable {
23 if (ptr != 0) { bindings.CommitmentTransaction_free(ptr); }
27 * Creates a copy of the CommitmentTransaction
29 public CommitmentTransaction clone() {
30 long ret = bindings.CommitmentTransaction_clone(this.ptr);
31 CommitmentTransaction ret_hu_conv = new CommitmentTransaction(null, ret);
32 ret_hu_conv.ptrs_to.add(this);
37 * Serialize the CommitmentTransaction object into a byte array which can be read by CommitmentTransaction_read
39 public byte[] write() {
40 byte[] ret = bindings.CommitmentTransaction_write(this.ptr);
45 * Read a CommitmentTransaction from a byte array, created by CommitmentTransaction_write
47 public static Result_CommitmentTransactionDecodeErrorZ constructor_read(byte[] ser) {
48 long ret = bindings.CommitmentTransaction_read(ser);
49 Result_CommitmentTransactionDecodeErrorZ ret_hu_conv = Result_CommitmentTransactionDecodeErrorZ.constr_from_ptr(ret);
54 * The backwards-counting commitment number
56 public long commitment_number() {
57 long ret = bindings.CommitmentTransaction_commitment_number(this.ptr);
62 * The value to be sent to the broadcaster
64 public long to_broadcaster_value_sat() {
65 long ret = bindings.CommitmentTransaction_to_broadcaster_value_sat(this.ptr);
70 * The value to be sent to the counterparty
72 public long to_countersignatory_value_sat() {
73 long ret = bindings.CommitmentTransaction_to_countersignatory_value_sat(this.ptr);
78 * The feerate paid per 1000-weight-unit in this commitment transaction.
80 public int feerate_per_kw() {
81 int ret = bindings.CommitmentTransaction_feerate_per_kw(this.ptr);
86 * Trust our pre-built transaction and derived transaction creation public keys.
88 * Applies a wrapper which allows access to these fields.
90 * This should only be used if you fully trust the builder of this object. It should not
91 * \tbe used by an external signer - instead use the verify function.
93 public TrustedCommitmentTransaction trust() {
94 long ret = bindings.CommitmentTransaction_trust(this.ptr);
95 TrustedCommitmentTransaction ret_hu_conv = new TrustedCommitmentTransaction(null, ret);
96 ret_hu_conv.ptrs_to.add(this);
101 * Verify our pre-built transaction and derived transaction creation public keys.
103 * Applies a wrapper which allows access to these fields.
105 * An external validating signer must call this method before signing
106 * or using the built transaction.
108 public Result_TrustedCommitmentTransactionNoneZ verify(DirectedChannelTransactionParameters channel_parameters, ChannelPublicKeys broadcaster_keys, ChannelPublicKeys countersignatory_keys) {
109 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);
110 Result_TrustedCommitmentTransactionNoneZ ret_hu_conv = Result_TrustedCommitmentTransactionNoneZ.constr_from_ptr(ret);
111 this.ptrs_to.add(channel_parameters);
112 this.ptrs_to.add(broadcaster_keys);
113 this.ptrs_to.add(countersignatory_keys);