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 (channel_id: number, data: number, update_id: number): number {
36 const channel_id_hu_conv: OutPoint = new OutPoint(null, channel_id);
37 channel_id_hu_conv.ptrs_to.add(this);
38 const data_hu_conv: ChannelMonitor = new ChannelMonitor(null, data);
39 const update_id_hu_conv: MonitorUpdateId = new MonitorUpdateId(null, update_id);
40 update_id_hu_conv.ptrs_to.add(this);
41 Result_NoneChannelMonitorUpdateErrZ ret = arg.persist_new_channel(channel_id_hu_conv, data_hu_conv, update_id_hu_conv);
42 result: number = ret == null ? 0 : ret.clone_ptr();
46 update_persisted_channel (channel_id: number, update: number, data: number, update_id: number): number {
47 const channel_id_hu_conv: OutPoint = new OutPoint(null, channel_id);
48 channel_id_hu_conv.ptrs_to.add(this);
49 const update_hu_conv: ChannelMonitorUpdate = new ChannelMonitorUpdate(null, update);
50 const data_hu_conv: ChannelMonitor = new ChannelMonitor(null, data);
51 const update_id_hu_conv: MonitorUpdateId = new MonitorUpdateId(null, update_id);
52 update_id_hu_conv.ptrs_to.add(this);
53 Result_NoneChannelMonitorUpdateErrZ ret = arg.update_persisted_channel(channel_id_hu_conv, update_hu_conv, data_hu_conv, update_id_hu_conv);
54 result: number = ret == null ? 0 : ret.clone_ptr();
60 impl_holder.held = new Persist (null, structImplementation);
64 export interface PersistInterface {
65 persist_new_channel(channel_id: OutPoint, data: ChannelMonitor, update_id: MonitorUpdateId): Result_NoneChannelMonitorUpdateErrZ;
66 update_persisted_channel(channel_id: OutPoint, update: ChannelMonitorUpdate, data: ChannelMonitor, update_id: MonitorUpdateId): Result_NoneChannelMonitorUpdateErrZ;
70 class LDKPersistHolder {
73 public Result_NoneChannelMonitorUpdateErrZ persist_new_channel(OutPoint channel_id, ChannelMonitor data, MonitorUpdateId update_id) {
74 number ret = bindings.Persist_persist_new_channel(this.ptr, channel_id == null ? 0 : channel_id.ptr & ~1, data == null ? 0 : data.ptr & ~1, update_id == null ? 0 : update_id.ptr & ~1);
75 Result_NoneChannelMonitorUpdateErrZ ret_hu_conv = Result_NoneChannelMonitorUpdateErrZ.constr_from_ptr(ret);
76 this.ptrs_to.add(data);
80 public Result_NoneChannelMonitorUpdateErrZ update_persisted_channel(OutPoint channel_id, ChannelMonitorUpdate update, ChannelMonitor data, MonitorUpdateId update_id) {
81 number ret = bindings.Persist_update_persisted_channel(this.ptr, channel_id == null ? 0 : channel_id.ptr & ~1, update == null ? 0 : update.ptr & ~1, data == null ? 0 : data.ptr & ~1, update_id == null ? 0 : update_id.ptr & ~1);
82 Result_NoneChannelMonitorUpdateErrZ ret_hu_conv = Result_NoneChannelMonitorUpdateErrZ.constr_from_ptr(ret);
83 this.ptrs_to.add(update);
84 this.ptrs_to.add(data);