c3cd91beaf3c62aefb53f098bd99316f32da9f20
[ldk-java] / src / main / java / org / ldk / structs / ClosingTransaction.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * This class tracks the per-transaction information needed to build a closing transaction and will
13  * actually build it and sign.
14  * 
15  * This class can be used inside a signer implementation to generate a signature given the relevant
16  * secret key.
17  */
18 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
19 public class ClosingTransaction extends CommonBase {
20         ClosingTransaction(Object _dummy, long ptr) { super(ptr); }
21         @Override @SuppressWarnings("deprecation")
22         protected void finalize() throws Throwable {
23                 super.finalize();
24                 if (ptr != 0) { bindings.ClosingTransaction_free(ptr); }
25         }
26
27         long clone_ptr() {
28                 long ret = bindings.ClosingTransaction_clone_ptr(this.ptr);
29                 Reference.reachabilityFence(this);
30                 return ret;
31         }
32
33         /**
34          * Creates a copy of the ClosingTransaction
35          */
36         public ClosingTransaction clone() {
37                 long ret = bindings.ClosingTransaction_clone(this.ptr);
38                 Reference.reachabilityFence(this);
39                 if (ret >= 0 && ret <= 4096) { return null; }
40                 org.ldk.structs.ClosingTransaction ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ClosingTransaction(null, ret); }
41                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
42                 return ret_hu_conv;
43         }
44
45         /**
46          * Checks if two ClosingTransactions contain equal inner contents.
47          */
48         public long hash() {
49                 long ret = bindings.ClosingTransaction_hash(this.ptr);
50                 Reference.reachabilityFence(this);
51                 return ret;
52         }
53
54         @Override public int hashCode() {
55                 return (int)this.hash();
56         }
57         /**
58          * Checks if two ClosingTransactions contain equal inner contents.
59          * This ignores pointers and is_owned flags and looks at the values in fields.
60          * Two objects with NULL inner values will be considered "equal" here.
61          */
62         public boolean eq(org.ldk.structs.ClosingTransaction b) {
63                 boolean ret = bindings.ClosingTransaction_eq(this.ptr, b == null ? 0 : b.ptr);
64                 Reference.reachabilityFence(this);
65                 Reference.reachabilityFence(b);
66                 if (this != null) { this.ptrs_to.add(b); };
67                 return ret;
68         }
69
70         @Override public boolean equals(Object o) {
71                 if (!(o instanceof ClosingTransaction)) return false;
72                 return this.eq((ClosingTransaction)o);
73         }
74         /**
75          * Construct an object of the class
76          */
77         public static ClosingTransaction of(long to_holder_value_sat, long to_counterparty_value_sat, byte[] to_holder_script, byte[] to_counterparty_script, org.ldk.structs.OutPoint funding_outpoint) {
78                 long ret = bindings.ClosingTransaction_new(to_holder_value_sat, to_counterparty_value_sat, to_holder_script, to_counterparty_script, funding_outpoint == null ? 0 : funding_outpoint.ptr);
79                 Reference.reachabilityFence(to_holder_value_sat);
80                 Reference.reachabilityFence(to_counterparty_value_sat);
81                 Reference.reachabilityFence(to_holder_script);
82                 Reference.reachabilityFence(to_counterparty_script);
83                 Reference.reachabilityFence(funding_outpoint);
84                 if (ret >= 0 && ret <= 4096) { return null; }
85                 org.ldk.structs.ClosingTransaction ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ClosingTransaction(null, ret); }
86                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
87                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(funding_outpoint); };
88                 return ret_hu_conv;
89         }
90
91         /**
92          * Trust our pre-built transaction.
93          * 
94          * Applies a wrapper which allows access to the transaction.
95          * 
96          * This should only be used if you fully trust the builder of this object. It should not
97          * be used by an external signer - instead use the verify function.
98          */
99         public TrustedClosingTransaction trust() {
100                 long ret = bindings.ClosingTransaction_trust(this.ptr);
101                 Reference.reachabilityFence(this);
102                 if (ret >= 0 && ret <= 4096) { return null; }
103                 org.ldk.structs.TrustedClosingTransaction ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.TrustedClosingTransaction(null, ret); }
104                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
105                 return ret_hu_conv;
106         }
107
108         /**
109          * Verify our pre-built transaction.
110          * 
111          * Applies a wrapper which allows access to the transaction.
112          * 
113          * An external validating signer must call this method before signing
114          * or using the built transaction.
115          */
116         public Result_TrustedClosingTransactionNoneZ verify(org.ldk.structs.OutPoint funding_outpoint) {
117                 long ret = bindings.ClosingTransaction_verify(this.ptr, funding_outpoint == null ? 0 : funding_outpoint.ptr);
118                 Reference.reachabilityFence(this);
119                 Reference.reachabilityFence(funding_outpoint);
120                 if (ret >= 0 && ret <= 4096) { return null; }
121                 Result_TrustedClosingTransactionNoneZ ret_hu_conv = Result_TrustedClosingTransactionNoneZ.constr_from_ptr(ret);
122                 if (this != null) { this.ptrs_to.add(funding_outpoint); };
123                 return ret_hu_conv;
124         }
125
126         /**
127          * The value to be sent to the holder, or zero if the output will be omitted
128          */
129         public long to_holder_value_sat() {
130                 long ret = bindings.ClosingTransaction_to_holder_value_sat(this.ptr);
131                 Reference.reachabilityFence(this);
132                 return ret;
133         }
134
135         /**
136          * The value to be sent to the counterparty, or zero if the output will be omitted
137          */
138         public long to_counterparty_value_sat() {
139                 long ret = bindings.ClosingTransaction_to_counterparty_value_sat(this.ptr);
140                 Reference.reachabilityFence(this);
141                 return ret;
142         }
143
144         /**
145          * The destination of the holder's output
146          */
147         public byte[] to_holder_script() {
148                 byte[] ret = bindings.ClosingTransaction_to_holder_script(this.ptr);
149                 Reference.reachabilityFence(this);
150                 return ret;
151         }
152
153         /**
154          * The destination of the counterparty's output
155          */
156         public byte[] to_counterparty_script() {
157                 byte[] ret = bindings.ClosingTransaction_to_counterparty_script(this.ptr);
158                 Reference.reachabilityFence(this);
159                 return ret;
160         }
161
162 }