Merge pull request #139 from TheBlueMatt/main
[ldk-java] / c_sharp / src / org / ldk / structs / CoinSelection.cs
1 using org.ldk.impl;
2 using org.ldk.enums;
3 using org.ldk.util;
4 using System;
5
6 namespace org { namespace ldk { namespace structs {
7
8
9 /**
10  * The result of a successful coin selection attempt for a transaction requiring additional UTXOs
11  * to cover its fees.
12  */
13 public class CoinSelection : CommonBase {
14         internal CoinSelection(object _dummy, long ptr) : base(ptr) { }
15         ~CoinSelection() {
16                 if (ptr != 0) { bindings.CoinSelection_free(ptr); }
17         }
18
19         /**
20          * The set of UTXOs (with at least 1 confirmation) to spend and use within a transaction
21          * requiring additional fees.
22          */
23         public Utxo[] get_confirmed_utxos() {
24                 long[] ret = bindings.CoinSelection_get_confirmed_utxos(this.ptr);
25                 GC.KeepAlive(this);
26                 int ret_conv_6_len = ret.Length;
27                 Utxo[] ret_conv_6_arr = new Utxo[ret_conv_6_len];
28                 for (int g = 0; g < ret_conv_6_len; g++) {
29                         long ret_conv_6 = ret[g];
30                         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); }
31                         if (ret_conv_6_hu_conv != null) { ret_conv_6_hu_conv.ptrs_to.AddLast(this); };
32                         ret_conv_6_arr[g] = ret_conv_6_hu_conv;
33                 }
34                 return ret_conv_6_arr;
35         }
36
37         /**
38          * The set of UTXOs (with at least 1 confirmation) to spend and use within a transaction
39          * requiring additional fees.
40          */
41         public void set_confirmed_utxos(Utxo[] val) {
42                 bindings.CoinSelection_set_confirmed_utxos(this.ptr, val != null ? InternalUtils.mapArray(val, val_conv_6 => val_conv_6 == null ? 0 : val_conv_6.ptr) : null);
43                 GC.KeepAlive(this);
44                 GC.KeepAlive(val);
45                 foreach (Utxo val_conv_6 in val) { if (this != null) { this.ptrs_to.AddLast(val_conv_6); }; };
46         }
47
48         /**
49          * An additional output tracking whether any change remained after coin selection. This output
50          * should always have a value above dust for its given `script_pubkey`. It should not be
51          * spent until the transaction it belongs to confirms to ensure mempool descendant limits are
52          * not met. This implies no other party should be able to spend it except us.
53          */
54         public Option_TxOutZ get_change_output() {
55                 long ret = bindings.CoinSelection_get_change_output(this.ptr);
56                 GC.KeepAlive(this);
57                 if (ret >= 0 && ret <= 4096) { return null; }
58                 org.ldk.structs.Option_TxOutZ ret_hu_conv = org.ldk.structs.Option_TxOutZ.constr_from_ptr(ret);
59                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
60                 return ret_hu_conv;
61         }
62
63         /**
64          * An additional output tracking whether any change remained after coin selection. This output
65          * should always have a value above dust for its given `script_pubkey`. It should not be
66          * spent until the transaction it belongs to confirms to ensure mempool descendant limits are
67          * not met. This implies no other party should be able to spend it except us.
68          */
69         public void set_change_output(org.ldk.structs.Option_TxOutZ val) {
70                 bindings.CoinSelection_set_change_output(this.ptr, val.ptr);
71                 GC.KeepAlive(this);
72                 GC.KeepAlive(val);
73                 if (this != null) { this.ptrs_to.AddLast(val); };
74         }
75
76         /**
77          * Constructs a new CoinSelection given each field
78          */
79         public static CoinSelection of(Utxo[] confirmed_utxos_arg, org.ldk.structs.Option_TxOutZ change_output_arg) {
80                 long ret = bindings.CoinSelection_new(confirmed_utxos_arg != null ? InternalUtils.mapArray(confirmed_utxos_arg, confirmed_utxos_arg_conv_6 => confirmed_utxos_arg_conv_6 == null ? 0 : confirmed_utxos_arg_conv_6.ptr) : null, change_output_arg.ptr);
81                 GC.KeepAlive(confirmed_utxos_arg);
82                 GC.KeepAlive(change_output_arg);
83                 if (ret >= 0 && ret <= 4096) { return null; }
84                 org.ldk.structs.CoinSelection ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.CoinSelection(null, ret); }
85                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
86                 foreach (Utxo confirmed_utxos_arg_conv_6 in confirmed_utxos_arg) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(confirmed_utxos_arg_conv_6); }; };
87                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(change_output_arg); };
88                 return ret_hu_conv;
89         }
90
91         internal long clone_ptr() {
92                 long ret = bindings.CoinSelection_clone_ptr(this.ptr);
93                 GC.KeepAlive(this);
94                 return ret;
95         }
96
97         /**
98          * Creates a copy of the CoinSelection
99          */
100         public CoinSelection clone() {
101                 long ret = bindings.CoinSelection_clone(this.ptr);
102                 GC.KeepAlive(this);
103                 if (ret >= 0 && ret <= 4096) { return null; }
104                 org.ldk.structs.CoinSelection ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.CoinSelection(null, ret); }
105                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
106                 return ret_hu_conv;
107         }
108
109 }
110 } } }