3 import CommonBase from './CommonBase';
4 import * as bindings from '../bindings' // TODO: figure out location
8 export class Persist extends CommonBase {
10 bindings_instance?: bindings.LDKPersist;
12 constructor(ptr?: number, arg?: bindings.LDKPersist) {
13 if (Number.isFinite(ptr)) {
15 this.bindings_instance = null;
17 // TODO: private constructor instantiation
18 super(bindings.LDKPersist_new(arg));
19 this.ptrs_to.push(arg);
24 protected finalize() {
26 bindings.Persist_free(this.ptr);
31 static new_impl(arg: PersistInterface): Persist {
32 const impl_holder: LDKPersistHolder = new LDKPersistHolder();
33 let structImplementation = <bindings.LDKPersist>{
34 // todo: in-line interface filling
35 persist_new_channel (id: number, data: number): number {
36 const id_hu_conv: OutPoint = new OutPoint(null, id);
37 id_hu_conv.ptrs_to.add(this);
38 const data_hu_conv: ChannelMonitor = new ChannelMonitor(null, data);
39 Result_NoneChannelMonitorUpdateErrZ ret = arg.persist_new_channel(id_hu_conv, data_hu_conv);
40 result: number = ret != null ? ret.ptr : 0;
44 update_persisted_channel (id: number, update: number, data: number): number {
45 const id_hu_conv: OutPoint = new OutPoint(null, id);
46 id_hu_conv.ptrs_to.add(this);
47 const update_hu_conv: ChannelMonitorUpdate = new ChannelMonitorUpdate(null, update);
48 const data_hu_conv: ChannelMonitor = new ChannelMonitor(null, data);
49 Result_NoneChannelMonitorUpdateErrZ ret = arg.update_persisted_channel(id_hu_conv, update_hu_conv, data_hu_conv);
50 result: number = ret != null ? ret.ptr : 0;
56 impl_holder.held = new Persist (null, structImplementation);
60 export interface PersistInterface {
61 persist_new_channel(id: OutPoint, data: ChannelMonitor): Result_NoneChannelMonitorUpdateErrZ;
62 update_persisted_channel(id: OutPoint, update: ChannelMonitorUpdate, data: ChannelMonitor): Result_NoneChannelMonitorUpdateErrZ;
66 class LDKPersistHolder {
69 public Result_NoneChannelMonitorUpdateErrZ persist_new_channel(OutPoint id, ChannelMonitor data) {
70 number ret = bindings.Persist_persist_new_channel(this.ptr, id == null ? 0 : id.ptr & ~1, data == null ? 0 : data.ptr & ~1);
71 Result_NoneChannelMonitorUpdateErrZ ret_hu_conv = Result_NoneChannelMonitorUpdateErrZ.constr_from_ptr(ret);
73 this.ptrs_to.add(data);
77 public Result_NoneChannelMonitorUpdateErrZ update_persisted_channel(OutPoint id, ChannelMonitorUpdate update, ChannelMonitor data) {
78 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);
79 Result_NoneChannelMonitorUpdateErrZ ret_hu_conv = Result_NoneChannelMonitorUpdateErrZ.constr_from_ptr(ret);
81 this.ptrs_to.add(update);
82 this.ptrs_to.add(data);