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 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 value to be sent to the broadcaster
78 public long to_broadcaster_value_sat() {
79 long ret = bindings.CommitmentTransaction_to_broadcaster_value_sat(this.ptr);
80 Reference.reachabilityFence(this);
85 * The value to be sent to the counterparty
87 public long to_countersignatory_value_sat() {
88 long ret = bindings.CommitmentTransaction_to_countersignatory_value_sat(this.ptr);
89 Reference.reachabilityFence(this);
94 * The feerate paid per 1000-weight-unit in this commitment transaction.
96 public int feerate_per_kw() {
97 int ret = bindings.CommitmentTransaction_feerate_per_kw(this.ptr);
98 Reference.reachabilityFence(this);
103 * Trust our pre-built transaction and derived transaction creation public keys.
105 * Applies a wrapper which allows access to these fields.
107 * This should only be used if you fully trust the builder of this object. It should not
108 * be used by an external signer - instead use the verify function.
110 public TrustedCommitmentTransaction trust() {
111 long ret = bindings.CommitmentTransaction_trust(this.ptr);
112 Reference.reachabilityFence(this);
113 if (ret >= 0 && ret <= 4096) { return null; }
114 org.ldk.structs.TrustedCommitmentTransaction ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.TrustedCommitmentTransaction(null, ret); }
115 ret_hu_conv.ptrs_to.add(this);
120 * Verify our pre-built transaction and derived transaction creation public keys.
122 * Applies a wrapper which allows access to these fields.
124 * An external validating signer must call this method before signing
125 * or using the built transaction.
127 public Result_TrustedCommitmentTransactionNoneZ verify(DirectedChannelTransactionParameters channel_parameters, ChannelPublicKeys broadcaster_keys, ChannelPublicKeys countersignatory_keys) {
128 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);
129 Reference.reachabilityFence(this);
130 Reference.reachabilityFence(channel_parameters);
131 Reference.reachabilityFence(broadcaster_keys);
132 Reference.reachabilityFence(countersignatory_keys);
133 if (ret >= 0 && ret <= 4096) { return null; }
134 Result_TrustedCommitmentTransactionNoneZ ret_hu_conv = Result_TrustedCommitmentTransactionNoneZ.constr_from_ptr(ret);
135 this.ptrs_to.add(channel_parameters);
136 this.ptrs_to.add(broadcaster_keys);
137 this.ptrs_to.add(countersignatory_keys);