f9206898166bc71ff2d97c101c6dae7264625366
[ldk-java] / c_sharp / src / org / ldk / structs / Access.cs
1 using org.ldk.impl;
2 using org.ldk.enums;
3 using org.ldk.util;
4 using System;
5
6 namespace org { namespace ldk { namespace structs {
7
8 /**
9  * The `Access` trait defines behavior for accessing chain data and state, such as blocks and
10  * UTXOs.
11  */
12 public class Access : CommonBase {
13         internal readonly bindings.LDKAccess bindings_instance;
14         internal Access(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
15         private Access(bindings.LDKAccess arg) : base(bindings.LDKAccess_new(arg)) {
16                 this.ptrs_to.AddLast(arg);
17                 this.bindings_instance = arg;
18         }
19         ~Access() {
20                 if (ptr != 0) { bindings.Access_free(ptr); }
21         }
22
23         public interface AccessInterface {
24                 /**
25                  * Returns the transaction output of a funding transaction encoded by [`short_channel_id`].
26                  * Returns an error if `genesis_hash` is for a different chain or if such a transaction output
27                  * is unknown.
28                  * 
29                  * [`short_channel_id`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#definition-of-short_channel_id
30                  */
31                 Result_TxOutAccessErrorZ get_utxo(byte[] _genesis_hash, long _short_channel_id);
32         }
33         private class LDKAccessHolder { internal Access held; }
34         private class LDKAccessImpl : bindings.LDKAccess {
35                 internal LDKAccessImpl(AccessInterface arg, LDKAccessHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
36                 private AccessInterface arg;
37                 private LDKAccessHolder impl_holder;
38                 public long get_utxo(byte[] _genesis_hash, long _short_channel_id) {
39                         Result_TxOutAccessErrorZ ret = arg.get_utxo(_genesis_hash, _short_channel_id);
40                                 GC.KeepAlive(arg);
41                         long result = ret == null ? 0 : ret.clone_ptr();
42                         return result;
43                 }
44         }
45         public static Access new_impl(AccessInterface arg) {
46                 LDKAccessHolder impl_holder = new LDKAccessHolder();
47                 impl_holder.held = new Access(new LDKAccessImpl(arg, impl_holder));
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/lightning/bolts/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                 GC.KeepAlive(this);
60                 GC.KeepAlive(genesis_hash);
61                 GC.KeepAlive(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 }
68 } } }