X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FAccess.java;h=b80661ba3c570eebdd57d2ba127b86014ce1ecd4;hb=1854b5cebef22ace9e9e4dd191f609818df9ce08;hp=15b3d7423df26c1bb581c2a75b7393295ae382da;hpb=aa0e2aade37133339f4113a0cd7465b111f0a0d0;p=ldk-java diff --git a/src/main/java/org/ldk/structs/Access.java b/src/main/java/org/ldk/structs/Access.java index 15b3d742..b80661ba 100644 --- a/src/main/java/org/ldk/structs/Access.java +++ b/src/main/java/org/ldk/structs/Access.java @@ -4,7 +4,13 @@ import org.ldk.impl.bindings; import org.ldk.enums.*; import org.ldk.util.*; import java.util.Arrays; +import java.lang.ref.Reference; +import javax.annotation.Nullable; +/** + * The `Access` trait defines behavior for accessing chain data and state, such as blocks and + * UTXOs. + */ @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class Access extends CommonBase { final bindings.LDKAccess bindings_instance; @@ -20,22 +26,41 @@ public class Access extends CommonBase { } public static interface AccessInterface { + /** + * Returns the transaction output of a funding transaction encoded by [`short_channel_id`]. + * Returns an error if `genesis_hash` is for a different chain or if such a transaction output + * is unknown. + * + * [`short_channel_id`]: https://github.com/lightningnetwork/lightning-rfc/blob/master/07-routing-gossip.md#definition-of-short_channel_id + */ Result_TxOutAccessErrorZ get_utxo(byte[] genesis_hash, long short_channel_id); } - public Access(AccessInterface arg) { - this(new bindings.LDKAccess() { + private static class LDKAccessHolder { Access held; } + public static Access new_impl(AccessInterface arg) { + final LDKAccessHolder impl_holder = new LDKAccessHolder(); + impl_holder.held = new Access(new bindings.LDKAccess() { @Override public long get_utxo(byte[] genesis_hash, long short_channel_id) { Result_TxOutAccessErrorZ ret = arg.get_utxo(genesis_hash, short_channel_id); - long result = ret != null ? ret.ptr : 0; - ret.ptr = 0; + long result = ret == null ? 0 : ret.clone_ptr(); return result; } }); + return impl_holder.held; } + /** + * Returns the transaction output of a funding transaction encoded by [`short_channel_id`]. + * Returns an error if `genesis_hash` is for a different chain or if such a transaction output + * is unknown. + * + * [`short_channel_id`]: https://github.com/lightningnetwork/lightning-rfc/blob/master/07-routing-gossip.md#definition-of-short_channel_id + */ public Result_TxOutAccessErrorZ get_utxo(byte[] genesis_hash, long short_channel_id) { - long ret = bindings.Access_get_utxo(this.ptr, genesis_hash, short_channel_id); + long ret = bindings.Access_get_utxo(this.ptr, InternalUtils.check_arr_len(genesis_hash, 32), short_channel_id); + Reference.reachabilityFence(this); + Reference.reachabilityFence(genesis_hash); + Reference.reachabilityFence(short_channel_id); + if (ret >= 0 && ret <= 4096) { return null; } Result_TxOutAccessErrorZ ret_hu_conv = Result_TxOutAccessErrorZ.constr_from_ptr(ret); - ret_hu_conv.ptrs_to.add(this); return ret_hu_conv; }