1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * The result of a [`UtxoLookup::get_utxo`] call. A call may resolve either synchronously,
13 * returning the `Sync` variant, or asynchronously, returning an [`UtxoFuture`] in the `Async`
16 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
17 public class UtxoResult extends CommonBase {
18 private UtxoResult(Object _dummy, long ptr) { super(ptr); }
19 @Override @SuppressWarnings("deprecation")
20 protected void finalize() throws Throwable {
22 if (ptr != 0) { bindings.UtxoResult_free(ptr); }
24 static UtxoResult constr_from_ptr(long ptr) {
25 bindings.LDKUtxoResult raw_val = bindings.LDKUtxoResult_ref_from_ptr(ptr);
26 if (raw_val.getClass() == bindings.LDKUtxoResult.Sync.class) {
27 return new Sync(ptr, (bindings.LDKUtxoResult.Sync)raw_val);
29 if (raw_val.getClass() == bindings.LDKUtxoResult.Async.class) {
30 return new Async(ptr, (bindings.LDKUtxoResult.Async)raw_val);
32 assert false; return null; // Unreachable without extending the (internal) bindings interface
36 * A result which was resolved synchronously. It either includes a [`TxOut`] for the output
37 * requested or a [`UtxoLookupError`].
39 public final static class Sync extends UtxoResult {
40 public final org.ldk.structs.Result_TxOutUtxoLookupErrorZ sync;
41 private Sync(long ptr, bindings.LDKUtxoResult.Sync obj) {
44 Result_TxOutUtxoLookupErrorZ sync_hu_conv = Result_TxOutUtxoLookupErrorZ.constr_from_ptr(sync);
45 this.sync = sync_hu_conv;
49 * A result which will be resolved asynchronously. It includes a [`UtxoFuture`], a `clone` of
50 * which you must keep locally and call [`UtxoFuture::resolve`] on once the lookup completes.
52 * Note that in order to avoid runaway memory usage, the number of parallel checks is limited,
53 * but only fairly loosely. Because a pending checks block all message processing, leaving
54 * checks pending for an extended time may cause DoS of other functions. It is recommended you
55 * keep a tight timeout on lookups, on the order of a few seconds.
57 public final static class Async extends UtxoResult {
58 public final org.ldk.structs.UtxoFuture async;
59 private Async(long ptr, bindings.LDKUtxoResult.Async obj) {
61 long async = obj.async;
62 org.ldk.structs.UtxoFuture async_hu_conv = null; if (async < 0 || async > 4096) { async_hu_conv = new org.ldk.structs.UtxoFuture(null, async); }
63 if (async_hu_conv != null) { async_hu_conv.ptrs_to.add(this); };
64 this.async = async_hu_conv;
68 long ret = bindings.UtxoResult_clone_ptr(this.ptr);
69 Reference.reachabilityFence(this);
74 * Creates a copy of the UtxoResult
76 public UtxoResult clone() {
77 long ret = bindings.UtxoResult_clone(this.ptr);
78 Reference.reachabilityFence(this);
79 if (ret >= 0 && ret <= 4096) { return null; }
80 org.ldk.structs.UtxoResult ret_hu_conv = org.ldk.structs.UtxoResult.constr_from_ptr(ret);
81 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
86 * Utility method to constructs a new Sync-variant UtxoResult
88 public static UtxoResult sync(org.ldk.structs.Result_TxOutUtxoLookupErrorZ a) {
89 long ret = bindings.UtxoResult_sync(a.ptr);
90 Reference.reachabilityFence(a);
91 if (ret >= 0 && ret <= 4096) { return null; }
92 org.ldk.structs.UtxoResult ret_hu_conv = org.ldk.structs.UtxoResult.constr_from_ptr(ret);
93 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
98 * Utility method to constructs a new Async-variant UtxoResult
100 public static UtxoResult async(org.ldk.structs.UtxoFuture a) {
101 long ret = bindings.UtxoResult_async(a.ptr);
102 Reference.reachabilityFence(a);
103 if (ret >= 0 && ret <= 4096) { return null; }
104 org.ldk.structs.UtxoResult ret_hu_conv = org.ldk.structs.UtxoResult.constr_from_ptr(ret);
105 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
106 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };