b80661ba3c570eebdd57d2ba127b86014ce1ecd4
[ldk-java] / src / main / java / org / ldk / structs / Access.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 `Access` trait defines behavior for accessing chain data and state, such as blocks and
12  * UTXOs.
13  */
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;
22         }
23         @Override @SuppressWarnings("deprecation")
24         protected void finalize() throws Throwable {
25                 if (ptr != 0) { bindings.Access_free(ptr); } super.finalize();
26         }
27
28         public static interface AccessInterface {
29                 /**
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
32                  * is unknown.
33                  * 
34                  * [`short_channel_id`]: https://github.com/lightningnetwork/lightning-rfc/blob/master/07-routing-gossip.md#definition-of-short_channel_id
35                  */
36                 Result_TxOutAccessErrorZ get_utxo(byte[] genesis_hash, long short_channel_id);
37         }
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                                 long result = ret == null ? 0 : ret.clone_ptr();
45                                 return result;
46                         }
47                 });
48                 return impl_holder.held;
49         }
50         /**
51          * Returns the transaction output of a funding transaction encoded by [`short_channel_id`].
52          * Returns an error if `genesis_hash` is for a different chain or if such a transaction output
53          * is unknown.
54          * 
55          * [`short_channel_id`]: https://github.com/lightningnetwork/lightning-rfc/blob/master/07-routing-gossip.md#definition-of-short_channel_id
56          */
57         public Result_TxOutAccessErrorZ get_utxo(byte[] genesis_hash, long short_channel_id) {
58                 long ret = bindings.Access_get_utxo(this.ptr, InternalUtils.check_arr_len(genesis_hash, 32), short_channel_id);
59                 Reference.reachabilityFence(this);
60                 Reference.reachabilityFence(genesis_hash);
61                 Reference.reachabilityFence(short_channel_id);
62                 if (ret >= 0 && ret <= 4096) { return null; }
63                 Result_TxOutAccessErrorZ ret_hu_conv = Result_TxOutAccessErrorZ.constr_from_ptr(ret);
64                 return ret_hu_conv;
65         }
66
67 }