7 namespace org { namespace ldk { namespace structs {
11 /** An implementation of WalletSource */
12 public interface WalletSourceInterface {
13 /**Returns all UTXOs, with at least 1 confirmation each, that are available to spend.
15 Result_CVec_UtxoZNoneZ list_confirmed_utxos();
16 /**Returns a script to use for change above dust resulting from a successful coin selection
19 Result_CVec_u8ZNoneZ get_change_script();
20 /**Signs and provides the full [`TxIn::script_sig`] and [`TxIn::witness`] for all inputs within
21 * the transaction known to the wallet (i.e., any provided via
22 * [`WalletSource::list_confirmed_utxos`]).
24 * If your wallet does not support signing PSBTs you can call `psbt.extract_tx()` to get the
25 * unsigned transaction and then sign it with your wallet.
27 Result_TransactionNoneZ sign_psbt(byte[] psbt);
31 * An alternative to [`CoinSelectionSource`] that can be implemented and used along [`Wallet`] to
32 * provide a default implementation to [`CoinSelectionSource`].
34 public class WalletSource : CommonBase {
35 internal bindings.LDKWalletSource bindings_instance;
36 internal long instance_idx;
38 internal WalletSource(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
40 if (ptr != 0) { bindings.WalletSource_free(ptr); }
43 private class LDKWalletSourceHolder { internal WalletSource held; }
44 private class LDKWalletSourceImpl : bindings.LDKWalletSource {
45 internal LDKWalletSourceImpl(WalletSourceInterface arg, LDKWalletSourceHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
46 private WalletSourceInterface arg;
47 private LDKWalletSourceHolder impl_holder;
48 public long list_confirmed_utxos() {
49 Result_CVec_UtxoZNoneZ ret = arg.list_confirmed_utxos();
51 long result = ret == null ? 0 : ret.clone_ptr();
54 public long get_change_script() {
55 Result_CVec_u8ZNoneZ ret = arg.get_change_script();
57 long result = ret == null ? 0 : ret.clone_ptr();
60 public long sign_psbt(long _psbt) {
61 byte[] _psbt_conv = InternalUtils.decodeUint8Array(_psbt);
62 Result_TransactionNoneZ ret = arg.sign_psbt(_psbt_conv);
64 long result = ret == null ? 0 : ret.clone_ptr();
69 /** Creates a new instance of WalletSource from a given implementation */
70 public static WalletSource new_impl(WalletSourceInterface arg) {
71 LDKWalletSourceHolder impl_holder = new LDKWalletSourceHolder();
72 LDKWalletSourceImpl impl = new LDKWalletSourceImpl(arg, impl_holder);
73 long[] ptr_idx = bindings.LDKWalletSource_new(impl);
75 impl_holder.held = new WalletSource(null, ptr_idx[0]);
76 impl_holder.held.instance_idx = ptr_idx[1];
77 impl_holder.held.bindings_instance = impl;
78 return impl_holder.held;
82 * Returns all UTXOs, with at least 1 confirmation each, that are available to spend.
84 public Result_CVec_UtxoZNoneZ list_confirmed_utxos() {
85 long ret = bindings.WalletSource_list_confirmed_utxos(this.ptr);
87 if (ret >= 0 && ret <= 4096) { return null; }
88 Result_CVec_UtxoZNoneZ ret_hu_conv = Result_CVec_UtxoZNoneZ.constr_from_ptr(ret);
93 * Returns a script to use for change above dust resulting from a successful coin selection
96 public Result_CVec_u8ZNoneZ get_change_script() {
97 long ret = bindings.WalletSource_get_change_script(this.ptr);
99 if (ret >= 0 && ret <= 4096) { return null; }
100 Result_CVec_u8ZNoneZ ret_hu_conv = Result_CVec_u8ZNoneZ.constr_from_ptr(ret);
105 * Signs and provides the full [`TxIn::script_sig`] and [`TxIn::witness`] for all inputs within
106 * the transaction known to the wallet (i.e., any provided via
107 * [`WalletSource::list_confirmed_utxos`]).
109 * If your wallet does not support signing PSBTs you can call `psbt.extract_tx()` to get the
110 * unsigned transaction and then sign it with your wallet.
112 public Result_TransactionNoneZ sign_psbt(byte[] psbt) {
113 long ret = bindings.WalletSource_sign_psbt(this.ptr, InternalUtils.encodeUint8Array(psbt));
116 if (ret >= 0 && ret <= 4096) { return null; }
117 Result_TransactionNoneZ ret_hu_conv = Result_TransactionNoneZ.constr_from_ptr(ret);