[Java] Update auto-generated bindings to 0.0.117
[ldk-java] / src / main / java / org / ldk / structs / WalletSource.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  * An alternative to [`CoinSelectionSource`] that can be implemented and used along [`Wallet`] to
12  * provide a default implementation to [`CoinSelectionSource`].
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class WalletSource extends CommonBase {
16         final bindings.LDKWalletSource bindings_instance;
17         WalletSource(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
18         private WalletSource(bindings.LDKWalletSource arg) {
19                 super(bindings.LDKWalletSource_new(arg));
20                 this.ptrs_to.add(arg);
21                 this.bindings_instance = arg;
22         }
23         @Override @SuppressWarnings("deprecation")
24         protected void finalize() throws Throwable {
25                 if (ptr != 0) { bindings.WalletSource_free(ptr); } super.finalize();
26         }
27         /**
28          * Destroys the object, freeing associated resources. After this call, any access
29          * to this object may result in a SEGFAULT or worse.
30          *
31          * You should generally NEVER call this method. You should let the garbage collector
32          * do this for you when it finalizes objects. However, it may be useful for types
33          * which represent locks and should be closed immediately to avoid holding locks
34          * until the GC runs.
35          */
36         public void destroy() {
37                 if (ptr != 0) { bindings.WalletSource_free(ptr); }
38                 ptr = 0;
39         }
40         public static interface WalletSourceInterface {
41                 /**
42                  * Returns all UTXOs, with at least 1 confirmation each, that are available to spend.
43                  */
44                 Result_CVec_UtxoZNoneZ list_confirmed_utxos();
45                 /**
46                  * Returns a script to use for change above dust resulting from a successful coin selection
47                  * attempt.
48                  */
49                 Result_CVec_u8ZNoneZ get_change_script();
50                 /**
51                  * Signs and provides the full [`TxIn::script_sig`] and [`TxIn::witness`] for all inputs within
52                  * the transaction known to the wallet (i.e., any provided via
53                  * [`WalletSource::list_confirmed_utxos`]).
54                  */
55                 Result_TransactionNoneZ sign_tx(byte[] tx);
56         }
57         private static class LDKWalletSourceHolder { WalletSource held; }
58         public static WalletSource new_impl(WalletSourceInterface arg) {
59                 final LDKWalletSourceHolder impl_holder = new LDKWalletSourceHolder();
60                 impl_holder.held = new WalletSource(new bindings.LDKWalletSource() {
61                         @Override public long list_confirmed_utxos() {
62                                 Result_CVec_UtxoZNoneZ ret = arg.list_confirmed_utxos();
63                                 Reference.reachabilityFence(arg);
64                                 long result = ret == null ? 0 : ret.clone_ptr();
65                                 return result;
66                         }
67                         @Override public long get_change_script() {
68                                 Result_CVec_u8ZNoneZ ret = arg.get_change_script();
69                                 Reference.reachabilityFence(arg);
70                                 long result = ret == null ? 0 : ret.clone_ptr();
71                                 return result;
72                         }
73                         @Override public long sign_tx(byte[] tx) {
74                                 Result_TransactionNoneZ ret = arg.sign_tx(tx);
75                                 Reference.reachabilityFence(arg);
76                                 long result = ret == null ? 0 : ret.clone_ptr();
77                                 return result;
78                         }
79                 });
80                 return impl_holder.held;
81         }
82         /**
83          * Returns all UTXOs, with at least 1 confirmation each, that are available to spend.
84          */
85         public Result_CVec_UtxoZNoneZ list_confirmed_utxos() {
86                 long ret = bindings.WalletSource_list_confirmed_utxos(this.ptr);
87                 Reference.reachabilityFence(this);
88                 if (ret >= 0 && ret <= 4096) { return null; }
89                 Result_CVec_UtxoZNoneZ ret_hu_conv = Result_CVec_UtxoZNoneZ.constr_from_ptr(ret);
90                 return ret_hu_conv;
91         }
92
93         /**
94          * Returns a script to use for change above dust resulting from a successful coin selection
95          * attempt.
96          */
97         public Result_CVec_u8ZNoneZ get_change_script() {
98                 long ret = bindings.WalletSource_get_change_script(this.ptr);
99                 Reference.reachabilityFence(this);
100                 if (ret >= 0 && ret <= 4096) { return null; }
101                 Result_CVec_u8ZNoneZ ret_hu_conv = Result_CVec_u8ZNoneZ.constr_from_ptr(ret);
102                 return ret_hu_conv;
103         }
104
105         /**
106          * Signs and provides the full [`TxIn::script_sig`] and [`TxIn::witness`] for all inputs within
107          * the transaction known to the wallet (i.e., any provided via
108          * [`WalletSource::list_confirmed_utxos`]).
109          */
110         public Result_TransactionNoneZ sign_tx(byte[] tx) {
111                 long ret = bindings.WalletSource_sign_tx(this.ptr, tx);
112                 Reference.reachabilityFence(this);
113                 Reference.reachabilityFence(tx);
114                 if (ret >= 0 && ret <= 4096) { return null; }
115                 Result_TransactionNoneZ ret_hu_conv = Result_TransactionNoneZ.constr_from_ptr(ret);
116                 return ret_hu_conv;
117         }
118
119 }