X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=ts%2Fstructs%2FChannelManager.ts;h=5c483a3d4c07631c5a82526e23cf28794a2a3b7a;hb=1854b5cebef22ace9e9e4dd191f609818df9ce08;hp=2908997b29dc81ca2c3b942b609800aaf9a13fcb;hpb=822471992c6bf6f9985e531cc5940e4cc35e3e4c;p=ldk-java diff --git a/ts/structs/ChannelManager.ts b/ts/structs/ChannelManager.ts index 2908997b..5c483a3d 100644 --- a/ts/structs/ChannelManager.ts +++ b/ts/structs/ChannelManager.ts @@ -1,148 +1,243 @@ + import CommonBase from './CommonBase'; import * as bindings from '../bindings' // TODO: figure out location -public class ChannelManager extends CommonBase { - ChannelManager(Object _dummy, long ptr) { super(ptr); } - @Override @SuppressWarnings("deprecation") - protected void finalize() throws Throwable { - super.finalize(); - if (ptr != 0) { bindings.ChannelManager_free(ptr); } - } - public static ChannelManager constructor_new(LDKNetwork network, FeeEstimator fee_est, Watch chain_monitor, BroadcasterInterface tx_broadcaster, Logger logger, KeysInterface keys_manager, UserConfig config, long current_blockchain_height) { - uint32_t ret = bindings.ChannelManager_new(network, fee_est == null ? 0 : fee_est.ptr, chain_monitor == null ? 0 : chain_monitor.ptr, tx_broadcaster == null ? 0 : tx_broadcaster.ptr, logger == null ? 0 : logger.ptr, keys_manager == null ? 0 : keys_manager.ptr, config == null ? 0 : config.ptr & ~1, current_blockchain_height); - ChannelManager ret_hu_conv = new ChannelManager(null, ret); + + export default class ChannelManager extends CommonBase { + constructor(_dummy: object, ptr: number) { + super(ptr); + } + + + protected finalize() { + super.finalize(); + + if (this.ptr != 0) { + bindings.ChannelManager_free(this.ptr); + } + } + public static ChannelManager constructor_new(FeeEstimator fee_est, Watch chain_monitor, BroadcasterInterface tx_broadcaster, Logger logger, KeysInterface keys_manager, UserConfig config, ChainParameters params) { + number ret = bindings.ChannelManager_new(fee_est == null ? 0 : fee_est.ptr, chain_monitor == null ? 0 : chain_monitor.ptr, tx_broadcaster == null ? 0 : tx_broadcaster.ptr, logger == null ? 0 : logger.ptr, keys_manager == null ? 0 : keys_manager.ptr, config == null ? 0 : config.ptr & ~1, params == null ? 0 : params.ptr & ~1); + const ret_hu_conv: ChannelManager = new ChannelManager(null, ret); + ret_hu_conv.ptrs_to.add(ret_hu_conv); ret_hu_conv.ptrs_to.add(fee_est); ret_hu_conv.ptrs_to.add(chain_monitor); ret_hu_conv.ptrs_to.add(tx_broadcaster); ret_hu_conv.ptrs_to.add(logger); ret_hu_conv.ptrs_to.add(keys_manager); - ret_hu_conv.ptrs_to.add(config); return ret_hu_conv; } - public Result_NoneAPIErrorZ create_channel(byte[] their_network_key, long channel_value_satoshis, long push_msat, long user_id, UserConfig override_config) { - uint32_t ret = bindings.ChannelManager_create_channel(this.ptr, their_network_key, channel_value_satoshis, push_msat, user_id, override_config == null ? 0 : override_config.ptr & ~1); - Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret); - this.ptrs_to.add(override_config); + public UserConfig get_current_default_configuration() { + number ret = bindings.ChannelManager_get_current_default_configuration(this.ptr); + const ret_hu_conv: UserConfig = new UserConfig(null, ret); + ret_hu_conv.ptrs_to.add(this); + return ret_hu_conv; + } + + public Result__u832APIErrorZ create_channel(Uint8Array their_network_key, number channel_value_satoshis, number push_msat, number user_channel_id, UserConfig override_config) { + number ret = bindings.ChannelManager_create_channel(this.ptr, InternalUtils.check_arr_len(their_network_key, 33), channel_value_satoshis, push_msat, user_channel_id, override_config == null ? 0 : override_config.ptr & ~1); + Result__u832APIErrorZ ret_hu_conv = Result__u832APIErrorZ.constr_from_ptr(ret); return ret_hu_conv; } public ChannelDetails[] list_channels() { - uint32_t[] ret = bindings.ChannelManager_list_channels(this.ptr); - ChannelDetails[] arr_conv_16_arr = new ChannelDetails[ret.length]; + number[] ret = bindings.ChannelManager_list_channels(this.ptr); + ChannelDetails[] ret_conv_16_arr = new ChannelDetails[ret.length]; for (int q = 0; q < ret.length; q++) { - uint32_t arr_conv_16 = ret[q]; - ChannelDetails arr_conv_16_hu_conv = new ChannelDetails(null, arr_conv_16); - arr_conv_16_arr[q] = arr_conv_16_hu_conv; + number ret_conv_16 = ret[q]; + const ret_conv_16_hu_conv: ChannelDetails = new ChannelDetails(null, ret_conv_16); + ret_conv_16_hu_conv.ptrs_to.add(this); + ret_conv_16_arr[q] = ret_conv_16_hu_conv; } - return arr_conv_16_arr; + return ret_conv_16_arr; } public ChannelDetails[] list_usable_channels() { - uint32_t[] ret = bindings.ChannelManager_list_usable_channels(this.ptr); - ChannelDetails[] arr_conv_16_arr = new ChannelDetails[ret.length]; + number[] ret = bindings.ChannelManager_list_usable_channels(this.ptr); + ChannelDetails[] ret_conv_16_arr = new ChannelDetails[ret.length]; for (int q = 0; q < ret.length; q++) { - uint32_t arr_conv_16 = ret[q]; - ChannelDetails arr_conv_16_hu_conv = new ChannelDetails(null, arr_conv_16); - arr_conv_16_arr[q] = arr_conv_16_hu_conv; + number ret_conv_16 = ret[q]; + const ret_conv_16_hu_conv: ChannelDetails = new ChannelDetails(null, ret_conv_16); + ret_conv_16_hu_conv.ptrs_to.add(this); + ret_conv_16_arr[q] = ret_conv_16_hu_conv; } - return arr_conv_16_arr; + return ret_conv_16_arr; } - public Result_NoneAPIErrorZ close_channel(byte[] channel_id) { - uint32_t ret = bindings.ChannelManager_close_channel(this.ptr, channel_id); + public Result_NoneAPIErrorZ close_channel(Uint8Array channel_id) { + number ret = bindings.ChannelManager_close_channel(this.ptr, InternalUtils.check_arr_len(channel_id, 32)); Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret); return ret_hu_conv; } - public void force_close_channel(byte[] channel_id) { - bindings.ChannelManager_force_close_channel(this.ptr, channel_id); + public Result_NoneAPIErrorZ close_channel_with_target_feerate(Uint8Array channel_id, number target_feerate_sats_per_1000_weight) { + number ret = bindings.ChannelManager_close_channel_with_target_feerate(this.ptr, InternalUtils.check_arr_len(channel_id, 32), target_feerate_sats_per_1000_weight); + Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret); + return ret_hu_conv; + } + + public Result_NoneAPIErrorZ force_close_channel(Uint8Array channel_id) { + number ret = bindings.ChannelManager_force_close_channel(this.ptr, InternalUtils.check_arr_len(channel_id, 32)); + Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret); + return ret_hu_conv; } public void force_close_all_channels() { bindings.ChannelManager_force_close_all_channels(this.ptr); } - public Result_NonePaymentSendFailureZ send_payment(Route route, byte[] payment_hash, byte[] payment_secret) { - uint32_t ret = bindings.ChannelManager_send_payment(this.ptr, route == null ? 0 : route.ptr & ~1, payment_hash, payment_secret); + public Result_PaymentIdPaymentSendFailureZ send_payment(Route route, Uint8Array payment_hash, Uint8Array payment_secret) { + number ret = bindings.ChannelManager_send_payment(this.ptr, route == null ? 0 : route.ptr & ~1, InternalUtils.check_arr_len(payment_hash, 32), InternalUtils.check_arr_len(payment_secret, 32)); + Result_PaymentIdPaymentSendFailureZ ret_hu_conv = Result_PaymentIdPaymentSendFailureZ.constr_from_ptr(ret); + this.ptrs_to.add(route); + return ret_hu_conv; + } + + public Result_NonePaymentSendFailureZ retry_payment(Route route, Uint8Array payment_id) { + number ret = bindings.ChannelManager_retry_payment(this.ptr, route == null ? 0 : route.ptr & ~1, InternalUtils.check_arr_len(payment_id, 32)); Result_NonePaymentSendFailureZ ret_hu_conv = Result_NonePaymentSendFailureZ.constr_from_ptr(ret); this.ptrs_to.add(route); return ret_hu_conv; } - public void funding_transaction_generated(byte[] temporary_channel_id, OutPoint funding_txo) { - bindings.ChannelManager_funding_transaction_generated(this.ptr, temporary_channel_id, funding_txo == null ? 0 : funding_txo.ptr & ~1); - this.ptrs_to.add(funding_txo); + public void abandon_payment(Uint8Array payment_id) { + bindings.ChannelManager_abandon_payment(this.ptr, InternalUtils.check_arr_len(payment_id, 32)); + } + + public Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ send_spontaneous_payment(Route route, Uint8Array payment_preimage) { + number ret = bindings.ChannelManager_send_spontaneous_payment(this.ptr, route == null ? 0 : route.ptr & ~1, InternalUtils.check_arr_len(payment_preimage, 32)); + Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ.constr_from_ptr(ret); + this.ptrs_to.add(route); + return ret_hu_conv; + } + + public Result_NoneAPIErrorZ funding_transaction_generated(Uint8Array temporary_channel_id, Uint8Array funding_transaction) { + number ret = bindings.ChannelManager_funding_transaction_generated(this.ptr, InternalUtils.check_arr_len(temporary_channel_id, 32), funding_transaction); + Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret); + return ret_hu_conv; } - public void broadcast_node_announcement(byte[] rgb, byte[] alias, NetAddress[] addresses) { - bindings.ChannelManager_broadcast_node_announcement(this.ptr, rgb, alias, (uint32_t[])Arrays.stream(addresses).map(arr_conv_12 -> arr_conv_12.ptr).toArray()); - /* TODO 2 NetAddress */; + public void broadcast_node_announcement(Uint8Array rgb, Uint8Array alias, NetAddress[] addresses) { + bindings.ChannelManager_broadcast_node_announcement(this.ptr, InternalUtils.check_arr_len(rgb, 3), InternalUtils.check_arr_len(alias, 32), addresses != null ? Arrays.stream(addresses).map(addresses_conv_12 -> addresses_conv_12.ptr).toArray(number[]::new) : null); } public void process_pending_htlc_forwards() { bindings.ChannelManager_process_pending_htlc_forwards(this.ptr); } - public void timer_chan_freshness_every_min() { - bindings.ChannelManager_timer_chan_freshness_every_min(this.ptr); + public void timer_tick_occurred() { + bindings.ChannelManager_timer_tick_occurred(this.ptr); } - public boolean fail_htlc_backwards(byte[] payment_hash, byte[] payment_secret) { - boolean ret = bindings.ChannelManager_fail_htlc_backwards(this.ptr, payment_hash, payment_secret); + public boolean fail_htlc_backwards(Uint8Array payment_hash) { + boolean ret = bindings.ChannelManager_fail_htlc_backwards(this.ptr, InternalUtils.check_arr_len(payment_hash, 32)); return ret; } - public boolean claim_funds(byte[] payment_preimage, byte[] payment_secret, long expected_amount) { - boolean ret = bindings.ChannelManager_claim_funds(this.ptr, payment_preimage, payment_secret, expected_amount); + public boolean claim_funds(Uint8Array payment_preimage) { + boolean ret = bindings.ChannelManager_claim_funds(this.ptr, InternalUtils.check_arr_len(payment_preimage, 32)); return ret; } - public byte[] get_our_node_id() { - byte[] ret = bindings.ChannelManager_get_our_node_id(this.ptr); + public Uint8Array get_our_node_id() { + Uint8Array ret = bindings.ChannelManager_get_our_node_id(this.ptr); return ret; } - public void channel_monitor_updated(OutPoint funding_txo, long highest_applied_update_id) { - bindings.ChannelManager_channel_monitor_updated(this.ptr, funding_txo == null ? 0 : funding_txo.ptr & ~1, highest_applied_update_id); - this.ptrs_to.add(funding_txo); + public Result_C2Tuple_PaymentHashPaymentSecretZNoneZ create_inbound_payment(Option_u64Z min_value_msat, number invoice_expiry_delta_secs) { + number ret = bindings.ChannelManager_create_inbound_payment(this.ptr, min_value_msat.ptr, invoice_expiry_delta_secs); + Result_C2Tuple_PaymentHashPaymentSecretZNoneZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentSecretZNoneZ.constr_from_ptr(ret); + return ret_hu_conv; + } + + public Result_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ create_inbound_payment_legacy(Option_u64Z min_value_msat, number invoice_expiry_delta_secs) { + number ret = bindings.ChannelManager_create_inbound_payment_legacy(this.ptr, min_value_msat.ptr, invoice_expiry_delta_secs); + Result_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ.constr_from_ptr(ret); + return ret_hu_conv; + } + + public Result_PaymentSecretNoneZ create_inbound_payment_for_hash(Uint8Array payment_hash, Option_u64Z min_value_msat, number invoice_expiry_delta_secs) { + number ret = bindings.ChannelManager_create_inbound_payment_for_hash(this.ptr, InternalUtils.check_arr_len(payment_hash, 32), min_value_msat.ptr, invoice_expiry_delta_secs); + Result_PaymentSecretNoneZ ret_hu_conv = Result_PaymentSecretNoneZ.constr_from_ptr(ret); + return ret_hu_conv; + } + + public Result_PaymentSecretAPIErrorZ create_inbound_payment_for_hash_legacy(Uint8Array payment_hash, Option_u64Z min_value_msat, number invoice_expiry_delta_secs) { + number ret = bindings.ChannelManager_create_inbound_payment_for_hash_legacy(this.ptr, InternalUtils.check_arr_len(payment_hash, 32), min_value_msat.ptr, invoice_expiry_delta_secs); + Result_PaymentSecretAPIErrorZ ret_hu_conv = Result_PaymentSecretAPIErrorZ.constr_from_ptr(ret); + return ret_hu_conv; + } + + public Result_PaymentPreimageAPIErrorZ get_payment_preimage(Uint8Array payment_hash, Uint8Array payment_secret) { + number ret = bindings.ChannelManager_get_payment_preimage(this.ptr, InternalUtils.check_arr_len(payment_hash, 32), InternalUtils.check_arr_len(payment_secret, 32)); + Result_PaymentPreimageAPIErrorZ ret_hu_conv = Result_PaymentPreimageAPIErrorZ.constr_from_ptr(ret); + return ret_hu_conv; } public MessageSendEventsProvider as_MessageSendEventsProvider() { - uint32_t ret = bindings.ChannelManager_as_MessageSendEventsProvider(this.ptr); + number ret = bindings.ChannelManager_as_MessageSendEventsProvider(this.ptr); MessageSendEventsProvider ret_hu_conv = new MessageSendEventsProvider(null, ret); ret_hu_conv.ptrs_to.add(this); return ret_hu_conv; } public EventsProvider as_EventsProvider() { - uint32_t ret = bindings.ChannelManager_as_EventsProvider(this.ptr); + number ret = bindings.ChannelManager_as_EventsProvider(this.ptr); EventsProvider ret_hu_conv = new EventsProvider(null, ret); ret_hu_conv.ptrs_to.add(this); return ret_hu_conv; } - public void block_connected(byte[] header, TwoTuple[] txdata, int height) { - bindings.ChannelManager_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); - /* TODO 2 TwoTuple */; + public Listen as_Listen() { + number ret = bindings.ChannelManager_as_Listen(this.ptr); + Listen ret_hu_conv = new Listen(null, ret); + ret_hu_conv.ptrs_to.add(this); + return ret_hu_conv; + } + + public Confirm as_Confirm() { + number ret = bindings.ChannelManager_as_Confirm(this.ptr); + Confirm ret_hu_conv = new Confirm(null, ret); + ret_hu_conv.ptrs_to.add(this); + return ret_hu_conv; + } + + public boolean await_persistable_update_timeout(number max_wait) { + boolean ret = bindings.ChannelManager_await_persistable_update_timeout(this.ptr, max_wait); + return ret; + } + + public void await_persistable_update() { + bindings.ChannelManager_await_persistable_update(this.ptr); } - public void block_disconnected(byte[] header) { - bindings.ChannelManager_block_disconnected(this.ptr, header); + public BestBlock current_best_block() { + number ret = bindings.ChannelManager_current_best_block(this.ptr); + const ret_hu_conv: BestBlock = new BestBlock(null, ret); + ret_hu_conv.ptrs_to.add(this); + return ret_hu_conv; } public ChannelMessageHandler as_ChannelMessageHandler() { - uint32_t ret = bindings.ChannelManager_as_ChannelMessageHandler(this.ptr); + number ret = bindings.ChannelManager_as_ChannelMessageHandler(this.ptr); ChannelMessageHandler ret_hu_conv = new ChannelMessageHandler(null, ret); ret_hu_conv.ptrs_to.add(this); return ret_hu_conv; } - public byte[] write() { - byte[] ret = bindings.ChannelManager_write(this.ptr); + public Uint8Array write() { + Uint8Array ret = bindings.ChannelManager_write(this.ptr); return ret; } + public Payer as_Payer() { + number ret = bindings.ChannelManager_as_Payer(this.ptr); + Payer ret_hu_conv = new Payer(null, ret); + ret_hu_conv.ptrs_to.add(this); + return ret_hu_conv; + } + }