06842bbcb6e4d854d9f1369cc1565de95c54f99b
[ldk-java] / src / main / java / org / ldk / structs / StaticPaymentOutputDescriptor.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  * Information about a spendable output to our \"payment key\".
13  * 
14  * See [`SpendableOutputDescriptor::StaticPaymentOutput`] for more details on how to spend this.
15  */
16 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
17 public class StaticPaymentOutputDescriptor extends CommonBase {
18         StaticPaymentOutputDescriptor(Object _dummy, long ptr) { super(ptr); }
19         @Override @SuppressWarnings("deprecation")
20         protected void finalize() throws Throwable {
21                 super.finalize();
22                 if (ptr != 0) { bindings.StaticPaymentOutputDescriptor_free(ptr); }
23         }
24
25         /**
26          * The outpoint which is spendable.
27          */
28         public OutPoint get_outpoint() {
29                 long ret = bindings.StaticPaymentOutputDescriptor_get_outpoint(this.ptr);
30                 Reference.reachabilityFence(this);
31                 if (ret >= 0 && ret <= 4096) { return null; }
32                 org.ldk.structs.OutPoint ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OutPoint(null, ret); }
33                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
34                 return ret_hu_conv;
35         }
36
37         /**
38          * The outpoint which is spendable.
39          */
40         public void set_outpoint(org.ldk.structs.OutPoint val) {
41                 bindings.StaticPaymentOutputDescriptor_set_outpoint(this.ptr, val == null ? 0 : val.ptr);
42                 Reference.reachabilityFence(this);
43                 Reference.reachabilityFence(val);
44                 if (this != null) { this.ptrs_to.add(val); };
45         }
46
47         /**
48          * The output which is referenced by the given outpoint.
49          * 
50          * Returns a copy of the field.
51          */
52         public TxOut get_output() {
53                 long ret = bindings.StaticPaymentOutputDescriptor_get_output(this.ptr);
54                 Reference.reachabilityFence(this);
55                 if (ret >= 0 && ret <= 4096) { return null; }
56                 TxOut ret_conv = new TxOut(null, ret);
57                 return ret_conv;
58         }
59
60         /**
61          * The output which is referenced by the given outpoint.
62          */
63         public void set_output(org.ldk.structs.TxOut val) {
64                 bindings.StaticPaymentOutputDescriptor_set_output(this.ptr, val.ptr);
65                 Reference.reachabilityFence(this);
66                 Reference.reachabilityFence(val);
67         }
68
69         /**
70          * Arbitrary identification information returned by a call to [`ChannelSigner::channel_keys_id`].
71          * This may be useful in re-deriving keys used in the channel to spend the output.
72          */
73         public byte[] get_channel_keys_id() {
74                 byte[] ret = bindings.StaticPaymentOutputDescriptor_get_channel_keys_id(this.ptr);
75                 Reference.reachabilityFence(this);
76                 return ret;
77         }
78
79         /**
80          * Arbitrary identification information returned by a call to [`ChannelSigner::channel_keys_id`].
81          * This may be useful in re-deriving keys used in the channel to spend the output.
82          */
83         public void set_channel_keys_id(byte[] val) {
84                 bindings.StaticPaymentOutputDescriptor_set_channel_keys_id(this.ptr, InternalUtils.check_arr_len(val, 32));
85                 Reference.reachabilityFence(this);
86                 Reference.reachabilityFence(val);
87         }
88
89         /**
90          * The value of the channel which this transactions spends.
91          */
92         public long get_channel_value_satoshis() {
93                 long ret = bindings.StaticPaymentOutputDescriptor_get_channel_value_satoshis(this.ptr);
94                 Reference.reachabilityFence(this);
95                 return ret;
96         }
97
98         /**
99          * The value of the channel which this transactions spends.
100          */
101         public void set_channel_value_satoshis(long val) {
102                 bindings.StaticPaymentOutputDescriptor_set_channel_value_satoshis(this.ptr, val);
103                 Reference.reachabilityFence(this);
104                 Reference.reachabilityFence(val);
105         }
106
107         /**
108          * Constructs a new StaticPaymentOutputDescriptor given each field
109          */
110         public static StaticPaymentOutputDescriptor of(org.ldk.structs.OutPoint outpoint_arg, org.ldk.structs.TxOut output_arg, byte[] channel_keys_id_arg, long channel_value_satoshis_arg) {
111                 long ret = bindings.StaticPaymentOutputDescriptor_new(outpoint_arg == null ? 0 : outpoint_arg.ptr, output_arg.ptr, InternalUtils.check_arr_len(channel_keys_id_arg, 32), channel_value_satoshis_arg);
112                 Reference.reachabilityFence(outpoint_arg);
113                 Reference.reachabilityFence(output_arg);
114                 Reference.reachabilityFence(channel_keys_id_arg);
115                 Reference.reachabilityFence(channel_value_satoshis_arg);
116                 if (ret >= 0 && ret <= 4096) { return null; }
117                 org.ldk.structs.StaticPaymentOutputDescriptor ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.StaticPaymentOutputDescriptor(null, ret); }
118                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
119                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(outpoint_arg); };
120                 return ret_hu_conv;
121         }
122
123         long clone_ptr() {
124                 long ret = bindings.StaticPaymentOutputDescriptor_clone_ptr(this.ptr);
125                 Reference.reachabilityFence(this);
126                 return ret;
127         }
128
129         /**
130          * Creates a copy of the StaticPaymentOutputDescriptor
131          */
132         public StaticPaymentOutputDescriptor clone() {
133                 long ret = bindings.StaticPaymentOutputDescriptor_clone(this.ptr);
134                 Reference.reachabilityFence(this);
135                 if (ret >= 0 && ret <= 4096) { return null; }
136                 org.ldk.structs.StaticPaymentOutputDescriptor ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.StaticPaymentOutputDescriptor(null, ret); }
137                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
138                 return ret_hu_conv;
139         }
140
141         /**
142          * Checks if two StaticPaymentOutputDescriptors contain equal inner contents.
143          * This ignores pointers and is_owned flags and looks at the values in fields.
144          * Two objects with NULL inner values will be considered "equal" here.
145          */
146         public boolean eq(org.ldk.structs.StaticPaymentOutputDescriptor b) {
147                 boolean ret = bindings.StaticPaymentOutputDescriptor_eq(this.ptr, b == null ? 0 : b.ptr);
148                 Reference.reachabilityFence(this);
149                 Reference.reachabilityFence(b);
150                 if (this != null) { this.ptrs_to.add(b); };
151                 return ret;
152         }
153
154         @Override public boolean equals(Object o) {
155                 if (!(o instanceof StaticPaymentOutputDescriptor)) return false;
156                 return this.eq((StaticPaymentOutputDescriptor)o);
157         }
158         /**
159          * Serialize the StaticPaymentOutputDescriptor object into a byte array which can be read by StaticPaymentOutputDescriptor_read
160          */
161         public byte[] write() {
162                 byte[] ret = bindings.StaticPaymentOutputDescriptor_write(this.ptr);
163                 Reference.reachabilityFence(this);
164                 return ret;
165         }
166
167         /**
168          * Read a StaticPaymentOutputDescriptor from a byte array, created by StaticPaymentOutputDescriptor_write
169          */
170         public static Result_StaticPaymentOutputDescriptorDecodeErrorZ read(byte[] ser) {
171                 long ret = bindings.StaticPaymentOutputDescriptor_read(ser);
172                 Reference.reachabilityFence(ser);
173                 if (ret >= 0 && ret <= 4096) { return null; }
174                 Result_StaticPaymentOutputDescriptorDecodeErrorZ ret_hu_conv = Result_StaticPaymentOutputDescriptorDecodeErrorZ.constr_from_ptr(ret);
175                 return ret_hu_conv;
176         }
177
178 }