[C#] Update auto-generated files
[ldk-java] / c_sharp / src / org / ldk / structs / CoinSelectionSource.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  * An abstraction over a bitcoin wallet that can perform coin selection over a set of UTXOs and can
10  * sign for them. The coin selection method aims to mimic Bitcoin Core's `fundrawtransaction` RPC,
11  * which most wallets should be able to satisfy. Otherwise, consider implementing [`WalletSource`],
12  * which can provide a default implementation of this trait when used with [`Wallet`].
13  */
14 public class CoinSelectionSource : CommonBase {
15         internal readonly bindings.LDKCoinSelectionSource bindings_instance;
16         internal CoinSelectionSource(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
17         private CoinSelectionSource(bindings.LDKCoinSelectionSource arg) : base(bindings.LDKCoinSelectionSource_new(arg)) {
18                 this.ptrs_to.AddLast(arg);
19                 this.bindings_instance = arg;
20         }
21         ~CoinSelectionSource() {
22                 if (ptr != 0) { bindings.CoinSelectionSource_free(ptr); }
23         }
24
25         public interface CoinSelectionSourceInterface {
26                 /**
27                  * Performs coin selection of a set of UTXOs, with at least 1 confirmation each, that are
28                  * available to spend. Implementations are free to pick their coin selection algorithm of
29                  * choice, as long as the following requirements are met:
30                  * 
31                  * 1. `must_spend` contains a set of [`Input`]s that must be included in the transaction
32                  * throughout coin selection, but must not be returned as part of the result.
33                  * 2. `must_pay_to` contains a set of [`TxOut`]s that must be included in the transaction
34                  * throughout coin selection. In some cases, like when funding an anchor transaction, this
35                  * set is empty. Implementations should ensure they handle this correctly on their end,
36                  * e.g., Bitcoin Core's `fundrawtransaction` RPC requires at least one output to be
37                  * provided, in which case a zero-value empty OP_RETURN output can be used instead.
38                  * 3. Enough inputs must be selected/contributed for the resulting transaction (including the
39                  * inputs and outputs noted above) to meet `target_feerate_sat_per_1000_weight`.
40                  * 
41                  * Implementations must take note that [`Input::satisfaction_weight`] only tracks the weight of
42                  * the input's `script_sig` and `witness`. Some wallets, like Bitcoin Core's, may require
43                  * providing the full input weight. Failing to do so may lead to underestimating fee bumps and
44                  * delaying block inclusion.
45                  * 
46                  * The `claim_id` must map to the set of external UTXOs assigned to the claim, such that they
47                  * can be re-used within new fee-bumped iterations of the original claiming transaction,
48                  * ensuring that claims don't double spend each other. If a specific `claim_id` has never had a
49                  * transaction associated with it, and all of the available UTXOs have already been assigned to
50                  * other claims, implementations must be willing to double spend their UTXOs. The choice of
51                  * which UTXOs to double spend is left to the implementation, but it must strive to keep the
52                  * set of other claims being double spent to a minimum.
53                  */
54                 Result_CoinSelectionNoneZ select_confirmed_utxos(byte[] _claim_id, Input[] _must_spend, TxOut[] _must_pay_to, int _target_feerate_sat_per_1000_weight);
55                 /**
56                  * Signs and provides the full witness for all inputs within the transaction known to the
57                  * trait (i.e., any provided via [`CoinSelectionSource::select_confirmed_utxos`]).
58                  */
59                 Result_TransactionNoneZ sign_tx(byte[] _tx);
60         }
61         private class LDKCoinSelectionSourceHolder { internal CoinSelectionSource held; }
62         private class LDKCoinSelectionSourceImpl : bindings.LDKCoinSelectionSource {
63                 internal LDKCoinSelectionSourceImpl(CoinSelectionSourceInterface arg, LDKCoinSelectionSourceHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
64                 private CoinSelectionSourceInterface arg;
65                 private LDKCoinSelectionSourceHolder impl_holder;
66                 public long select_confirmed_utxos(byte[] _claim_id, long[] _must_spend, long[] _must_pay_to, int _target_feerate_sat_per_1000_weight) {
67                         int _must_spend_conv_7_len = _must_spend.Length;
68                         Input[] _must_spend_conv_7_arr = new Input[_must_spend_conv_7_len];
69                         for (int h = 0; h < _must_spend_conv_7_len; h++) {
70                                 long _must_spend_conv_7 = _must_spend[h];
71                                 org.ldk.structs.Input _must_spend_conv_7_hu_conv = null; if (_must_spend_conv_7 < 0 || _must_spend_conv_7 > 4096) { _must_spend_conv_7_hu_conv = new org.ldk.structs.Input(null, _must_spend_conv_7); }
72                                 if (_must_spend_conv_7_hu_conv != null) { _must_spend_conv_7_hu_conv.ptrs_to.AddLast(this); };
73                                 _must_spend_conv_7_arr[h] = _must_spend_conv_7_hu_conv;
74                         }
75                         int _must_pay_to_conv_7_len = _must_pay_to.Length;
76                         TxOut[] _must_pay_to_conv_7_arr = new TxOut[_must_pay_to_conv_7_len];
77                         for (int h = 0; h < _must_pay_to_conv_7_len; h++) {
78                                 long _must_pay_to_conv_7 = _must_pay_to[h];
79                                 TxOut _must_pay_to_conv_7_conv = new TxOut(null, _must_pay_to_conv_7);
80                                 _must_pay_to_conv_7_arr[h] = _must_pay_to_conv_7_conv;
81                         }
82                         Result_CoinSelectionNoneZ ret = arg.select_confirmed_utxos(_claim_id, _must_spend_conv_7_arr, _must_pay_to_conv_7_arr, _target_feerate_sat_per_1000_weight);
83                                 GC.KeepAlive(arg);
84                         long result = ret == null ? 0 : ret.clone_ptr();
85                         return result;
86                 }
87                 public long sign_tx(byte[] _tx) {
88                         Result_TransactionNoneZ ret = arg.sign_tx(_tx);
89                                 GC.KeepAlive(arg);
90                         long result = ret == null ? 0 : ret.clone_ptr();
91                         return result;
92                 }
93         }
94         public static CoinSelectionSource new_impl(CoinSelectionSourceInterface arg) {
95                 LDKCoinSelectionSourceHolder impl_holder = new LDKCoinSelectionSourceHolder();
96                 impl_holder.held = new CoinSelectionSource(new LDKCoinSelectionSourceImpl(arg, impl_holder));
97                 return impl_holder.held;
98         }
99         /**
100          * Performs coin selection of a set of UTXOs, with at least 1 confirmation each, that are
101          * available to spend. Implementations are free to pick their coin selection algorithm of
102          * choice, as long as the following requirements are met:
103          * 
104          * 1. `must_spend` contains a set of [`Input`]s that must be included in the transaction
105          * throughout coin selection, but must not be returned as part of the result.
106          * 2. `must_pay_to` contains a set of [`TxOut`]s that must be included in the transaction
107          * throughout coin selection. In some cases, like when funding an anchor transaction, this
108          * set is empty. Implementations should ensure they handle this correctly on their end,
109          * e.g., Bitcoin Core's `fundrawtransaction` RPC requires at least one output to be
110          * provided, in which case a zero-value empty OP_RETURN output can be used instead.
111          * 3. Enough inputs must be selected/contributed for the resulting transaction (including the
112          * inputs and outputs noted above) to meet `target_feerate_sat_per_1000_weight`.
113          * 
114          * Implementations must take note that [`Input::satisfaction_weight`] only tracks the weight of
115          * the input's `script_sig` and `witness`. Some wallets, like Bitcoin Core's, may require
116          * providing the full input weight. Failing to do so may lead to underestimating fee bumps and
117          * delaying block inclusion.
118          * 
119          * The `claim_id` must map to the set of external UTXOs assigned to the claim, such that they
120          * can be re-used within new fee-bumped iterations of the original claiming transaction,
121          * ensuring that claims don't double spend each other. If a specific `claim_id` has never had a
122          * transaction associated with it, and all of the available UTXOs have already been assigned to
123          * other claims, implementations must be willing to double spend their UTXOs. The choice of
124          * which UTXOs to double spend is left to the implementation, but it must strive to keep the
125          * set of other claims being double spent to a minimum.
126          */
127         public Result_CoinSelectionNoneZ select_confirmed_utxos(byte[] claim_id, Input[] must_spend, TxOut[] must_pay_to, int target_feerate_sat_per_1000_weight) {
128                 long ret = bindings.CoinSelectionSource_select_confirmed_utxos(this.ptr, InternalUtils.check_arr_len(claim_id, 32), must_spend != null ? InternalUtils.mapArray(must_spend, must_spend_conv_7 => must_spend_conv_7 == null ? 0 : must_spend_conv_7.ptr) : null, must_pay_to != null ? InternalUtils.mapArray(must_pay_to, must_pay_to_conv_7 => must_pay_to_conv_7.ptr) : null, target_feerate_sat_per_1000_weight);
129                 GC.KeepAlive(this);
130                 GC.KeepAlive(claim_id);
131                 GC.KeepAlive(must_spend);
132                 GC.KeepAlive(must_pay_to);
133                 GC.KeepAlive(target_feerate_sat_per_1000_weight);
134                 if (ret >= 0 && ret <= 4096) { return null; }
135                 Result_CoinSelectionNoneZ ret_hu_conv = Result_CoinSelectionNoneZ.constr_from_ptr(ret);
136                 foreach (Input must_spend_conv_7 in must_spend) { if (this != null) { this.ptrs_to.AddLast(must_spend_conv_7); }; };
137                 return ret_hu_conv;
138         }
139
140         /**
141          * Signs and provides the full witness for all inputs within the transaction known to the
142          * trait (i.e., any provided via [`CoinSelectionSource::select_confirmed_utxos`]).
143          */
144         public Result_TransactionNoneZ sign_tx(byte[] tx) {
145                 long ret = bindings.CoinSelectionSource_sign_tx(this.ptr, tx);
146                 GC.KeepAlive(this);
147                 GC.KeepAlive(tx);
148                 if (ret >= 0 && ret <= 4096) { return null; }
149                 Result_TransactionNoneZ ret_hu_conv = Result_TransactionNoneZ.constr_from_ptr(ret);
150                 return ret_hu_conv;
151         }
152
153 }
154 } } }