X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=ts%2Fstructs%2FAccess.ts;h=ccb20fb0e3272f98d17b75eceaedb08e05a67091;hb=f3e670e9341decac613d33fc52febf19cea32f20;hp=897b4b59e57d80b31f3735e33c8ce7b58258324e;hpb=822471992c6bf6f9985e531cc5940e4cc35e3e4c;p=ldk-java diff --git a/ts/structs/Access.ts b/ts/structs/Access.ts index 897b4b59..ccb20fb0 100644 --- a/ts/structs/Access.ts +++ b/ts/structs/Access.ts @@ -1,38 +1,59 @@ + import CommonBase from './CommonBase'; import * as bindings from '../bindings' // TODO: figure out location -public class Access extends CommonBase { - final bindings.LDKAccess bindings_instance; - Access(Object _dummy, long ptr) { super(ptr); bindings_instance = null; } - private Access(bindings.LDKAccess arg) { - super(bindings.LDKAccess_new(arg)); - this.ptrs_to.add(arg); - this.bindings_instance = arg; - } - @Override @SuppressWarnings("deprecation") - protected void finalize() throws Throwable { - if (ptr != 0) { bindings.Access_free(ptr); } super.finalize(); - } - public static interface AccessInterface { - Result_TxOutAccessErrorZ get_utxo(byte[] genesis_hash, long short_channel_id); - } - 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 uint32_t get_utxo(byte[] genesis_hash, long short_channel_id) { - Result_TxOutAccessErrorZ ret = arg.get_utxo(genesis_hash, short_channel_id); - uint32_t result = ret != null ? ret.ptr : 0; - ret.ptr = 0; + + export class Access extends CommonBase { + + bindings_instance?: bindings.LDKAccess; + + constructor(ptr?: number, arg?: bindings.LDKAccess) { + if (Number.isFinite(ptr)) { + super(ptr); + this.bindings_instance = null; + } else { + // TODO: private constructor instantiation + super(bindings.LDKAccess_new(arg)); + this.ptrs_to.push(arg); + + } + } + + protected finalize() { + if (this.ptr != 0) { + bindings.Access_free(this.ptr); + } + super.finalize(); + } + + static new_impl(arg: AccessInterface): Access { + const impl_holder: LDKAccessHolder = new LDKAccessHolder(); + let structImplementation = { + // todo: in-line interface filling + get_utxo (genesis_hash: Uint8Array, short_channel_id: number): number { + Result_TxOutAccessErrorZ ret = arg.get_utxo(genesis_hash, short_channel_id); + result: number = ret == null ? 0 : ret.clone_ptr(); return result; - } - }); - return impl_holder.held; - } - public Result_TxOutAccessErrorZ get_utxo(byte[] genesis_hash, long short_channel_id) { - uint32_t ret = bindings.Access_get_utxo(this.ptr, genesis_hash, short_channel_id); + }, + + + }; + impl_holder.held = new Access (null, structImplementation); + } + } + + export interface AccessInterface { + get_utxo(genesis_hash: Uint8Array, short_channel_id: number): Result_TxOutAccessErrorZ; + + } + + class LDKAccessHolder { + held: Access; + } + public Result_TxOutAccessErrorZ get_utxo(Uint8Array genesis_hash, number short_channel_id) { + number ret = bindings.Access_get_utxo(this.ptr, InternalUtils.check_arr_len(genesis_hash, 32), short_channel_id); Result_TxOutAccessErrorZ ret_hu_conv = Result_TxOutAccessErrorZ.constr_from_ptr(ret); return ret_hu_conv; }