6087060d97cd03f887dbfeff647fbf84e2b7effa
[ldk-java] / src / main / java / org / ldk / structs / UtxoLookup.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10 /**
11  * The `UtxoLookup` trait defines behavior for accessing on-chain UTXOs.
12  */
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;
21         }
22         @Override @SuppressWarnings("deprecation")
23         protected void finalize() throws Throwable {
24                 if (ptr != 0) { bindings.UtxoLookup_free(ptr); } super.finalize();
25         }
26         /**
27          * Destroys the object, freeing associated resources. After this call, any access
28          * to this object may result in a SEGFAULT or worse.
29          *
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
33          * until the GC runs.
34          */
35         public void destroy() {
36                 if (ptr != 0) { bindings.UtxoLookup_free(ptr); }
37                 ptr = 0;
38         }
39         public static interface UtxoLookupInterface {
40                 /**
41                  * Returns the transaction output of a funding transaction encoded by [`short_channel_id`].
42                  * Returns an error if `genesis_hash` is for a different chain or if such a transaction output
43                  * is unknown.
44                  * 
45                  * [`short_channel_id`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#definition-of-short_channel_id
46                  */
47                 UtxoResult get_utxo(byte[] genesis_hash, long short_channel_id);
48         }
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[] genesis_hash, long short_channel_id) {
54                                 UtxoResult ret = arg.get_utxo(genesis_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); };
58                                 return result;
59                         }
60                 });
61                 return impl_holder.held;
62         }
63         /**
64          * Returns the transaction output of a funding transaction encoded by [`short_channel_id`].
65          * Returns an error if `genesis_hash` is for a different chain or if such a transaction output
66          * is unknown.
67          * 
68          * [`short_channel_id`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#definition-of-short_channel_id
69          */
70         public UtxoResult get_utxo(byte[] genesis_hash, long short_channel_id) {
71                 long ret = bindings.UtxoLookup_get_utxo(this.ptr, InternalUtils.check_arr_len(genesis_hash, 32), short_channel_id);
72                 Reference.reachabilityFence(this);
73                 Reference.reachabilityFence(genesis_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); };
78                 return ret_hu_conv;
79         }
80
81 }