X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=c_sharp%2Fsrc%2Forg%2Fldk%2Fstructs%2FWalletSource.cs;h=b8900e77c652ab4acfac4e131d638a31ded1a9a8;hb=3d1f246d05172683acd3b81836de4e4e9f0c1afd;hp=4c9182825204e4617f29ae522551a7c8a3a99141;hpb=c6777737ea14e7814b0fa7d6fe16536f31d4a82b;p=ldk-java diff --git a/c_sharp/src/org/ldk/structs/WalletSource.cs b/c_sharp/src/org/ldk/structs/WalletSource.cs index 4c918282..b8900e77 100644 --- a/c_sharp/src/org/ldk/structs/WalletSource.cs +++ b/c_sharp/src/org/ldk/structs/WalletSource.cs @@ -1,3 +1,4 @@ + using org.ldk.impl; using org.ldk.enums; using org.ldk.util; @@ -5,38 +6,40 @@ using System; namespace org { namespace ldk { namespace structs { + + +/** An implementation of WalletSource */ +public interface WalletSourceInterface { + /**Returns all UTXOs, with at least 1 confirmation each, that are available to spend. + */ + Result_CVec_UtxoZNoneZ list_confirmed_utxos(); + /**Returns a script to use for change above dust resulting from a successful coin selection + * attempt. + */ + Result_CVec_u8ZNoneZ get_change_script(); + /**Signs and provides the full [`TxIn::script_sig`] and [`TxIn::witness`] for all inputs within + * the transaction known to the wallet (i.e., any provided via + * [`WalletSource::list_confirmed_utxos`]). + * + * If your wallet does not support signing PSBTs you can call `psbt.extract_tx()` to get the + * unsigned transaction and then sign it with your wallet. + */ + Result_TransactionNoneZ sign_psbt(byte[] psbt); +} + /** * An alternative to [`CoinSelectionSource`] that can be implemented and used along [`Wallet`] to * provide a default implementation to [`CoinSelectionSource`]. */ public class WalletSource : CommonBase { - internal readonly bindings.LDKWalletSource bindings_instance; + internal bindings.LDKWalletSource bindings_instance; + internal long instance_idx; + internal WalletSource(object _dummy, long ptr) : base(ptr) { bindings_instance = null; } - private WalletSource(bindings.LDKWalletSource arg) : base(bindings.LDKWalletSource_new(arg)) { - this.ptrs_to.AddLast(arg); - this.bindings_instance = arg; - } ~WalletSource() { if (ptr != 0) { bindings.WalletSource_free(ptr); } } - public interface WalletSourceInterface { - /** - * Returns all UTXOs, with at least 1 confirmation each, that are available to spend. - */ - Result_CVec_UtxoZNoneZ list_confirmed_utxos(); - /** - * Returns a script to use for change above dust resulting from a successful coin selection - * attempt. - */ - Result_ScriptNoneZ get_change_script(); - /** - * Signs and provides the full [`TxIn::script_sig`] and [`TxIn::witness`] for all inputs within - * the transaction known to the wallet (i.e., any provided via - * [`WalletSource::list_confirmed_utxos`]). - */ - Result_TransactionNoneZ sign_tx(byte[] _tx); - } private class LDKWalletSourceHolder { internal WalletSource held; } private class LDKWalletSourceImpl : bindings.LDKWalletSource { internal LDKWalletSourceImpl(WalletSourceInterface arg, LDKWalletSourceHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; } @@ -49,23 +52,32 @@ public class WalletSource : CommonBase { return result; } public long get_change_script() { - Result_ScriptNoneZ ret = arg.get_change_script(); + Result_CVec_u8ZNoneZ ret = arg.get_change_script(); GC.KeepAlive(arg); long result = ret == null ? 0 : ret.clone_ptr(); return result; } - public long sign_tx(byte[] _tx) { - Result_TransactionNoneZ ret = arg.sign_tx(_tx); + public long sign_psbt(long _psbt) { + byte[] _psbt_conv = InternalUtils.decodeUint8Array(_psbt); + Result_TransactionNoneZ ret = arg.sign_psbt(_psbt_conv); GC.KeepAlive(arg); long result = ret == null ? 0 : ret.clone_ptr(); return result; } } + + /** Creates a new instance of WalletSource from a given implementation */ public static WalletSource new_impl(WalletSourceInterface arg) { LDKWalletSourceHolder impl_holder = new LDKWalletSourceHolder(); - impl_holder.held = new WalletSource(new LDKWalletSourceImpl(arg, impl_holder)); + LDKWalletSourceImpl impl = new LDKWalletSourceImpl(arg, impl_holder); + long[] ptr_idx = bindings.LDKWalletSource_new(impl); + + impl_holder.held = new WalletSource(null, ptr_idx[0]); + impl_holder.held.instance_idx = ptr_idx[1]; + impl_holder.held.bindings_instance = impl; return impl_holder.held; } + /** * Returns all UTXOs, with at least 1 confirmation each, that are available to spend. */ @@ -81,11 +93,11 @@ public class WalletSource : CommonBase { * Returns a script to use for change above dust resulting from a successful coin selection * attempt. */ - public Result_ScriptNoneZ get_change_script() { + public Result_CVec_u8ZNoneZ get_change_script() { long ret = bindings.WalletSource_get_change_script(this.ptr); GC.KeepAlive(this); if (ret >= 0 && ret <= 4096) { return null; } - Result_ScriptNoneZ ret_hu_conv = Result_ScriptNoneZ.constr_from_ptr(ret); + Result_CVec_u8ZNoneZ ret_hu_conv = Result_CVec_u8ZNoneZ.constr_from_ptr(ret); return ret_hu_conv; } @@ -93,11 +105,14 @@ public class WalletSource : CommonBase { * Signs and provides the full [`TxIn::script_sig`] and [`TxIn::witness`] for all inputs within * the transaction known to the wallet (i.e., any provided via * [`WalletSource::list_confirmed_utxos`]). + * + * If your wallet does not support signing PSBTs you can call `psbt.extract_tx()` to get the + * unsigned transaction and then sign it with your wallet. */ - public Result_TransactionNoneZ sign_tx(byte[] tx) { - long ret = bindings.WalletSource_sign_tx(this.ptr, tx); + public Result_TransactionNoneZ sign_psbt(byte[] psbt) { + long ret = bindings.WalletSource_sign_psbt(this.ptr, InternalUtils.encodeUint8Array(psbt)); GC.KeepAlive(this); - GC.KeepAlive(tx); + GC.KeepAlive(psbt); if (ret >= 0 && ret <= 4096) { return null; } Result_TransactionNoneZ ret_hu_conv = Result_TransactionNoneZ.constr_from_ptr(ret); return ret_hu_conv;