X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=ts%2Fstructs%2FChannelMonitor.ts;h=af5d1cf911b540cbe2c4ccd017680c4a6ccb570b;hb=b6cc0960eaee5a5bbc7fde79a56152d6dcd649d8;hp=da4255669a8a2153a4ad774c57171be87aa59c04;hpb=822471992c6bf6f9985e531cc5940e4cc35e3e4c;p=ldk-java diff --git a/ts/structs/ChannelMonitor.ts b/ts/structs/ChannelMonitor.ts index da425566..af5d1cf9 100644 --- a/ts/structs/ChannelMonitor.ts +++ b/ts/structs/ChannelMonitor.ts @@ -1,22 +1,37 @@ + import CommonBase from './CommonBase'; import * as bindings from '../bindings' // TODO: figure out location -public class ChannelMonitor extends CommonBase { - ChannelMonitor(Object _dummy, long ptr) { super(ptr); } - @Override @SuppressWarnings("deprecation") - protected void finalize() throws Throwable { - super.finalize(); - if (ptr != 0) { bindings.ChannelMonitor_free(ptr); } + + + export default class ChannelMonitor extends CommonBase { + constructor(_dummy: object, ptr: number) { + super(ptr); + } + + + protected finalize() { + super.finalize(); + + if (this.ptr != 0) { + bindings.ChannelMonitor_free(this.ptr); + } + } + public ChannelMonitor clone() { + number ret = bindings.ChannelMonitor_clone(this.ptr); + const ret_hu_conv: ChannelMonitor = new ChannelMonitor(null, ret); + ret_hu_conv.ptrs_to.add(this); + return ret_hu_conv; } - public byte[] write() { - byte[] ret = bindings.ChannelMonitor_write(this.ptr); + public Uint8Array write() { + Uint8Array ret = bindings.ChannelMonitor_write(this.ptr); return ret; } public Result_NoneMonitorUpdateErrorZ update_monitor(ChannelMonitorUpdate updates, BroadcasterInterface broadcaster, FeeEstimator fee_estimator, Logger logger) { - uint32_t 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); + 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); Result_NoneMonitorUpdateErrorZ ret_hu_conv = Result_NoneMonitorUpdateErrorZ.constr_from_ptr(ret); this.ptrs_to.add(updates); this.ptrs_to.add(broadcaster); @@ -25,80 +40,189 @@ public class ChannelMonitor extends CommonBase { return ret_hu_conv; } - public long get_latest_update_id() { - long ret = bindings.ChannelMonitor_get_latest_update_id(this.ptr); + public number get_latest_update_id() { + number ret = bindings.ChannelMonitor_get_latest_update_id(this.ptr); return ret; } - public TwoTuple get_funding_txo() { - uint32_t ret = bindings.ChannelMonitor_get_funding_txo(this.ptr); - uint32_t ret_a = bindings.LDKC2Tuple_OutPointScriptZ_get_a(ret); - OutPoint ret_a_hu_conv = new OutPoint(null, ret_a);; - byte[] ret_b = bindings.LDKC2Tuple_OutPointScriptZ_get_b(ret); - TwoTuple ret_conv = new TwoTuple(ret_a_hu_conv, ret_b); + public TwoTuple get_funding_txo() { + number ret = bindings.ChannelMonitor_get_funding_txo(this.ptr); + number ret_a = bindings.LDKC2Tuple_OutPointScriptZ_get_a(ret); + const ret_a_hu_conv: OutPoint = new OutPoint(null, ret_a); + ret_a_hu_conv.ptrs_to.add(this);; + Uint8Array ret_b = bindings.LDKC2Tuple_OutPointScriptZ_get_b(ret); + TwoTuple ret_conv = new TwoTuple(ret_a_hu_conv, ret_b, () -> { + bindings.C2Tuple_OutPointScriptZ_free(ret); + }); + ret_a_hu_conv.ptrs_to.add(ret_conv); return ret_conv; } + public TwoTuple[]>[] get_outputs_to_watch() { + number[] ret = bindings.ChannelMonitor_get_outputs_to_watch(this.ptr); + TwoTuple[]>[] ret_conv_54_arr = new TwoTuple[ret.length]; + for (int c = 0; c < ret.length; c++) { + number ret_conv_54 = ret[c]; + Uint8Array ret_conv_54_a = bindings.LDKC2Tuple_TxidCVec_C2Tuple_u32ScriptZZZ_get_a(ret_conv_54); + number[] ret_conv_54_b = bindings.LDKC2Tuple_TxidCVec_C2Tuple_u32ScriptZZZ_get_b(ret_conv_54); + TwoTuple[] ret_conv_54_b_conv_30_arr = new TwoTuple[ret_conv_54_b.length]; + for (int e = 0; e < ret_conv_54_b.length; e++) { + number ret_conv_54_b_conv_30 = ret_conv_54_b[e]; + number ret_conv_54_b_conv_30_a = bindings.LDKC2Tuple_u32ScriptZ_get_a(ret_conv_54_b_conv_30); + Uint8Array ret_conv_54_b_conv_30_b = bindings.LDKC2Tuple_u32ScriptZ_get_b(ret_conv_54_b_conv_30); + TwoTuple ret_conv_54_b_conv_30_conv = new TwoTuple(ret_conv_54_b_conv_30_a, ret_conv_54_b_conv_30_b, () -> { + bindings.C2Tuple_u32ScriptZ_free(ret_conv_54_b_conv_30); + }); + ret_conv_54_b_conv_30_arr[e] = ret_conv_54_b_conv_30_conv; + }; + TwoTuple[]> ret_conv_54_conv = new TwoTuple[]>(ret_conv_54_a, ret_conv_54_b_conv_30_arr); + // Warning: We may not free the C tuple object! + ret_conv_54_arr[c] = ret_conv_54_conv; + } + return ret_conv_54_arr; + } + + public void load_outputs_to_watch(Filter filter) { + bindings.ChannelMonitor_load_outputs_to_watch(this.ptr, filter == null ? 0 : filter.ptr); + this.ptrs_to.add(filter); + } + public MonitorEvent[] get_and_clear_pending_monitor_events() { - uint32_t[] ret = bindings.ChannelMonitor_get_and_clear_pending_monitor_events(this.ptr); - MonitorEvent[] arr_conv_14_arr = new MonitorEvent[ret.length]; + number[] ret = bindings.ChannelMonitor_get_and_clear_pending_monitor_events(this.ptr); + MonitorEvent[] ret_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); - arr_conv_14_arr[o] = arr_conv_14_hu_conv; + number ret_conv_14 = ret[o]; + MonitorEvent ret_conv_14_hu_conv = MonitorEvent.constr_from_ptr(ret_conv_14); + ret_conv_14_hu_conv.ptrs_to.add(this); + ret_conv_14_arr[o] = ret_conv_14_hu_conv; } - return arr_conv_14_arr; + return ret_conv_14_arr; } public Event[] get_and_clear_pending_events() { - uint32_t[] ret = bindings.ChannelMonitor_get_and_clear_pending_events(this.ptr); - Event[] arr_conv_7_arr = new Event[ret.length]; + number[] ret = bindings.ChannelMonitor_get_and_clear_pending_events(this.ptr); + Event[] ret_conv_7_arr = new Event[ret.length]; for (int h = 0; h < ret.length; h++) { - uint32_t arr_conv_7 = ret[h]; - Event arr_conv_7_hu_conv = Event.constr_from_ptr(arr_conv_7); - arr_conv_7_hu_conv.ptrs_to.add(this); - arr_conv_7_arr[h] = arr_conv_7_hu_conv; + number ret_conv_7 = ret[h]; + Event ret_conv_7_hu_conv = Event.constr_from_ptr(ret_conv_7); + ret_conv_7_hu_conv.ptrs_to.add(this); + ret_conv_7_arr[h] = ret_conv_7_hu_conv; } - return arr_conv_7_arr; + return ret_conv_7_arr; } - public byte[][] get_latest_holder_commitment_txn(Logger logger) { - byte[][] ret = bindings.ChannelMonitor_get_latest_holder_commitment_txn(this.ptr, logger == null ? 0 : logger.ptr); + public Uint8Array[] get_latest_holder_commitment_txn(Logger logger) { + Uint8Array[] ret = bindings.ChannelMonitor_get_latest_holder_commitment_txn(this.ptr, logger == null ? 0 : logger.ptr); this.ptrs_to.add(logger); return ret; } - public TwoTuple[]>[] block_connected(byte[] header, TwoTuple[] txdata, int height, BroadcasterInterface broadcaster, FeeEstimator fee_estimator, Logger logger) { - uint32_t[] ret = bindings.ChannelMonitor_block_connected(this.ptr, header, (uint32_t[])Arrays.stream(txdata).map(arr_conv_24 -> bindings.C2Tuple_usizeTransactionZ_new(arr_conv_24.a, arr_conv_24.b)).toArray(), height, broadcaster == null ? 0 : broadcaster.ptr, fee_estimator == null ? 0 : fee_estimator.ptr, logger == null ? 0 : logger.ptr); - TwoTuple[]>[] arr_conv_46_arr = new TwoTuple[ret.length]; - for (int u = 0; u < ret.length; u++) { - uint32_t arr_conv_46 = ret[u]; - byte[] arr_conv_46_a = bindings.LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_get_a(arr_conv_46); - uint32_t[] arr_conv_46_b = bindings.LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_get_b(arr_conv_46); - TwoTuple[] arr_conv_26_arr = new TwoTuple[arr_conv_46_b.length]; - for (int a = 0; a < arr_conv_46_b.length; a++) { - uint32_t arr_conv_26 = arr_conv_46_b[a]; - int arr_conv_26_a = bindings.LDKC2Tuple_u32TxOutZ_get_a(arr_conv_26); - uint32_t arr_conv_26_b = bindings.LDKC2Tuple_u32TxOutZ_get_b(arr_conv_26); - TxOut arr_conv_26_b_conv = new TxOut(null, arr_conv_26_b);; - TwoTuple arr_conv_26_conv = new TwoTuple(arr_conv_26_a, arr_conv_26_b_conv); - arr_conv_26_arr[a] = arr_conv_26_conv; + public TwoTuple[]>[] block_connected(Uint8Array header, TwoTuple[] txdata, number height, BroadcasterInterface broadcaster, FeeEstimator fee_estimator, Logger logger) { + 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); + TwoTuple[]>[] ret_conv_49_arr = new TwoTuple[ret.length]; + for (int x = 0; x < ret.length; x++) { + number ret_conv_49 = ret[x]; + Uint8Array ret_conv_49_a = bindings.LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_get_a(ret_conv_49); + number[] ret_conv_49_b = bindings.LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_get_b(ret_conv_49); + TwoTuple[] ret_conv_49_b_conv_25_arr = new TwoTuple[ret_conv_49_b.length]; + for (int z = 0; z < ret_conv_49_b.length; z++) { + number ret_conv_49_b_conv_25 = ret_conv_49_b[z]; + number ret_conv_49_b_conv_25_a = bindings.LDKC2Tuple_u32TxOutZ_get_a(ret_conv_49_b_conv_25); + number ret_conv_49_b_conv_25_b = bindings.TxOut_clone(bindings.LDKC2Tuple_u32TxOutZ_get_b(ret_conv_49_b_conv_25)); + TxOut ret_conv_49_b_conv_25_b_conv = new TxOut(null, ret_conv_49_b_conv_25_b);; + TwoTuple ret_conv_49_b_conv_25_conv = new TwoTuple(ret_conv_49_b_conv_25_a, ret_conv_49_b_conv_25_b_conv, () -> { + bindings.C2Tuple_u32TxOutZ_free(ret_conv_49_b_conv_25); + }); + ret_conv_49_b_conv_25_b_conv.ptrs_to.add(ret_conv_49_b_conv_25_conv); + ret_conv_49_b_conv_25_arr[z] = ret_conv_49_b_conv_25_conv; }; - TwoTuple[]> arr_conv_46_conv = new TwoTuple[]>(arr_conv_46_a, arr_conv_26_arr); - arr_conv_46_arr[u] = arr_conv_46_conv; + TwoTuple[]> ret_conv_49_conv = new TwoTuple[]>(ret_conv_49_a, ret_conv_49_b_conv_25_arr); + // Warning: We may not free the C tuple object! + ret_conv_49_arr[x] = ret_conv_49_conv; } - /* TODO 2 TwoTuple */; + /* TODO 2 TwoTuple */; this.ptrs_to.add(broadcaster); this.ptrs_to.add(fee_estimator); this.ptrs_to.add(logger); - return arr_conv_46_arr; + return ret_conv_49_arr; } - public void block_disconnected(byte[] header, int height, BroadcasterInterface broadcaster, FeeEstimator fee_estimator, Logger logger) { + public void block_disconnected(Uint8Array header, number height, BroadcasterInterface broadcaster, FeeEstimator fee_estimator, Logger logger) { 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); this.ptrs_to.add(broadcaster); this.ptrs_to.add(fee_estimator); this.ptrs_to.add(logger); } + public TwoTuple[]>[] transactions_confirmed(Uint8Array header, TwoTuple[] txdata, number height, BroadcasterInterface broadcaster, FeeEstimator fee_estimator, Logger logger) { + number[] ret = bindings.ChannelMonitor_transactions_confirmed(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); + TwoTuple[]>[] ret_conv_49_arr = new TwoTuple[ret.length]; + for (int x = 0; x < ret.length; x++) { + number ret_conv_49 = ret[x]; + Uint8Array ret_conv_49_a = bindings.LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_get_a(ret_conv_49); + number[] ret_conv_49_b = bindings.LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_get_b(ret_conv_49); + TwoTuple[] ret_conv_49_b_conv_25_arr = new TwoTuple[ret_conv_49_b.length]; + for (int z = 0; z < ret_conv_49_b.length; z++) { + number ret_conv_49_b_conv_25 = ret_conv_49_b[z]; + number ret_conv_49_b_conv_25_a = bindings.LDKC2Tuple_u32TxOutZ_get_a(ret_conv_49_b_conv_25); + number ret_conv_49_b_conv_25_b = bindings.TxOut_clone(bindings.LDKC2Tuple_u32TxOutZ_get_b(ret_conv_49_b_conv_25)); + TxOut ret_conv_49_b_conv_25_b_conv = new TxOut(null, ret_conv_49_b_conv_25_b);; + TwoTuple ret_conv_49_b_conv_25_conv = new TwoTuple(ret_conv_49_b_conv_25_a, ret_conv_49_b_conv_25_b_conv, () -> { + bindings.C2Tuple_u32TxOutZ_free(ret_conv_49_b_conv_25); + }); + ret_conv_49_b_conv_25_b_conv.ptrs_to.add(ret_conv_49_b_conv_25_conv); + ret_conv_49_b_conv_25_arr[z] = ret_conv_49_b_conv_25_conv; + }; + TwoTuple[]> ret_conv_49_conv = new TwoTuple[]>(ret_conv_49_a, ret_conv_49_b_conv_25_arr); + // Warning: We may not free the C tuple object! + ret_conv_49_arr[x] = ret_conv_49_conv; + } + /* TODO 2 TwoTuple */; + this.ptrs_to.add(broadcaster); + this.ptrs_to.add(fee_estimator); + this.ptrs_to.add(logger); + return ret_conv_49_arr; + } + + public void transaction_unconfirmed(Uint8Array txid, BroadcasterInterface broadcaster, FeeEstimator fee_estimator, Logger logger) { + bindings.ChannelMonitor_transaction_unconfirmed(this.ptr, txid, broadcaster == null ? 0 : broadcaster.ptr, fee_estimator == null ? 0 : fee_estimator.ptr, logger == null ? 0 : logger.ptr); + this.ptrs_to.add(broadcaster); + this.ptrs_to.add(fee_estimator); + this.ptrs_to.add(logger); + } + + public TwoTuple[]>[] best_block_updated(Uint8Array header, number height, BroadcasterInterface broadcaster, FeeEstimator fee_estimator, Logger logger) { + number[] ret = bindings.ChannelMonitor_best_block_updated(this.ptr, header, height, broadcaster == null ? 0 : broadcaster.ptr, fee_estimator == null ? 0 : fee_estimator.ptr, logger == null ? 0 : logger.ptr); + TwoTuple[]>[] ret_conv_49_arr = new TwoTuple[ret.length]; + for (int x = 0; x < ret.length; x++) { + number ret_conv_49 = ret[x]; + Uint8Array ret_conv_49_a = bindings.LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_get_a(ret_conv_49); + number[] ret_conv_49_b = bindings.LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_get_b(ret_conv_49); + TwoTuple[] ret_conv_49_b_conv_25_arr = new TwoTuple[ret_conv_49_b.length]; + for (int z = 0; z < ret_conv_49_b.length; z++) { + number ret_conv_49_b_conv_25 = ret_conv_49_b[z]; + number ret_conv_49_b_conv_25_a = bindings.LDKC2Tuple_u32TxOutZ_get_a(ret_conv_49_b_conv_25); + number ret_conv_49_b_conv_25_b = bindings.TxOut_clone(bindings.LDKC2Tuple_u32TxOutZ_get_b(ret_conv_49_b_conv_25)); + TxOut ret_conv_49_b_conv_25_b_conv = new TxOut(null, ret_conv_49_b_conv_25_b);; + TwoTuple ret_conv_49_b_conv_25_conv = new TwoTuple(ret_conv_49_b_conv_25_a, ret_conv_49_b_conv_25_b_conv, () -> { + bindings.C2Tuple_u32TxOutZ_free(ret_conv_49_b_conv_25); + }); + ret_conv_49_b_conv_25_b_conv.ptrs_to.add(ret_conv_49_b_conv_25_conv); + ret_conv_49_b_conv_25_arr[z] = ret_conv_49_b_conv_25_conv; + }; + TwoTuple[]> ret_conv_49_conv = new TwoTuple[]>(ret_conv_49_a, ret_conv_49_b_conv_25_arr); + // Warning: We may not free the C tuple object! + ret_conv_49_arr[x] = ret_conv_49_conv; + } + this.ptrs_to.add(broadcaster); + this.ptrs_to.add(fee_estimator); + this.ptrs_to.add(logger); + return ret_conv_49_arr; + } + + public Uint8Array[] get_relevant_txids() { + Uint8Array[] ret = bindings.ChannelMonitor_get_relevant_txids(this.ptr); + return ret; + } + }