Bindings updates
[ldk-java] / ts / structs / Watch.ts
index 931fc726cbec267429d7d34387a8570317861684..ea0bdf4b1d8d804f888855247fabfc3effcdcd64 100644 (file)
@@ -1,56 +1,78 @@
 
+            
 import CommonBase from './CommonBase';
 import * as bindings from '../bindings' // TODO: figure out location
 
-public class Watch extends CommonBase {
-       final bindings.LDKWatch bindings_instance;
-       Watch(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
-       private Watch(bindings.LDKWatch arg) {
-               super(bindings.LDKWatch_new(arg));
-               this.ptrs_to.add(arg);
-               this.bindings_instance = arg;
-       }
-       @Override @SuppressWarnings("deprecation")
-       protected void finalize() throws Throwable {
-               if (ptr != 0) { bindings.Watch_free(ptr); } super.finalize();
-       }
 
-       public static interface WatchInterface {
-               Result_NoneChannelMonitorUpdateErrZ watch_channel(OutPoint funding_txo, ChannelMonitor monitor);
-               Result_NoneChannelMonitorUpdateErrZ update_channel(OutPoint funding_txo, ChannelMonitorUpdate update);
-               MonitorEvent[] release_pending_monitor_events();
-       }
-       private static class LDKWatchHolder { Watch held; }
-       public static Watch new_impl(WatchInterface arg) {
-               final LDKWatchHolder impl_holder = new LDKWatchHolder();
-               impl_holder.held = new Watch(new bindings.LDKWatch() {
-                       @Override public uint32_t watch_channel(uint32_t funding_txo, uint32_t monitor) {
-                               OutPoint funding_txo_hu_conv = new OutPoint(null, funding_txo);
-                               ChannelMonitor monitor_hu_conv = new ChannelMonitor(null, monitor);
-                               Result_NoneChannelMonitorUpdateErrZ ret = arg.watch_channel(funding_txo_hu_conv, monitor_hu_conv);
-                               uint32_t result = ret != null ? ret.ptr : 0;
-                               ret.ptr = 0;
+
+            export class Watch extends CommonBase {
+
+                bindings_instance?: bindings.LDKWatch;
+
+                constructor(ptr?: number, arg?: bindings.LDKWatch) {
+                    if (Number.isFinite(ptr)) {
+                                       super(ptr);
+                                       this.bindings_instance = null;
+                                   } else {
+                                       // TODO: private constructor instantiation
+                                       super(bindings.LDKWatch_new(arg));
+                                       this.ptrs_to.push(arg);
+                                       
+                                   }
+                }
+
+                protected finalize() {
+                    if (this.ptr != 0) {
+                        bindings.Watch_free(this.ptr);
+                    }
+                    super.finalize();
+                }
+
+                static new_impl(arg: WatchInterface): Watch {
+                    const impl_holder: LDKWatchHolder = new LDKWatchHolder();
+                    let structImplementation = <bindings.LDKWatch>{
+                        // todo: in-line interface filling
+                        watch_channel (funding_txo: number, monitor: number): number {
+                                                       const funding_txo_hu_conv: OutPoint = new OutPoint(null, funding_txo);
+                                                       const monitor_hu_conv: ChannelMonitor = new ChannelMonitor(null, monitor);
+                                                       Result_NoneChannelMonitorUpdateErrZ ret = arg.watch_channel(funding_txo_hu_conv, monitor_hu_conv);
+                               result: number = ret != null ? ret.ptr : 0;
                                return result;
-                       }
-                       @Override public uint32_t update_channel(uint32_t funding_txo, uint32_t update) {
-                               OutPoint funding_txo_hu_conv = new OutPoint(null, funding_txo);
-                               ChannelMonitorUpdate update_hu_conv = new ChannelMonitorUpdate(null, update);
-                               Result_NoneChannelMonitorUpdateErrZ ret = arg.update_channel(funding_txo_hu_conv, update_hu_conv);
-                               uint32_t result = ret != null ? ret.ptr : 0;
-                               ret.ptr = 0;
+                                               },
+
+                                               update_channel (funding_txo: number, update: number): number {
+                                                       const funding_txo_hu_conv: OutPoint = new OutPoint(null, funding_txo);
+                                                       const update_hu_conv: ChannelMonitorUpdate = new ChannelMonitorUpdate(null, update);
+                                                       Result_NoneChannelMonitorUpdateErrZ ret = arg.update_channel(funding_txo_hu_conv, update_hu_conv);
+                               result: number = ret != null ? ret.ptr : 0;
                                return result;
-                       }
-                       @Override public uint32_t[] release_pending_monitor_events() {
-                               MonitorEvent[] ret = arg.release_pending_monitor_events();
-                               uint32_t[] result = (uint32_t[])Arrays.stream(ret).map(arr_conv_14 -> arr_conv_14 == null ? 0 : arr_conv_14.ptr & ~1).toArray();
+                                               },
+
+                                               release_pending_monitor_events (): number[] {
+                                                       MonitorEvent[] ret = arg.release_pending_monitor_events();
+                               result: number[] = (number[])Arrays.stream(ret).map(arr_conv_14 -> arr_conv_14 == null ? 0 : arr_conv_14.ptr & ~1).toArray();
                                /* TODO 2 MonitorEvent  */;
                                return result;
-                       }
-               });
-               return impl_holder.held;
-       }
+                                               },
+
+                                               
+                    };
+                    impl_holder.held = new Watch (null, structImplementation);
+                }
+            }
+
+            export interface WatchInterface {
+                watch_channel(funding_txo: OutPoint, monitor: ChannelMonitor): Result_NoneChannelMonitorUpdateErrZ;
+                               update_channel(funding_txo: OutPoint, update: ChannelMonitorUpdate): Result_NoneChannelMonitorUpdateErrZ;
+                               release_pending_monitor_events(): MonitorEvent[];
+                               
+            }
+
+            class LDKWatchHolder {
+                held: Watch;
+            }
        public Result_NoneChannelMonitorUpdateErrZ watch_channel(OutPoint funding_txo, ChannelMonitor monitor) {
-               uint32_t ret = bindings.Watch_watch_channel(this.ptr, funding_txo == null ? 0 : funding_txo.ptr & ~1, monitor == null ? 0 : monitor.ptr & ~1);
+               number ret = bindings.Watch_watch_channel(this.ptr, funding_txo == null ? 0 : funding_txo.ptr & ~1, monitor == null ? 0 : monitor.ptr & ~1);
                Result_NoneChannelMonitorUpdateErrZ ret_hu_conv = Result_NoneChannelMonitorUpdateErrZ.constr_from_ptr(ret);
                this.ptrs_to.add(funding_txo);
                this.ptrs_to.add(monitor);
@@ -58,7 +80,7 @@ public class Watch extends CommonBase {
        }
 
        public Result_NoneChannelMonitorUpdateErrZ update_channel(OutPoint funding_txo, ChannelMonitorUpdate update) {
-               uint32_t ret = bindings.Watch_update_channel(this.ptr, funding_txo == null ? 0 : funding_txo.ptr & ~1, update == null ? 0 : update.ptr & ~1);
+               number ret = bindings.Watch_update_channel(this.ptr, funding_txo == null ? 0 : funding_txo.ptr & ~1, update == null ? 0 : update.ptr & ~1);
                Result_NoneChannelMonitorUpdateErrZ ret_hu_conv = Result_NoneChannelMonitorUpdateErrZ.constr_from_ptr(ret);
                this.ptrs_to.add(funding_txo);
                this.ptrs_to.add(update);
@@ -66,11 +88,11 @@ public class Watch extends CommonBase {
        }
 
        public MonitorEvent[] release_pending_monitor_events() {
-               uint32_t[] ret = bindings.Watch_release_pending_monitor_events(this.ptr);
+               number[] ret = bindings.Watch_release_pending_monitor_events(this.ptr);
                MonitorEvent[] arr_conv_14_arr = new MonitorEvent[ret.length];
                for (int o = 0; o < ret.length; o++) {
-                       uint32_t arr_conv_14 = ret[o];
-                       MonitorEvent arr_conv_14_hu_conv = new MonitorEvent(null, arr_conv_14);
+                       number arr_conv_14 = ret[o];
+                       const arr_conv_14_hu_conv: MonitorEvent = new MonitorEvent(null, arr_conv_14);
                        arr_conv_14_arr[o] = arr_conv_14_hu_conv;
                }
                return arr_conv_14_arr;