X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=ts%2Fstructs%2FPersist.ts;h=dbfc8aeb284ff549bcf8909a73abfb7e6aa86eb0;hb=fed2245c60159f6c074c9ed5c0f3ce273ad9841b;hp=9b1dde6e3c73e7bb38254181b1ab5230850eed76;hpb=822471992c6bf6f9985e531cc5940e4cc35e3e4c;p=ldk-java diff --git a/ts/structs/Persist.ts b/ts/structs/Persist.ts index 9b1dde6e..dbfc8aeb 100644 --- a/ts/structs/Persist.ts +++ b/ts/structs/Persist.ts @@ -1,50 +1,73 @@ + import CommonBase from './CommonBase'; import * as bindings from '../bindings' // TODO: figure out location -public class Persist extends CommonBase { - final bindings.LDKPersist bindings_instance; - Persist(Object _dummy, long ptr) { super(ptr); bindings_instance = null; } - private Persist(bindings.LDKPersist arg) { - super(bindings.LDKPersist_new(arg)); - this.ptrs_to.add(arg); - this.bindings_instance = arg; - } - @Override @SuppressWarnings("deprecation") - protected void finalize() throws Throwable { - if (ptr != 0) { bindings.Persist_free(ptr); } super.finalize(); - } - public static interface PersistInterface { - Result_NoneChannelMonitorUpdateErrZ persist_new_channel(OutPoint id, ChannelMonitor data); - Result_NoneChannelMonitorUpdateErrZ update_persisted_channel(OutPoint id, ChannelMonitorUpdate update, ChannelMonitor data); - } - private static class LDKPersistHolder { Persist held; } - public static Persist new_impl(PersistInterface arg) { - final LDKPersistHolder impl_holder = new LDKPersistHolder(); - impl_holder.held = new Persist(new bindings.LDKPersist() { - @Override public uint32_t persist_new_channel(uint32_t id, uint32_t data) { - OutPoint id_hu_conv = new OutPoint(null, id); - ChannelMonitor data_hu_conv = new ChannelMonitor(null, data); - Result_NoneChannelMonitorUpdateErrZ ret = arg.persist_new_channel(id_hu_conv, data_hu_conv); - uint32_t result = ret != null ? ret.ptr : 0; - ret.ptr = 0; + + export class Persist extends CommonBase { + + bindings_instance?: bindings.LDKPersist; + + constructor(ptr?: number, arg?: bindings.LDKPersist) { + if (Number.isFinite(ptr)) { + super(ptr); + this.bindings_instance = null; + } else { + // TODO: private constructor instantiation + super(bindings.LDKPersist_new(arg)); + this.ptrs_to.push(arg); + + } + } + + protected finalize() { + if (this.ptr != 0) { + bindings.Persist_free(this.ptr); + } + super.finalize(); + } + + static new_impl(arg: PersistInterface): Persist { + const impl_holder: LDKPersistHolder = new LDKPersistHolder(); + let structImplementation = { + // todo: in-line interface filling + persist_new_channel (id: number, data: number): number { + const id_hu_conv: OutPoint = new OutPoint(null, id); + id_hu_conv.ptrs_to.add(this); + const data_hu_conv: ChannelMonitor = new ChannelMonitor(null, data); + Result_NoneChannelMonitorUpdateErrZ ret = arg.persist_new_channel(id_hu_conv, data_hu_conv); + result: number = ret != null ? ret.ptr : 0; return result; - } - @Override public uint32_t update_persisted_channel(uint32_t id, uint32_t update, uint32_t data) { - OutPoint id_hu_conv = new OutPoint(null, id); - ChannelMonitorUpdate update_hu_conv = new ChannelMonitorUpdate(null, update); - ChannelMonitor data_hu_conv = new ChannelMonitor(null, data); - Result_NoneChannelMonitorUpdateErrZ ret = arg.update_persisted_channel(id_hu_conv, update_hu_conv, data_hu_conv); - uint32_t result = ret != null ? ret.ptr : 0; - ret.ptr = 0; + }, + + update_persisted_channel (id: number, update: number, data: number): number { + const id_hu_conv: OutPoint = new OutPoint(null, id); + id_hu_conv.ptrs_to.add(this); + const update_hu_conv: ChannelMonitorUpdate = new ChannelMonitorUpdate(null, update); + const data_hu_conv: ChannelMonitor = new ChannelMonitor(null, data); + Result_NoneChannelMonitorUpdateErrZ ret = arg.update_persisted_channel(id_hu_conv, update_hu_conv, data_hu_conv); + result: number = ret != null ? ret.ptr : 0; return result; - } - }); - return impl_holder.held; - } + }, + + + }; + impl_holder.held = new Persist (null, structImplementation); + } + } + + export interface PersistInterface { + persist_new_channel(id: OutPoint, data: ChannelMonitor): Result_NoneChannelMonitorUpdateErrZ; + update_persisted_channel(id: OutPoint, update: ChannelMonitorUpdate, data: ChannelMonitor): Result_NoneChannelMonitorUpdateErrZ; + + } + + class LDKPersistHolder { + held: Persist; + } public Result_NoneChannelMonitorUpdateErrZ persist_new_channel(OutPoint id, ChannelMonitor data) { - uint32_t ret = bindings.Persist_persist_new_channel(this.ptr, id == null ? 0 : id.ptr & ~1, data == null ? 0 : data.ptr & ~1); + number ret = bindings.Persist_persist_new_channel(this.ptr, id == null ? 0 : id.ptr & ~1, data == null ? 0 : data.ptr & ~1); Result_NoneChannelMonitorUpdateErrZ ret_hu_conv = Result_NoneChannelMonitorUpdateErrZ.constr_from_ptr(ret); this.ptrs_to.add(id); this.ptrs_to.add(data); @@ -52,7 +75,7 @@ public class Persist extends CommonBase { } public Result_NoneChannelMonitorUpdateErrZ update_persisted_channel(OutPoint id, ChannelMonitorUpdate update, ChannelMonitor data) { - uint32_t ret = bindings.Persist_update_persisted_channel(this.ptr, id == null ? 0 : id.ptr & ~1, update == null ? 0 : update.ptr & ~1, data == null ? 0 : data.ptr & ~1); + number ret = bindings.Persist_update_persisted_channel(this.ptr, id == null ? 0 : id.ptr & ~1, update == null ? 0 : update.ptr & ~1, data == null ? 0 : data.ptr & ~1); Result_NoneChannelMonitorUpdateErrZ ret_hu_conv = Result_NoneChannelMonitorUpdateErrZ.constr_from_ptr(ret); this.ptrs_to.add(id); this.ptrs_to.add(update);