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;
11 * The `UtxoLookup` trait defines behavior for accessing on-chain UTXOs.
13 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
14 public class UtxoLookup extends CommonBase {
15 final bindings.LDKUtxoLookup bindings_instance;
16 UtxoLookup(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
17 private UtxoLookup(bindings.LDKUtxoLookup arg) {
18 super(bindings.LDKUtxoLookup_new(arg));
19 this.ptrs_to.add(arg);
20 this.bindings_instance = arg;
22 @Override @SuppressWarnings("deprecation")
23 protected void finalize() throws Throwable {
24 if (ptr != 0) { bindings.UtxoLookup_free(ptr); } super.finalize();
27 * Destroys the object, freeing associated resources. After this call, any access
28 * to this object may result in a SEGFAULT or worse.
30 * You should generally NEVER call this method. You should let the garbage collector
31 * do this for you when it finalizes objects. However, it may be useful for types
32 * which represent locks and should be closed immediately to avoid holding locks
35 public void destroy() {
36 if (ptr != 0) { bindings.UtxoLookup_free(ptr); }
39 public static interface UtxoLookupInterface {
41 * Returns the transaction output of a funding transaction encoded by [`short_channel_id`].
42 * Returns an error if `chain_hash` is for a different chain or if such a transaction output is
45 * [`short_channel_id`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#definition-of-short_channel_id
47 UtxoResult get_utxo(byte[] chain_hash, long short_channel_id);
49 private static class LDKUtxoLookupHolder { UtxoLookup held; }
50 public static UtxoLookup new_impl(UtxoLookupInterface arg) {
51 final LDKUtxoLookupHolder impl_holder = new LDKUtxoLookupHolder();
52 impl_holder.held = new UtxoLookup(new bindings.LDKUtxoLookup() {
53 @Override public long get_utxo(byte[] chain_hash, long short_channel_id) {
54 UtxoResult ret = arg.get_utxo(chain_hash, short_channel_id);
55 Reference.reachabilityFence(arg);
56 long result = ret == null ? 0 : ret.clone_ptr();
57 if (impl_holder.held != null) { impl_holder.held.ptrs_to.add(ret); };
61 return impl_holder.held;
64 * Returns the transaction output of a funding transaction encoded by [`short_channel_id`].
65 * Returns an error if `chain_hash` is for a different chain or if such a transaction output is
68 * [`short_channel_id`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#definition-of-short_channel_id
70 public UtxoResult get_utxo(byte[] chain_hash, long short_channel_id) {
71 long ret = bindings.UtxoLookup_get_utxo(this.ptr, InternalUtils.check_arr_len(chain_hash, 32), short_channel_id);
72 Reference.reachabilityFence(this);
73 Reference.reachabilityFence(chain_hash);
74 Reference.reachabilityFence(short_channel_id);
75 if (ret >= 0 && ret <= 4096) { return null; }
76 org.ldk.structs.UtxoResult ret_hu_conv = org.ldk.structs.UtxoResult.constr_from_ptr(ret);
77 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };