d010bdb047a08ba4afcf927bdc0b841f4a9282f3
[ldk-java] / src / main / java / org / ldk / structs / Input.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  * An input that must be included in a transaction when performing coin selection through
13  * [`CoinSelectionSource::select_confirmed_utxos`]. It is guaranteed to be a SegWit input, so it
14  * must have an empty [`TxIn::script_sig`] when spent.
15  */
16 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
17 public class Input extends CommonBase {
18         Input(Object _dummy, long ptr) { super(ptr); }
19         @Override @SuppressWarnings("deprecation")
20         protected void finalize() throws Throwable {
21                 super.finalize();
22                 if (ptr != 0) { bindings.Input_free(ptr); }
23         }
24
25         /**
26          * The unique identifier of the input.
27          */
28         public OutPoint get_outpoint() {
29                 long ret = bindings.Input_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 unique identifier of the input.
39          */
40         public void set_outpoint(org.ldk.structs.OutPoint val) {
41                 bindings.Input_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 UTXO being spent by the input.
49          */
50         public TxOut get_previous_utxo() {
51                 long ret = bindings.Input_get_previous_utxo(this.ptr);
52                 Reference.reachabilityFence(this);
53                 if (ret >= 0 && ret <= 4096) { return null; }
54                 TxOut ret_conv = new TxOut(null, ret);
55                 return ret_conv;
56         }
57
58         /**
59          * The UTXO being spent by the input.
60          */
61         public void set_previous_utxo(org.ldk.structs.TxOut val) {
62                 bindings.Input_set_previous_utxo(this.ptr, val.ptr);
63                 Reference.reachabilityFence(this);
64                 Reference.reachabilityFence(val);
65         }
66
67         /**
68          * The upper-bound weight consumed by the input's full [`TxIn::script_sig`] and
69          * [`TxIn::witness`], each with their lengths included, required to satisfy the output's
70          * script.
71          */
72         public long get_satisfaction_weight() {
73                 long ret = bindings.Input_get_satisfaction_weight(this.ptr);
74                 Reference.reachabilityFence(this);
75                 return ret;
76         }
77
78         /**
79          * The upper-bound weight consumed by the input's full [`TxIn::script_sig`] and
80          * [`TxIn::witness`], each with their lengths included, required to satisfy the output's
81          * script.
82          */
83         public void set_satisfaction_weight(long val) {
84                 bindings.Input_set_satisfaction_weight(this.ptr, val);
85                 Reference.reachabilityFence(this);
86                 Reference.reachabilityFence(val);
87         }
88
89         /**
90          * Constructs a new Input given each field
91          */
92         public static Input of(org.ldk.structs.OutPoint outpoint_arg, org.ldk.structs.TxOut previous_utxo_arg, long satisfaction_weight_arg) {
93                 long ret = bindings.Input_new(outpoint_arg == null ? 0 : outpoint_arg.ptr, previous_utxo_arg.ptr, satisfaction_weight_arg);
94                 Reference.reachabilityFence(outpoint_arg);
95                 Reference.reachabilityFence(previous_utxo_arg);
96                 Reference.reachabilityFence(satisfaction_weight_arg);
97                 if (ret >= 0 && ret <= 4096) { return null; }
98                 org.ldk.structs.Input ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Input(null, ret); }
99                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
100                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(outpoint_arg); };
101                 return ret_hu_conv;
102         }
103
104         long clone_ptr() {
105                 long ret = bindings.Input_clone_ptr(this.ptr);
106                 Reference.reachabilityFence(this);
107                 return ret;
108         }
109
110         /**
111          * Creates a copy of the Input
112          */
113         public Input clone() {
114                 long ret = bindings.Input_clone(this.ptr);
115                 Reference.reachabilityFence(this);
116                 if (ret >= 0 && ret <= 4096) { return null; }
117                 org.ldk.structs.Input ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Input(null, ret); }
118                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
119                 return ret_hu_conv;
120         }
121
122         /**
123          * Generates a non-cryptographic 64-bit hash of the Input.
124          */
125         public long hash() {
126                 long ret = bindings.Input_hash(this.ptr);
127                 Reference.reachabilityFence(this);
128                 return ret;
129         }
130
131         @Override public int hashCode() {
132                 return (int)this.hash();
133         }
134         /**
135          * Checks if two Inputs contain equal inner contents.
136          * This ignores pointers and is_owned flags and looks at the values in fields.
137          * Two objects with NULL inner values will be considered "equal" here.
138          */
139         public boolean eq(org.ldk.structs.Input b) {
140                 boolean ret = bindings.Input_eq(this.ptr, b == null ? 0 : b.ptr);
141                 Reference.reachabilityFence(this);
142                 Reference.reachabilityFence(b);
143                 if (this != null) { this.ptrs_to.add(b); };
144                 return ret;
145         }
146
147         @Override public boolean equals(Object o) {
148                 if (!(o instanceof Input)) return false;
149                 return this.eq((Input)o);
150         }
151 }