[Java] Update auto-generated Java bindings to LDK 0.0.121
[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                  * If your wallet does not support signing PSBTs you can call `psbt.extract_tx()` to get the
56                  * unsigned transaction and then sign it with your wallet.
57                  */
58                 Result_TransactionNoneZ sign_psbt(byte[] psbt);
59         }
60         private static class LDKWalletSourceHolder { WalletSource held; }
61         public static WalletSource new_impl(WalletSourceInterface arg) {
62                 final LDKWalletSourceHolder impl_holder = new LDKWalletSourceHolder();
63                 impl_holder.held = new WalletSource(new bindings.LDKWalletSource() {
64                         @Override public long list_confirmed_utxos() {
65                                 Result_CVec_UtxoZNoneZ ret = arg.list_confirmed_utxos();
66                                 Reference.reachabilityFence(arg);
67                                 long result = ret == null ? 0 : ret.clone_ptr();
68                                 return result;
69                         }
70                         @Override public long get_change_script() {
71                                 Result_CVec_u8ZNoneZ ret = arg.get_change_script();
72                                 Reference.reachabilityFence(arg);
73                                 long result = ret == null ? 0 : ret.clone_ptr();
74                                 return result;
75                         }
76                         @Override public long sign_psbt(byte[] psbt) {
77                                 Result_TransactionNoneZ ret = arg.sign_psbt(psbt);
78                                 Reference.reachabilityFence(arg);
79                                 long result = ret == null ? 0 : ret.clone_ptr();
80                                 return result;
81                         }
82                 });
83                 return impl_holder.held;
84         }
85         /**
86          * Returns all UTXOs, with at least 1 confirmation each, that are available to spend.
87          */
88         public Result_CVec_UtxoZNoneZ list_confirmed_utxos() {
89                 long ret = bindings.WalletSource_list_confirmed_utxos(this.ptr);
90                 Reference.reachabilityFence(this);
91                 if (ret >= 0 && ret <= 4096) { return null; }
92                 Result_CVec_UtxoZNoneZ ret_hu_conv = Result_CVec_UtxoZNoneZ.constr_from_ptr(ret);
93                 return ret_hu_conv;
94         }
95
96         /**
97          * Returns a script to use for change above dust resulting from a successful coin selection
98          * attempt.
99          */
100         public Result_CVec_u8ZNoneZ get_change_script() {
101                 long ret = bindings.WalletSource_get_change_script(this.ptr);
102                 Reference.reachabilityFence(this);
103                 if (ret >= 0 && ret <= 4096) { return null; }
104                 Result_CVec_u8ZNoneZ ret_hu_conv = Result_CVec_u8ZNoneZ.constr_from_ptr(ret);
105                 return ret_hu_conv;
106         }
107
108         /**
109          * Signs and provides the full [`TxIn::script_sig`] and [`TxIn::witness`] for all inputs within
110          * the transaction known to the wallet (i.e., any provided via
111          * [`WalletSource::list_confirmed_utxos`]).
112          * 
113          * If your wallet does not support signing PSBTs you can call `psbt.extract_tx()` to get the
114          * unsigned transaction and then sign it with your wallet.
115          */
116         public Result_TransactionNoneZ sign_psbt(byte[] psbt) {
117                 long ret = bindings.WalletSource_sign_psbt(this.ptr, psbt);
118                 Reference.reachabilityFence(this);
119                 Reference.reachabilityFence(psbt);
120                 if (ret >= 0 && ret <= 4096) { return null; }
121                 Result_TransactionNoneZ ret_hu_conv = Result_TransactionNoneZ.constr_from_ptr(ret);
122                 return ret_hu_conv;
123         }
124
125 }