6 namespace org { namespace ldk { namespace structs {
9 * The `UtxoLookup` trait defines behavior for accessing on-chain UTXOs.
11 public class UtxoLookup : CommonBase {
12 internal readonly bindings.LDKUtxoLookup bindings_instance;
13 internal UtxoLookup(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
14 private UtxoLookup(bindings.LDKUtxoLookup arg) : base(bindings.LDKUtxoLookup_new(arg)) {
15 this.ptrs_to.AddLast(arg);
16 this.bindings_instance = arg;
19 if (ptr != 0) { bindings.UtxoLookup_free(ptr); }
22 public interface UtxoLookupInterface {
24 * Returns the transaction output of a funding transaction encoded by [`short_channel_id`].
25 * Returns an error if `genesis_hash` is for a different chain or if such a transaction output
28 * [`short_channel_id`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#definition-of-short_channel_id
30 UtxoResult get_utxo(byte[] _genesis_hash, long _short_channel_id);
32 private class LDKUtxoLookupHolder { internal UtxoLookup held; }
33 private class LDKUtxoLookupImpl : bindings.LDKUtxoLookup {
34 internal LDKUtxoLookupImpl(UtxoLookupInterface arg, LDKUtxoLookupHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
35 private UtxoLookupInterface arg;
36 private LDKUtxoLookupHolder impl_holder;
37 public long get_utxo(byte[] _genesis_hash, long _short_channel_id) {
38 UtxoResult ret = arg.get_utxo(_genesis_hash, _short_channel_id);
40 long result = ret == null ? 0 : ret.clone_ptr();
41 if (impl_holder.held != null) { impl_holder.held.ptrs_to.AddLast(ret); };
45 public static UtxoLookup new_impl(UtxoLookupInterface arg) {
46 LDKUtxoLookupHolder impl_holder = new LDKUtxoLookupHolder();
47 impl_holder.held = new UtxoLookup(new LDKUtxoLookupImpl(arg, impl_holder));
48 return impl_holder.held;
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
55 * [`short_channel_id`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#definition-of-short_channel_id
57 public UtxoResult get_utxo(byte[] genesis_hash, long short_channel_id) {
58 long ret = bindings.UtxoLookup_get_utxo(this.ptr, InternalUtils.check_arr_len(genesis_hash, 32), short_channel_id);
60 GC.KeepAlive(genesis_hash);
61 GC.KeepAlive(short_channel_id);
62 if (ret >= 0 && ret <= 4096) { return null; }
63 org.ldk.structs.UtxoResult ret_hu_conv = org.ldk.structs.UtxoResult.constr_from_ptr(ret);
64 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };