]> git.bitcoin.ninja Git - ldk-java/blob - ts/structs/Persist.ts
Merge pull request #20 from TheBlueMatt/main
[ldk-java] / ts / structs / Persist.ts
1
2             
3 import CommonBase from './CommonBase';
4 import * as bindings from '../bindings' // TODO: figure out location
5
6
7
8             export class Persist extends CommonBase {
9
10                 bindings_instance?: bindings.LDKPersist;
11
12                 constructor(ptr?: number, arg?: bindings.LDKPersist) {
13                     if (Number.isFinite(ptr)) {
14                                         super(ptr);
15                                         this.bindings_instance = null;
16                                     } else {
17                                         // TODO: private constructor instantiation
18                                         super(bindings.LDKPersist_new(arg));
19                                         this.ptrs_to.push(arg);
20                                         
21                                     }
22                 }
23
24                 protected finalize() {
25                     if (this.ptr != 0) {
26                         bindings.Persist_free(this.ptr);
27                     }
28                     super.finalize();
29                 }
30
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;
41                                 return result;
42                                                 },
43
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;
51                                 return result;
52                                                 },
53
54                                                 
55                     };
56                     impl_holder.held = new Persist (null, structImplementation);
57                 }
58             }
59
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;
63                                 
64             }
65
66             class LDKPersistHolder {
67                 held: Persist;
68             }
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);
72                 this.ptrs_to.add(id);
73                 this.ptrs_to.add(data);
74                 return ret_hu_conv;
75         }
76
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);
80                 this.ptrs_to.add(id);
81                 this.ptrs_to.add(update);
82                 this.ptrs_to.add(data);
83                 return ret_hu_conv;
84         }
85
86 }