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 `Access` trait defines behavior for accessing chain data and state, such as blocks and
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class Access extends CommonBase {
16 final bindings.LDKAccess bindings_instance;
17 Access(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
18 private Access(bindings.LDKAccess arg) {
19 super(bindings.LDKAccess_new(arg));
20 this.ptrs_to.add(arg);
21 this.bindings_instance = arg;
23 @Override @SuppressWarnings("deprecation")
24 protected void finalize() throws Throwable {
25 if (ptr != 0) { bindings.Access_free(ptr); } super.finalize();
28 public static interface AccessInterface {
30 * Returns the transaction output of a funding transaction encoded by [`short_channel_id`].
31 * Returns an error if `genesis_hash` is for a different chain or if such a transaction output
34 * [`short_channel_id`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#definition-of-short_channel_id
36 Result_TxOutAccessErrorZ get_utxo(byte[] genesis_hash, long short_channel_id);
38 private static class LDKAccessHolder { Access held; }
39 public static Access new_impl(AccessInterface arg) {
40 final LDKAccessHolder impl_holder = new LDKAccessHolder();
41 impl_holder.held = new Access(new bindings.LDKAccess() {
42 @Override public long get_utxo(byte[] genesis_hash, long short_channel_id) {
43 Result_TxOutAccessErrorZ ret = arg.get_utxo(genesis_hash, short_channel_id);
44 Reference.reachabilityFence(arg);
45 long result = ret == null ? 0 : ret.clone_ptr();
49 return impl_holder.held;
52 * Returns the transaction output of a funding transaction encoded by [`short_channel_id`].
53 * Returns an error if `genesis_hash` is for a different chain or if such a transaction output
56 * [`short_channel_id`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#definition-of-short_channel_id
58 public Result_TxOutAccessErrorZ get_utxo(byte[] genesis_hash, long short_channel_id) {
59 long ret = bindings.Access_get_utxo(this.ptr, InternalUtils.check_arr_len(genesis_hash, 32), short_channel_id);
60 Reference.reachabilityFence(this);
61 Reference.reachabilityFence(genesis_hash);
62 Reference.reachabilityFence(short_channel_id);
63 if (ret >= 0 && ret <= 4096) { return null; }
64 Result_TxOutAccessErrorZ ret_hu_conv = Result_TxOutAccessErrorZ.constr_from_ptr(ret);