X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FWallet.java;fp=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FWallet.java;h=77be7fb7fe08927010e4865a9fd7355daa190694;hb=8fa2bcb208a51fa352d04981f1387d8bceced107;hp=0000000000000000000000000000000000000000;hpb=7da1092518e5ea1518255a4473c178f52549fd81;p=ldk-java diff --git a/src/main/java/org/ldk/structs/Wallet.java b/src/main/java/org/ldk/structs/Wallet.java new file mode 100644 index 00000000..77be7fb7 --- /dev/null +++ b/src/main/java/org/ldk/structs/Wallet.java @@ -0,0 +1,54 @@ +package org.ldk.structs; + +import org.ldk.impl.bindings; +import org.ldk.enums.*; +import org.ldk.util.*; +import java.util.Arrays; +import java.lang.ref.Reference; +import javax.annotation.Nullable; + + +/** + * A wrapper over [`WalletSource`] that implements [`CoinSelection`] by preferring UTXOs that would + * avoid conflicting double spends. If not enough UTXOs are available to do so, conflicting double + * spends may happen. + */ +@SuppressWarnings("unchecked") // We correctly assign various generic arrays +public class Wallet extends CommonBase { + Wallet(Object _dummy, long ptr) { super(ptr); } + @Override @SuppressWarnings("deprecation") + protected void finalize() throws Throwable { + super.finalize(); + if (ptr != 0) { bindings.Wallet_free(ptr); } + } + + /** + * Returns a new instance backed by the given [`WalletSource`] that serves as an implementation + * of [`CoinSelectionSource`]. + */ + public static Wallet of(org.ldk.structs.WalletSource source, org.ldk.structs.Logger logger) { + long ret = bindings.Wallet_new(source.ptr, logger.ptr); + Reference.reachabilityFence(source); + Reference.reachabilityFence(logger); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.Wallet ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Wallet(null, ret); } + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(source); }; + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); }; + return ret_hu_conv; + } + + /** + * Constructs a new CoinSelectionSource which calls the relevant methods on this_arg. + * This copies the `inner` pointer in this_arg and thus the returned CoinSelectionSource must be freed before this_arg is + */ + public CoinSelectionSource as_CoinSelectionSource() { + long ret = bindings.Wallet_as_CoinSelectionSource(this.ptr); + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } + CoinSelectionSource ret_hu_conv = new CoinSelectionSource(null, ret); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; + return ret_hu_conv; + } + +}