Merge pull request #33 from TheBlueMatt/main
[ldk-java] / src / main / java / org / ldk / structs / ChannelTransactionParameters.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 javax.annotation.Nullable;
8
9
10 /**
11  * Per-channel data used to build transactions in conjunction with the per-commitment data (CommitmentTransaction).
12  * The fields are organized by holder/counterparty.
13  * 
14  * Normally, this is converted to the broadcaster/countersignatory-organized DirectedChannelTransactionParameters
15  * before use, via the as_holder_broadcastable and as_counterparty_broadcastable functions.
16  */
17 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
18 public class ChannelTransactionParameters extends CommonBase {
19         ChannelTransactionParameters(Object _dummy, long ptr) { super(ptr); }
20         @Override @SuppressWarnings("deprecation")
21         protected void finalize() throws Throwable {
22                 super.finalize();
23                 if (ptr != 0) { bindings.ChannelTransactionParameters_free(ptr); }
24         }
25
26         /**
27          * Holder public keys
28          */
29         public ChannelPublicKeys get_holder_pubkeys() {
30                 long ret = bindings.ChannelTransactionParameters_get_holder_pubkeys(this.ptr);
31                 if (ret < 1024) { return null; }
32                 ChannelPublicKeys ret_hu_conv = new ChannelPublicKeys(null, ret);
33                 ret_hu_conv.ptrs_to.add(this);
34                 return ret_hu_conv;
35         }
36
37         /**
38          * Holder public keys
39          */
40         public void set_holder_pubkeys(ChannelPublicKeys val) {
41                 bindings.ChannelTransactionParameters_set_holder_pubkeys(this.ptr, val == null ? 0 : val.ptr & ~1);
42                 this.ptrs_to.add(val);
43         }
44
45         /**
46          * The contest delay selected by the holder, which applies to counterparty-broadcast transactions
47          */
48         public short get_holder_selected_contest_delay() {
49                 short ret = bindings.ChannelTransactionParameters_get_holder_selected_contest_delay(this.ptr);
50                 return ret;
51         }
52
53         /**
54          * The contest delay selected by the holder, which applies to counterparty-broadcast transactions
55          */
56         public void set_holder_selected_contest_delay(short val) {
57                 bindings.ChannelTransactionParameters_set_holder_selected_contest_delay(this.ptr, val);
58         }
59
60         /**
61          * Whether the holder is the initiator of this channel.
62          * This is an input to the commitment number obscure factor computation.
63          */
64         public boolean get_is_outbound_from_holder() {
65                 boolean ret = bindings.ChannelTransactionParameters_get_is_outbound_from_holder(this.ptr);
66                 return ret;
67         }
68
69         /**
70          * Whether the holder is the initiator of this channel.
71          * This is an input to the commitment number obscure factor computation.
72          */
73         public void set_is_outbound_from_holder(boolean val) {
74                 bindings.ChannelTransactionParameters_set_is_outbound_from_holder(this.ptr, val);
75         }
76
77         /**
78          * The late-bound counterparty channel transaction parameters.
79          * These parameters are populated at the point in the protocol where the counterparty provides them.
80          * 
81          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
82          */
83         @Nullable
84         public CounterpartyChannelTransactionParameters get_counterparty_parameters() {
85                 long ret = bindings.ChannelTransactionParameters_get_counterparty_parameters(this.ptr);
86                 if (ret < 1024) { return null; }
87                 CounterpartyChannelTransactionParameters ret_hu_conv = new CounterpartyChannelTransactionParameters(null, ret);
88                 ret_hu_conv.ptrs_to.add(this);
89                 return ret_hu_conv;
90         }
91
92         /**
93          * The late-bound counterparty channel transaction parameters.
94          * These parameters are populated at the point in the protocol where the counterparty provides them.
95          * 
96          * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
97          */
98         public void set_counterparty_parameters(@Nullable CounterpartyChannelTransactionParameters val) {
99                 bindings.ChannelTransactionParameters_set_counterparty_parameters(this.ptr, val == null ? 0 : val.ptr & ~1);
100                 this.ptrs_to.add(val);
101         }
102
103         /**
104          * The late-bound funding outpoint
105          * 
106          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
107          */
108         @Nullable
109         public OutPoint get_funding_outpoint() {
110                 long ret = bindings.ChannelTransactionParameters_get_funding_outpoint(this.ptr);
111                 if (ret < 1024) { return null; }
112                 OutPoint ret_hu_conv = new OutPoint(null, ret);
113                 ret_hu_conv.ptrs_to.add(this);
114                 return ret_hu_conv;
115         }
116
117         /**
118          * The late-bound funding outpoint
119          * 
120          * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
121          */
122         public void set_funding_outpoint(@Nullable OutPoint val) {
123                 bindings.ChannelTransactionParameters_set_funding_outpoint(this.ptr, val == null ? 0 : val.ptr & ~1);
124                 this.ptrs_to.add(val);
125         }
126
127         /**
128          * Constructs a new ChannelTransactionParameters given each field
129          */
130         public static ChannelTransactionParameters of(ChannelPublicKeys holder_pubkeys_arg, short holder_selected_contest_delay_arg, boolean is_outbound_from_holder_arg, CounterpartyChannelTransactionParameters counterparty_parameters_arg, OutPoint funding_outpoint_arg) {
131                 long ret = bindings.ChannelTransactionParameters_new(holder_pubkeys_arg == null ? 0 : holder_pubkeys_arg.ptr & ~1, holder_selected_contest_delay_arg, is_outbound_from_holder_arg, counterparty_parameters_arg == null ? 0 : counterparty_parameters_arg.ptr & ~1, funding_outpoint_arg == null ? 0 : funding_outpoint_arg.ptr & ~1);
132                 if (ret < 1024) { return null; }
133                 ChannelTransactionParameters ret_hu_conv = new ChannelTransactionParameters(null, ret);
134                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
135                 ret_hu_conv.ptrs_to.add(holder_pubkeys_arg);
136                 ret_hu_conv.ptrs_to.add(counterparty_parameters_arg);
137                 ret_hu_conv.ptrs_to.add(funding_outpoint_arg);
138                 return ret_hu_conv;
139         }
140
141         /**
142          * Creates a copy of the ChannelTransactionParameters
143          */
144         public ChannelTransactionParameters clone() {
145                 long ret = bindings.ChannelTransactionParameters_clone(this.ptr);
146                 if (ret < 1024) { return null; }
147                 ChannelTransactionParameters ret_hu_conv = new ChannelTransactionParameters(null, ret);
148                 ret_hu_conv.ptrs_to.add(this);
149                 return ret_hu_conv;
150         }
151
152         /**
153          * Whether the late bound parameters are populated.
154          */
155         public boolean is_populated() {
156                 boolean ret = bindings.ChannelTransactionParameters_is_populated(this.ptr);
157                 return ret;
158         }
159
160         /**
161          * Convert the holder/counterparty parameters to broadcaster/countersignatory-organized parameters,
162          * given that the holder is the broadcaster.
163          * 
164          * self.is_populated() must be true before calling this function.
165          */
166         public DirectedChannelTransactionParameters as_holder_broadcastable() {
167                 long ret = bindings.ChannelTransactionParameters_as_holder_broadcastable(this.ptr);
168                 if (ret < 1024) { return null; }
169                 DirectedChannelTransactionParameters ret_hu_conv = new DirectedChannelTransactionParameters(null, ret);
170                 ret_hu_conv.ptrs_to.add(this);
171                 return ret_hu_conv;
172         }
173
174         /**
175          * Convert the holder/counterparty parameters to broadcaster/countersignatory-organized parameters,
176          * given that the counterparty is the broadcaster.
177          * 
178          * self.is_populated() must be true before calling this function.
179          */
180         public DirectedChannelTransactionParameters as_counterparty_broadcastable() {
181                 long ret = bindings.ChannelTransactionParameters_as_counterparty_broadcastable(this.ptr);
182                 if (ret < 1024) { return null; }
183                 DirectedChannelTransactionParameters ret_hu_conv = new DirectedChannelTransactionParameters(null, ret);
184                 ret_hu_conv.ptrs_to.add(this);
185                 return ret_hu_conv;
186         }
187
188         /**
189          * Serialize the ChannelTransactionParameters object into a byte array which can be read by ChannelTransactionParameters_read
190          */
191         public byte[] write() {
192                 byte[] ret = bindings.ChannelTransactionParameters_write(this.ptr);
193                 return ret;
194         }
195
196         /**
197          * Read a ChannelTransactionParameters from a byte array, created by ChannelTransactionParameters_write
198          */
199         public static Result_ChannelTransactionParametersDecodeErrorZ read(byte[] ser) {
200                 long ret = bindings.ChannelTransactionParameters_read(ser);
201                 if (ret < 1024) { return null; }
202                 Result_ChannelTransactionParametersDecodeErrorZ ret_hu_conv = Result_ChannelTransactionParametersDecodeErrorZ.constr_from_ptr(ret);
203                 return ret_hu_conv;
204         }
205
206 }