7 namespace org { namespace ldk { namespace structs {
11 /** An implementation of UtxoLookup */
12 public interface UtxoLookupInterface {
13 /**Returns the transaction output of a funding transaction encoded by [`short_channel_id`].
14 * Returns an error if `chain_hash` is for a different chain or if such a transaction output is
17 * [`short_channel_id`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#definition-of-short_channel_id
19 UtxoResult get_utxo(byte[] chain_hash, long short_channel_id);
23 * The `UtxoLookup` trait defines behavior for accessing on-chain UTXOs.
25 public class UtxoLookup : CommonBase {
26 internal bindings.LDKUtxoLookup bindings_instance;
27 internal long instance_idx;
29 internal UtxoLookup(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
31 if (ptr != 0) { bindings.UtxoLookup_free(ptr); }
34 private class LDKUtxoLookupHolder { internal UtxoLookup held; }
35 private class LDKUtxoLookupImpl : bindings.LDKUtxoLookup {
36 internal LDKUtxoLookupImpl(UtxoLookupInterface arg, LDKUtxoLookupHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
37 private UtxoLookupInterface arg;
38 private LDKUtxoLookupHolder impl_holder;
39 public long get_utxo(long _chain_hash, long _short_channel_id) {
40 byte[] _chain_hash_conv = InternalUtils.decodeUint8Array(_chain_hash);
41 UtxoResult ret = arg.get_utxo(_chain_hash_conv, _short_channel_id);
43 long result = ret.clone_ptr();
44 if (impl_holder.held != null) { impl_holder.held.ptrs_to.AddLast(ret); };
49 /** Creates a new instance of UtxoLookup from a given implementation */
50 public static UtxoLookup new_impl(UtxoLookupInterface arg) {
51 LDKUtxoLookupHolder impl_holder = new LDKUtxoLookupHolder();
52 LDKUtxoLookupImpl impl = new LDKUtxoLookupImpl(arg, impl_holder);
53 long[] ptr_idx = bindings.LDKUtxoLookup_new(impl);
55 impl_holder.held = new UtxoLookup(null, ptr_idx[0]);
56 impl_holder.held.instance_idx = ptr_idx[1];
57 impl_holder.held.bindings_instance = impl;
58 return impl_holder.held;
62 * Returns the transaction output of a funding transaction encoded by [`short_channel_id`].
63 * Returns an error if `chain_hash` is for a different chain or if such a transaction output is
66 * [`short_channel_id`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#definition-of-short_channel_id
68 public UtxoResult get_utxo(byte[] chain_hash, long short_channel_id) {
69 long ret = bindings.UtxoLookup_get_utxo(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(chain_hash, 32)), short_channel_id);
71 GC.KeepAlive(chain_hash);
72 GC.KeepAlive(short_channel_id);
73 if (ret >= 0 && ret <= 4096) { return null; }
74 org.ldk.structs.UtxoResult ret_hu_conv = org.ldk.structs.UtxoResult.constr_from_ptr(ret);
75 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };