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 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.
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 long ret = bindings.CommitmentTransaction_clone_ptr(this.ptr);
33 * Creates a copy of the CommitmentTransaction
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);
44 * Serialize the CommitmentTransaction object into a byte array which can be read by CommitmentTransaction_read
46 public byte[] write() {
47 byte[] ret = bindings.CommitmentTransaction_write(this.ptr);
52 * Read a CommitmentTransaction from a byte array, created by CommitmentTransaction_write
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);
62 * The backwards-counting commitment number
64 public long commitment_number() {
65 long ret = bindings.CommitmentTransaction_commitment_number(this.ptr);
70 * The value to be sent to the broadcaster
72 public long to_broadcaster_value_sat() {
73 long ret = bindings.CommitmentTransaction_to_broadcaster_value_sat(this.ptr);
78 * The value to be sent to the counterparty
80 public long to_countersignatory_value_sat() {
81 long ret = bindings.CommitmentTransaction_to_countersignatory_value_sat(this.ptr);
86 * The feerate paid per 1000-weight-unit in this commitment transaction.
88 public int feerate_per_kw() {
89 int ret = bindings.CommitmentTransaction_feerate_per_kw(this.ptr);
94 * Trust our pre-built transaction and derived transaction creation public keys.
96 * Applies a wrapper which allows access to these fields.
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.
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);
110 * Verify our pre-built transaction and derived transaction creation public keys.
112 * Applies a wrapper which allows access to these fields.
114 * An external validating signer must call this method before signing
115 * or using the built transaction.
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);