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 Result_TransactionNoneZ sign_tx(byte[] tx);
28 * An alternative to [`CoinSelectionSource`] that can be implemented and used along [`Wallet`] to
29 * provide a default implementation to [`CoinSelectionSource`].
31 public class WalletSource : CommonBase {
32 internal bindings.LDKWalletSource bindings_instance;
33 internal long instance_idx;
35 internal WalletSource(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
37 if (ptr != 0) { bindings.WalletSource_free(ptr); }
40 private class LDKWalletSourceHolder { internal WalletSource held; }
41 private class LDKWalletSourceImpl : bindings.LDKWalletSource {
42 internal LDKWalletSourceImpl(WalletSourceInterface arg, LDKWalletSourceHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
43 private WalletSourceInterface arg;
44 private LDKWalletSourceHolder impl_holder;
45 public long list_confirmed_utxos() {
46 Result_CVec_UtxoZNoneZ ret = arg.list_confirmed_utxos();
48 long result = ret == null ? 0 : ret.clone_ptr();
51 public long get_change_script() {
52 Result_CVec_u8ZNoneZ ret = arg.get_change_script();
54 long result = ret == null ? 0 : ret.clone_ptr();
57 public long sign_tx(long _tx) {
58 byte[] _tx_conv = InternalUtils.decodeUint8Array(_tx);
59 Result_TransactionNoneZ ret = arg.sign_tx(_tx_conv);
61 long result = ret == null ? 0 : ret.clone_ptr();
66 /** Creates a new instance of WalletSource from a given implementation */
67 public static WalletSource new_impl(WalletSourceInterface arg) {
68 LDKWalletSourceHolder impl_holder = new LDKWalletSourceHolder();
69 LDKWalletSourceImpl impl = new LDKWalletSourceImpl(arg, impl_holder);
70 long[] ptr_idx = bindings.LDKWalletSource_new(impl);
72 impl_holder.held = new WalletSource(null, ptr_idx[0]);
73 impl_holder.held.instance_idx = ptr_idx[1];
74 impl_holder.held.bindings_instance = impl;
75 return impl_holder.held;
79 * Returns all UTXOs, with at least 1 confirmation each, that are available to spend.
81 public Result_CVec_UtxoZNoneZ list_confirmed_utxos() {
82 long ret = bindings.WalletSource_list_confirmed_utxos(this.ptr);
84 if (ret >= 0 && ret <= 4096) { return null; }
85 Result_CVec_UtxoZNoneZ ret_hu_conv = Result_CVec_UtxoZNoneZ.constr_from_ptr(ret);
90 * Returns a script to use for change above dust resulting from a successful coin selection
93 public Result_CVec_u8ZNoneZ get_change_script() {
94 long ret = bindings.WalletSource_get_change_script(this.ptr);
96 if (ret >= 0 && ret <= 4096) { return null; }
97 Result_CVec_u8ZNoneZ ret_hu_conv = Result_CVec_u8ZNoneZ.constr_from_ptr(ret);
102 * Signs and provides the full [`TxIn::script_sig`] and [`TxIn::witness`] for all inputs within
103 * the transaction known to the wallet (i.e., any provided via
104 * [`WalletSource::list_confirmed_utxos`]).
106 public Result_TransactionNoneZ sign_tx(byte[] tx) {
107 long ret = bindings.WalletSource_sign_tx(this.ptr, InternalUtils.encodeUint8Array(tx));
110 if (ret >= 0 && ret <= 4096) { return null; }
111 Result_TransactionNoneZ ret_hu_conv = Result_TransactionNoneZ.constr_from_ptr(ret);