f9ec64959ea26704e5aacea8bdeff8c4d60bd20a
[ldk-java] / src / main / java / org / ldk / structs / CoinSelection.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  * The result of a successful coin selection attempt for a transaction requiring additional UTXOs
13  * to cover its fees.
14  */
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class CoinSelection extends CommonBase {
17         CoinSelection(Object _dummy, long ptr) { super(ptr); }
18         @Override @SuppressWarnings("deprecation")
19         protected void finalize() throws Throwable {
20                 super.finalize();
21                 if (ptr != 0) { bindings.CoinSelection_free(ptr); }
22         }
23
24         /**
25          * The set of UTXOs (with at least 1 confirmation) to spend and use within a transaction
26          * requiring additional fees.
27          */
28         public Utxo[] get_confirmed_utxos() {
29                 long[] ret = bindings.CoinSelection_get_confirmed_utxos(this.ptr);
30                 Reference.reachabilityFence(this);
31                 int ret_conv_6_len = ret.length;
32                 Utxo[] ret_conv_6_arr = new Utxo[ret_conv_6_len];
33                 for (int g = 0; g < ret_conv_6_len; g++) {
34                         long ret_conv_6 = ret[g];
35                         org.ldk.structs.Utxo ret_conv_6_hu_conv = null; if (ret_conv_6 < 0 || ret_conv_6 > 4096) { ret_conv_6_hu_conv = new org.ldk.structs.Utxo(null, ret_conv_6); }
36                         if (ret_conv_6_hu_conv != null) { ret_conv_6_hu_conv.ptrs_to.add(this); };
37                         ret_conv_6_arr[g] = ret_conv_6_hu_conv;
38                 }
39                 return ret_conv_6_arr;
40         }
41
42         /**
43          * The set of UTXOs (with at least 1 confirmation) to spend and use within a transaction
44          * requiring additional fees.
45          */
46         public void set_confirmed_utxos(Utxo[] val) {
47                 bindings.CoinSelection_set_confirmed_utxos(this.ptr, val != null ? Arrays.stream(val).mapToLong(val_conv_6 -> val_conv_6 == null ? 0 : val_conv_6.ptr).toArray() : null);
48                 Reference.reachabilityFence(this);
49                 Reference.reachabilityFence(val);
50                 for (Utxo val_conv_6: val) { if (this != null) { this.ptrs_to.add(val_conv_6); }; };
51         }
52
53         /**
54          * An additional output tracking whether any change remained after coin selection. This output
55          * should always have a value above dust for its given `script_pubkey`. It should not be
56          * spent until the transaction it belongs to confirms to ensure mempool descendant limits are
57          * not met. This implies no other party should be able to spend it except us.
58          */
59         public Option_TxOutZ get_change_output() {
60                 long ret = bindings.CoinSelection_get_change_output(this.ptr);
61                 Reference.reachabilityFence(this);
62                 if (ret >= 0 && ret <= 4096) { return null; }
63                 org.ldk.structs.Option_TxOutZ ret_hu_conv = org.ldk.structs.Option_TxOutZ.constr_from_ptr(ret);
64                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
65                 return ret_hu_conv;
66         }
67
68         /**
69          * An additional output tracking whether any change remained after coin selection. This output
70          * should always have a value above dust for its given `script_pubkey`. It should not be
71          * spent until the transaction it belongs to confirms to ensure mempool descendant limits are
72          * not met. This implies no other party should be able to spend it except us.
73          */
74         public void set_change_output(org.ldk.structs.Option_TxOutZ val) {
75                 bindings.CoinSelection_set_change_output(this.ptr, val.ptr);
76                 Reference.reachabilityFence(this);
77                 Reference.reachabilityFence(val);
78                 if (this != null) { this.ptrs_to.add(val); };
79         }
80
81         /**
82          * Constructs a new CoinSelection given each field
83          */
84         public static CoinSelection of(Utxo[] confirmed_utxos_arg, org.ldk.structs.Option_TxOutZ change_output_arg) {
85                 long ret = bindings.CoinSelection_new(confirmed_utxos_arg != null ? Arrays.stream(confirmed_utxos_arg).mapToLong(confirmed_utxos_arg_conv_6 -> confirmed_utxos_arg_conv_6 == null ? 0 : confirmed_utxos_arg_conv_6.ptr).toArray() : null, change_output_arg.ptr);
86                 Reference.reachabilityFence(confirmed_utxos_arg);
87                 Reference.reachabilityFence(change_output_arg);
88                 if (ret >= 0 && ret <= 4096) { return null; }
89                 org.ldk.structs.CoinSelection ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.CoinSelection(null, ret); }
90                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
91                 for (Utxo confirmed_utxos_arg_conv_6: confirmed_utxos_arg) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(confirmed_utxos_arg_conv_6); }; };
92                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(change_output_arg); };
93                 return ret_hu_conv;
94         }
95
96         long clone_ptr() {
97                 long ret = bindings.CoinSelection_clone_ptr(this.ptr);
98                 Reference.reachabilityFence(this);
99                 return ret;
100         }
101
102         /**
103          * Creates a copy of the CoinSelection
104          */
105         public CoinSelection clone() {
106                 long ret = bindings.CoinSelection_clone(this.ptr);
107                 Reference.reachabilityFence(this);
108                 if (ret >= 0 && ret <= 4096) { return null; }
109                 org.ldk.structs.CoinSelection ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.CoinSelection(null, ret); }
110                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
111                 return ret_hu_conv;
112         }
113
114 }