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 * An unspent transaction output that is available to spend resulting from a successful
13 * [`CoinSelection`] attempt.
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class Utxo extends CommonBase {
17 Utxo(Object _dummy, long ptr) { super(ptr); }
18 @Override @SuppressWarnings("deprecation")
19 protected void finalize() throws Throwable {
21 if (ptr != 0) { bindings.Utxo_free(ptr); }
25 * The unique identifier of the output.
27 public OutPoint get_outpoint() {
28 long ret = bindings.Utxo_get_outpoint(this.ptr);
29 Reference.reachabilityFence(this);
30 if (ret >= 0 && ret <= 4096) { return null; }
31 org.ldk.structs.OutPoint ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OutPoint(null, ret); }
32 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
37 * The unique identifier of the output.
39 public void set_outpoint(org.ldk.structs.OutPoint val) {
40 bindings.Utxo_set_outpoint(this.ptr, val == null ? 0 : val.ptr);
41 Reference.reachabilityFence(this);
42 Reference.reachabilityFence(val);
43 if (this != null) { this.ptrs_to.add(val); };
47 * The output to spend.
49 public TxOut get_output() {
50 long ret = bindings.Utxo_get_output(this.ptr);
51 Reference.reachabilityFence(this);
52 if (ret >= 0 && ret <= 4096) { return null; }
53 TxOut ret_conv = new TxOut(null, ret);
58 * The output to spend.
60 public void set_output(org.ldk.structs.TxOut val) {
61 bindings.Utxo_set_output(this.ptr, val.ptr);
62 Reference.reachabilityFence(this);
63 Reference.reachabilityFence(val);
67 * The upper-bound weight consumed by the input's full [`TxIn::script_sig`] and [`TxIn::witness`], each
68 * with their lengths included, required to satisfy the output's script. The weight consumed by
69 * the input's `script_sig` must account for [`WITNESS_SCALE_FACTOR`].
71 public long get_satisfaction_weight() {
72 long ret = bindings.Utxo_get_satisfaction_weight(this.ptr);
73 Reference.reachabilityFence(this);
78 * The upper-bound weight consumed by the input's full [`TxIn::script_sig`] and [`TxIn::witness`], each
79 * with their lengths included, required to satisfy the output's script. The weight consumed by
80 * the input's `script_sig` must account for [`WITNESS_SCALE_FACTOR`].
82 public void set_satisfaction_weight(long val) {
83 bindings.Utxo_set_satisfaction_weight(this.ptr, val);
84 Reference.reachabilityFence(this);
85 Reference.reachabilityFence(val);
89 * Constructs a new Utxo given each field
91 public static Utxo of(org.ldk.structs.OutPoint outpoint_arg, org.ldk.structs.TxOut output_arg, long satisfaction_weight_arg) {
92 long ret = bindings.Utxo_new(outpoint_arg == null ? 0 : outpoint_arg.ptr, output_arg.ptr, satisfaction_weight_arg);
93 Reference.reachabilityFence(outpoint_arg);
94 Reference.reachabilityFence(output_arg);
95 Reference.reachabilityFence(satisfaction_weight_arg);
96 if (ret >= 0 && ret <= 4096) { return null; }
97 org.ldk.structs.Utxo ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Utxo(null, ret); }
98 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
99 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(outpoint_arg); };
104 long ret = bindings.Utxo_clone_ptr(this.ptr);
105 Reference.reachabilityFence(this);
110 * Creates a copy of the Utxo
112 public Utxo clone() {
113 long ret = bindings.Utxo_clone(this.ptr);
114 Reference.reachabilityFence(this);
115 if (ret >= 0 && ret <= 4096) { return null; }
116 org.ldk.structs.Utxo ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Utxo(null, ret); }
117 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
122 * Generates a non-cryptographic 64-bit hash of the Utxo.
125 long ret = bindings.Utxo_hash(this.ptr);
126 Reference.reachabilityFence(this);
130 @Override public int hashCode() {
131 return (int)this.hash();
134 * Checks if two Utxos contain equal inner contents.
135 * This ignores pointers and is_owned flags and looks at the values in fields.
136 * Two objects with NULL inner values will be considered "equal" here.
138 public boolean eq(org.ldk.structs.Utxo b) {
139 boolean ret = bindings.Utxo_eq(this.ptr, b == null ? 0 : b.ptr);
140 Reference.reachabilityFence(this);
141 Reference.reachabilityFence(b);
142 if (this != null) { this.ptrs_to.add(b); };
146 @Override public boolean equals(Object o) {
147 if (!(o instanceof Utxo)) return false;
148 return this.eq((Utxo)o);
151 * Returns a `Utxo` with the `satisfaction_weight` estimate for a legacy P2PKH output.
153 public static Utxo new_p2pkh(org.ldk.structs.OutPoint outpoint, long value, byte[] pubkey_hash) {
154 long ret = bindings.Utxo_new_p2pkh(outpoint == null ? 0 : outpoint.ptr, value, InternalUtils.check_arr_len(pubkey_hash, 20));
155 Reference.reachabilityFence(outpoint);
156 Reference.reachabilityFence(value);
157 Reference.reachabilityFence(pubkey_hash);
158 if (ret >= 0 && ret <= 4096) { return null; }
159 org.ldk.structs.Utxo ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Utxo(null, ret); }
160 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
161 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(outpoint); };