]> git.bitcoin.ninja Git - ldk-java/blob - ts/structs/ChannelMonitor.ts
Merge pull request #14 from TheBlueMatt/2021-03-fix-enums
[ldk-java] / ts / structs / ChannelMonitor.ts
1
2             
3 import CommonBase from './CommonBase';
4 import * as bindings from '../bindings' // TODO: figure out location
5
6
7
8             export default class ChannelMonitor extends CommonBase {
9                 constructor(_dummy: object, ptr: number) {
10                     super(ptr);
11                 }
12
13                 
14                 protected finalize() {
15                     super.finalize();
16
17                     if (this.ptr != 0) {
18                         bindings.ChannelMonitor_free(this.ptr);
19                     }
20                 }
21         public ChannelMonitor clone() {
22                 number ret = bindings.ChannelMonitor_clone(this.ptr);
23                 const ret_hu_conv: ChannelMonitor = new ChannelMonitor(null, ret);
24                 ret_hu_conv.ptrs_to.add(this);
25                 return ret_hu_conv;
26         }
27
28         public Uint8Array write() {
29                 Uint8Array ret = bindings.ChannelMonitor_write(this.ptr);
30                 return ret;
31         }
32
33         public Result_NoneMonitorUpdateErrorZ update_monitor(ChannelMonitorUpdate updates, BroadcasterInterface broadcaster, FeeEstimator fee_estimator, Logger logger) {
34                 number ret = bindings.ChannelMonitor_update_monitor(this.ptr, updates == null ? 0 : updates.ptr & ~1, broadcaster == null ? 0 : broadcaster.ptr, fee_estimator == null ? 0 : fee_estimator.ptr, logger == null ? 0 : logger.ptr);
35                 Result_NoneMonitorUpdateErrorZ ret_hu_conv = Result_NoneMonitorUpdateErrorZ.constr_from_ptr(ret);
36                 this.ptrs_to.add(updates);
37                 this.ptrs_to.add(broadcaster);
38                 this.ptrs_to.add(fee_estimator);
39                 this.ptrs_to.add(logger);
40                 return ret_hu_conv;
41         }
42
43         public number get_latest_update_id() {
44                 number ret = bindings.ChannelMonitor_get_latest_update_id(this.ptr);
45                 return ret;
46         }
47
48         public TwoTuple<OutPoint, Uint8Array> get_funding_txo() {
49                 number ret = bindings.ChannelMonitor_get_funding_txo(this.ptr);
50                 number ret_a = bindings.LDKC2Tuple_OutPointScriptZ_get_a(ret);
51                 const ret_a_hu_conv: OutPoint = new OutPoint(null, ret_a);
52                 ret_a_hu_conv.ptrs_to.add(this);;
53                 Uint8Array ret_b = bindings.LDKC2Tuple_OutPointScriptZ_get_b(ret);
54                 TwoTuple<OutPoint, Uint8Array> ret_conv = new TwoTuple<OutPoint, Uint8Array>(ret_a_hu_conv, ret_b, () -> {
55                         bindings.C2Tuple_OutPointScriptZ_free(ret);
56                 });
57                 ret_a_hu_conv.ptrs_to.add(ret_conv);
58                 return ret_conv;
59         }
60
61         public TwoTuple<Uint8Array, TwoTuple<Number, Uint8Array>[]>[] get_outputs_to_watch() {
62                 number[] ret = bindings.ChannelMonitor_get_outputs_to_watch(this.ptr);
63                 TwoTuple<Uint8Array, TwoTuple<Number, Uint8Array>[]>[] ret_conv_54_arr = new TwoTuple[ret.length];
64                 for (int c = 0; c < ret.length; c++) {
65                         number ret_conv_54 = ret[c];
66                         Uint8Array ret_conv_54_a = bindings.LDKC2Tuple_TxidCVec_C2Tuple_u32ScriptZZZ_get_a(ret_conv_54);
67                         number[] ret_conv_54_b = bindings.LDKC2Tuple_TxidCVec_C2Tuple_u32ScriptZZZ_get_b(ret_conv_54);
68                         TwoTuple<Number, Uint8Array>[] ret_conv_54_b_conv_30_arr = new TwoTuple[ret_conv_54_b.length];
69                         for (int e = 0; e < ret_conv_54_b.length; e++) {
70                                 number ret_conv_54_b_conv_30 = ret_conv_54_b[e];
71                                 number ret_conv_54_b_conv_30_a = bindings.LDKC2Tuple_u32ScriptZ_get_a(ret_conv_54_b_conv_30);
72                                 Uint8Array ret_conv_54_b_conv_30_b = bindings.LDKC2Tuple_u32ScriptZ_get_b(ret_conv_54_b_conv_30);
73                                 TwoTuple<Number, Uint8Array> ret_conv_54_b_conv_30_conv = new TwoTuple<Number, Uint8Array>(ret_conv_54_b_conv_30_a, ret_conv_54_b_conv_30_b, () -> {
74                                         bindings.C2Tuple_u32ScriptZ_free(ret_conv_54_b_conv_30);
75                                 });
76                                 ret_conv_54_b_conv_30_arr[e] = ret_conv_54_b_conv_30_conv;
77                         };
78                         TwoTuple<Uint8Array, TwoTuple<Number, Uint8Array>[]> ret_conv_54_conv = new TwoTuple<Uint8Array, TwoTuple<Number, Uint8Array>[]>(ret_conv_54_a, ret_conv_54_b_conv_30_arr);
79                         // Warning: We may not free the C tuple object!
80                         ret_conv_54_arr[c] = ret_conv_54_conv;
81                 }
82                 return ret_conv_54_arr;
83         }
84
85         public void load_outputs_to_watch(Filter filter) {
86                 bindings.ChannelMonitor_load_outputs_to_watch(this.ptr, filter == null ? 0 : filter.ptr);
87                 this.ptrs_to.add(filter);
88         }
89
90         public MonitorEvent[] get_and_clear_pending_monitor_events() {
91                 number[] ret = bindings.ChannelMonitor_get_and_clear_pending_monitor_events(this.ptr);
92                 MonitorEvent[] ret_conv_14_arr = new MonitorEvent[ret.length];
93                 for (int o = 0; o < ret.length; o++) {
94                         number ret_conv_14 = ret[o];
95                         MonitorEvent ret_conv_14_hu_conv = MonitorEvent.constr_from_ptr(ret_conv_14);
96                         ret_conv_14_hu_conv.ptrs_to.add(this);
97                         ret_conv_14_arr[o] = ret_conv_14_hu_conv;
98                 }
99                 return ret_conv_14_arr;
100         }
101
102         public Event[] get_and_clear_pending_events() {
103                 number[] ret = bindings.ChannelMonitor_get_and_clear_pending_events(this.ptr);
104                 Event[] ret_conv_7_arr = new Event[ret.length];
105                 for (int h = 0; h < ret.length; h++) {
106                         number ret_conv_7 = ret[h];
107                         Event ret_conv_7_hu_conv = Event.constr_from_ptr(ret_conv_7);
108                         ret_conv_7_hu_conv.ptrs_to.add(this);
109                         ret_conv_7_arr[h] = ret_conv_7_hu_conv;
110                 }
111                 return ret_conv_7_arr;
112         }
113
114         public Uint8Array[] get_latest_holder_commitment_txn(Logger logger) {
115                 Uint8Array[] ret = bindings.ChannelMonitor_get_latest_holder_commitment_txn(this.ptr, logger == null ? 0 : logger.ptr);
116                 this.ptrs_to.add(logger);
117                 return ret;
118         }
119
120         public TwoTuple<Uint8Array, TwoTuple<Number, TxOut>[]>[] block_connected(Uint8Array header, TwoTuple<Number, Uint8Array>[] txdata, number height, BroadcasterInterface broadcaster, FeeEstimator fee_estimator, Logger logger) {
121                 number[] ret = bindings.ChannelMonitor_block_connected(this.ptr, header, Arrays.stream(txdata).map(txdata_conv_30 -> bindings.C2Tuple_usizeTransactionZ_new(txdata_conv_30.a, txdata_conv_30.b)).toArray(number[]::new), height, broadcaster == null ? 0 : broadcaster.ptr, fee_estimator == null ? 0 : fee_estimator.ptr, logger == null ? 0 : logger.ptr);
122                 TwoTuple<Uint8Array, TwoTuple<Number, TxOut>[]>[] ret_conv_49_arr = new TwoTuple[ret.length];
123                 for (int x = 0; x < ret.length; x++) {
124                         number ret_conv_49 = ret[x];
125                         Uint8Array ret_conv_49_a = bindings.LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_get_a(ret_conv_49);
126                         number[] ret_conv_49_b = bindings.LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_get_b(ret_conv_49);
127                         TwoTuple<Number, TxOut>[] ret_conv_49_b_conv_25_arr = new TwoTuple[ret_conv_49_b.length];
128                         for (int z = 0; z < ret_conv_49_b.length; z++) {
129                                 number ret_conv_49_b_conv_25 = ret_conv_49_b[z];
130                                 number ret_conv_49_b_conv_25_a = bindings.LDKC2Tuple_u32TxOutZ_get_a(ret_conv_49_b_conv_25);
131                                 number ret_conv_49_b_conv_25_b = bindings.TxOut_clone(bindings.LDKC2Tuple_u32TxOutZ_get_b(ret_conv_49_b_conv_25));
132                                 TxOut ret_conv_49_b_conv_25_b_conv = new TxOut(null, ret_conv_49_b_conv_25_b);;
133                                 TwoTuple<Number, TxOut> ret_conv_49_b_conv_25_conv = new TwoTuple<Number, TxOut>(ret_conv_49_b_conv_25_a, ret_conv_49_b_conv_25_b_conv, () -> {
134                                         bindings.C2Tuple_u32TxOutZ_free(ret_conv_49_b_conv_25);
135                                 });
136                                 ret_conv_49_b_conv_25_b_conv.ptrs_to.add(ret_conv_49_b_conv_25_conv);
137                                 ret_conv_49_b_conv_25_arr[z] = ret_conv_49_b_conv_25_conv;
138                         };
139                         TwoTuple<Uint8Array, TwoTuple<Number, TxOut>[]> ret_conv_49_conv = new TwoTuple<Uint8Array, TwoTuple<Number, TxOut>[]>(ret_conv_49_a, ret_conv_49_b_conv_25_arr);
140                         // Warning: We may not free the C tuple object!
141                         ret_conv_49_arr[x] = ret_conv_49_conv;
142                 }
143                 /* TODO 2 TwoTuple<Number, Uint8Array>  */;
144                 this.ptrs_to.add(broadcaster);
145                 this.ptrs_to.add(fee_estimator);
146                 this.ptrs_to.add(logger);
147                 return ret_conv_49_arr;
148         }
149
150         public void block_disconnected(Uint8Array header, number height, BroadcasterInterface broadcaster, FeeEstimator fee_estimator, Logger logger) {
151                 bindings.ChannelMonitor_block_disconnected(this.ptr, header, height, broadcaster == null ? 0 : broadcaster.ptr, fee_estimator == null ? 0 : fee_estimator.ptr, logger == null ? 0 : logger.ptr);
152                 this.ptrs_to.add(broadcaster);
153                 this.ptrs_to.add(fee_estimator);
154                 this.ptrs_to.add(logger);
155         }
156
157 }