[TS] Update auto-generated bindings to LDK-C-Bindings 0.0.123.1
[ldk-java] / c_sharp / src / org / ldk / structs / OutputSpender.cs
1
2 using org.ldk.impl;
3 using org.ldk.enums;
4 using org.ldk.util;
5 using System;
6
7 namespace org { namespace ldk { namespace structs {
8
9
10
11 /** An implementation of OutputSpender */
12 public interface OutputSpenderInterface {
13         /**Creates a [`Transaction`] which spends the given descriptors to the given outputs, plus an
14          * output to the given change destination (if sufficient change value remains). The
15          * transaction will have a feerate, at least, of the given value.
16          * 
17          * The `locktime` argument is used to set the transaction's locktime. If `None`, the
18          * transaction will have a locktime of 0. It it recommended to set this to the current block
19          * height to avoid fee sniping, unless you have some specific reason to use a different
20          * locktime.
21          * 
22          * Returns `Err(())` if the output value is greater than the input value minus required fee,
23          * if a descriptor was duplicated, or if an output descriptor `script_pubkey`
24          * does not match the one we can spend.
25          */
26         Result_TransactionNoneZ spend_spendable_outputs(SpendableOutputDescriptor[] descriptors, TxOut[] outputs, byte[] change_destination_script, int feerate_sat_per_1000_weight, Option_u32Z locktime);
27 }
28
29 /**
30  * A trait that describes a wallet capable of creating a spending [`Transaction`] from a set of
31  * [`SpendableOutputDescriptor`]s.
32  */
33 public class OutputSpender : CommonBase {
34         internal bindings.LDKOutputSpender bindings_instance;
35         internal long instance_idx;
36
37         internal OutputSpender(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
38         ~OutputSpender() {
39                 if (ptr != 0) { bindings.OutputSpender_free(ptr); }
40         }
41
42         private class LDKOutputSpenderHolder { internal OutputSpender held; }
43         private class LDKOutputSpenderImpl : bindings.LDKOutputSpender {
44                 internal LDKOutputSpenderImpl(OutputSpenderInterface arg, LDKOutputSpenderHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
45                 private OutputSpenderInterface arg;
46                 private LDKOutputSpenderHolder impl_holder;
47                 public long spend_spendable_outputs(long _descriptors, long _outputs, long _change_destination_script, int _feerate_sat_per_1000_weight, long _locktime) {
48                         int _descriptors_conv_27_len = InternalUtils.getArrayLength(_descriptors);
49                         SpendableOutputDescriptor[] _descriptors_conv_27_arr = new SpendableOutputDescriptor[_descriptors_conv_27_len];
50                         for (int b = 0; b < _descriptors_conv_27_len; b++) {
51                                 long _descriptors_conv_27 = InternalUtils.getU64ArrayElem(_descriptors, b);
52                                 org.ldk.structs.SpendableOutputDescriptor _descriptors_conv_27_hu_conv = org.ldk.structs.SpendableOutputDescriptor.constr_from_ptr(_descriptors_conv_27);
53                                 if (_descriptors_conv_27_hu_conv != null) { _descriptors_conv_27_hu_conv.ptrs_to.AddLast(this); };
54                                 _descriptors_conv_27_arr[b] = _descriptors_conv_27_hu_conv;
55                         }
56                         bindings.free_buffer(_descriptors);
57                         int _outputs_conv_7_len = InternalUtils.getArrayLength(_outputs);
58                         TxOut[] _outputs_conv_7_arr = new TxOut[_outputs_conv_7_len];
59                         for (int h = 0; h < _outputs_conv_7_len; h++) {
60                                 long _outputs_conv_7 = InternalUtils.getU64ArrayElem(_outputs, h);
61                                 TxOut _outputs_conv_7_conv = new TxOut(null, _outputs_conv_7);
62                                 _outputs_conv_7_arr[h] = _outputs_conv_7_conv;
63                         }
64                         bindings.free_buffer(_outputs);
65                         byte[] _change_destination_script_conv = InternalUtils.decodeUint8Array(_change_destination_script);
66                         org.ldk.structs.Option_u32Z _locktime_hu_conv = org.ldk.structs.Option_u32Z.constr_from_ptr(_locktime);
67                         if (_locktime_hu_conv != null) { _locktime_hu_conv.ptrs_to.AddLast(this); };
68                         Result_TransactionNoneZ ret = arg.spend_spendable_outputs(_descriptors_conv_27_arr, _outputs_conv_7_arr, _change_destination_script_conv, _feerate_sat_per_1000_weight, _locktime_hu_conv);
69                                 GC.KeepAlive(arg);
70                         long result = ret.clone_ptr();
71                         return result;
72                 }
73         }
74
75         /** Creates a new instance of OutputSpender from a given implementation */
76         public static OutputSpender new_impl(OutputSpenderInterface arg) {
77                 LDKOutputSpenderHolder impl_holder = new LDKOutputSpenderHolder();
78                 LDKOutputSpenderImpl impl = new LDKOutputSpenderImpl(arg, impl_holder);
79                 long[] ptr_idx = bindings.LDKOutputSpender_new(impl);
80
81                 impl_holder.held = new OutputSpender(null, ptr_idx[0]);
82                 impl_holder.held.instance_idx = ptr_idx[1];
83                 impl_holder.held.bindings_instance = impl;
84                 return impl_holder.held;
85         }
86
87         /**
88          * Creates a [`Transaction`] which spends the given descriptors to the given outputs, plus an
89          * output to the given change destination (if sufficient change value remains). The
90          * transaction will have a feerate, at least, of the given value.
91          * 
92          * The `locktime` argument is used to set the transaction's locktime. If `None`, the
93          * transaction will have a locktime of 0. It it recommended to set this to the current block
94          * height to avoid fee sniping, unless you have some specific reason to use a different
95          * locktime.
96          * 
97          * Returns `Err(())` if the output value is greater than the input value minus required fee,
98          * if a descriptor was duplicated, or if an output descriptor `script_pubkey`
99          * does not match the one we can spend.
100          */
101         public Result_TransactionNoneZ spend_spendable_outputs(SpendableOutputDescriptor[] descriptors, TxOut[] outputs, byte[] change_destination_script, int feerate_sat_per_1000_weight, org.ldk.structs.Option_u32Z locktime) {
102                 long ret = bindings.OutputSpender_spend_spendable_outputs(this.ptr, InternalUtils.encodeUint64Array(InternalUtils.mapArray(descriptors, descriptors_conv_27 => descriptors_conv_27.ptr)), InternalUtils.encodeUint64Array(InternalUtils.mapArray(outputs, outputs_conv_7 => outputs_conv_7.ptr)), InternalUtils.encodeUint8Array(change_destination_script), feerate_sat_per_1000_weight, locktime.ptr);
103                 GC.KeepAlive(this);
104                 GC.KeepAlive(descriptors);
105                 GC.KeepAlive(outputs);
106                 GC.KeepAlive(change_destination_script);
107                 GC.KeepAlive(feerate_sat_per_1000_weight);
108                 GC.KeepAlive(locktime);
109                 if (ret >= 0 && ret <= 4096) { return null; }
110                 Result_TransactionNoneZ ret_hu_conv = Result_TransactionNoneZ.constr_from_ptr(ret);
111                 foreach (SpendableOutputDescriptor descriptors_conv_27 in descriptors) { if (this != null) { this.ptrs_to.AddLast(descriptors_conv_27); }; };
112                 if (this != null) { this.ptrs_to.AddLast(locktime); };
113                 return ret_hu_conv;
114         }
115
116 }
117 } } }