1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
8 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
9 public class Watch extends CommonBase {
10 final bindings.LDKWatch bindings_instance;
11 Watch(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
12 private Watch(bindings.LDKWatch arg) {
13 super(bindings.LDKWatch_new(arg));
14 this.ptrs_to.add(arg);
15 this.bindings_instance = arg;
17 @Override @SuppressWarnings("deprecation")
18 protected void finalize() throws Throwable {
19 if (ptr != 0) { bindings.Watch_free(ptr); } super.finalize();
22 public static interface WatchInterface {
23 Result_NoneChannelMonitorUpdateErrZ watch_channel(OutPoint funding_txo, ChannelMonitor monitor);
24 Result_NoneChannelMonitorUpdateErrZ update_channel(OutPoint funding_txo, ChannelMonitorUpdate update);
25 MonitorEvent[] release_pending_monitor_events();
27 private static class LDKWatchHolder { Watch held; }
28 public static Watch new_impl(WatchInterface arg) {
29 final LDKWatchHolder impl_holder = new LDKWatchHolder();
30 impl_holder.held = new Watch(new bindings.LDKWatch() {
31 @Override public long watch_channel(long funding_txo, long monitor) {
32 OutPoint funding_txo_hu_conv = new OutPoint(null, funding_txo);
33 ChannelMonitor monitor_hu_conv = new ChannelMonitor(null, monitor);
34 Result_NoneChannelMonitorUpdateErrZ ret = arg.watch_channel(funding_txo_hu_conv, monitor_hu_conv);
35 long result = ret != null ? ret.ptr : 0;
39 @Override public long update_channel(long funding_txo, long update) {
40 OutPoint funding_txo_hu_conv = new OutPoint(null, funding_txo);
41 ChannelMonitorUpdate update_hu_conv = new ChannelMonitorUpdate(null, update);
42 Result_NoneChannelMonitorUpdateErrZ ret = arg.update_channel(funding_txo_hu_conv, update_hu_conv);
43 long result = ret != null ? ret.ptr : 0;
47 @Override public long[] release_pending_monitor_events() {
48 MonitorEvent[] ret = arg.release_pending_monitor_events();
49 long[] result = Arrays.stream(ret).mapToLong(arr_conv_14 -> arr_conv_14 == null ? 0 : arr_conv_14.ptr & ~1).toArray();
50 /* TODO 2 MonitorEvent */;
54 return impl_holder.held;
56 // Skipped Watch_watch_channel
57 public Result_NoneChannelMonitorUpdateErrZ update_channel(OutPoint funding_txo, ChannelMonitorUpdate update) {
58 long ret = bindings.Watch_update_channel(this.ptr, funding_txo == null ? 0 : funding_txo.ptr & ~1, update == null ? 0 : update.ptr & ~1);
59 Result_NoneChannelMonitorUpdateErrZ ret_hu_conv = Result_NoneChannelMonitorUpdateErrZ.constr_from_ptr(ret);
60 ret_hu_conv.ptrs_to.add(this);
61 this.ptrs_to.add(funding_txo);
62 this.ptrs_to.add(update);
66 public MonitorEvent[] release_pending_monitor_events() {
67 long[] ret = bindings.Watch_release_pending_monitor_events(this.ptr);
68 MonitorEvent[] arr_conv_14_arr = new MonitorEvent[ret.length];
69 for (int o = 0; o < ret.length; o++) {
70 long arr_conv_14 = ret[o];
71 MonitorEvent arr_conv_14_hu_conv = new MonitorEvent(null, arr_conv_14);
72 arr_conv_14_arr[o] = arr_conv_14_hu_conv;
74 return arr_conv_14_arr;