]> git.bitcoin.ninja Git - ldk-java/blob - src/main/java/org/ldk/structs/Access.java
Merge pull request #123 from tnull/patch-1
[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/lightning/bolts/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                                 Reference.reachabilityFence(arg);
45                                 long result = ret == null ? 0 : ret.clone_ptr();
46                                 return result;
47                         }
48                 });
49                 return impl_holder.held;
50         }
51         /**
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
54          * is unknown.
55          * 
56          * [`short_channel_id`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#definition-of-short_channel_id
57          */
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);
65                 return ret_hu_conv;
66         }
67
68 }