3 import CommonBase from './CommonBase';
4 import * as bindings from '../bindings' // TODO: figure out location
8 export default class ChannelManager extends CommonBase {
9 constructor(_dummy: object, ptr: number) {
14 protected finalize() {
18 bindings.ChannelManager_free(this.ptr);
21 public static ChannelManager constructor_new(FeeEstimator fee_est, Watch chain_monitor, BroadcasterInterface tx_broadcaster, Logger logger, KeysInterface keys_manager, UserConfig config, ChainParameters params) {
22 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);
23 const ret_hu_conv: ChannelManager = new ChannelManager(null, ret);
24 ret_hu_conv.ptrs_to.add(ret_hu_conv);
25 ret_hu_conv.ptrs_to.add(fee_est);
26 ret_hu_conv.ptrs_to.add(chain_monitor);
27 ret_hu_conv.ptrs_to.add(tx_broadcaster);
28 ret_hu_conv.ptrs_to.add(logger);
29 ret_hu_conv.ptrs_to.add(keys_manager);
33 public UserConfig get_current_default_configuration() {
34 number ret = bindings.ChannelManager_get_current_default_configuration(this.ptr);
35 const ret_hu_conv: UserConfig = new UserConfig(null, ret);
36 ret_hu_conv.ptrs_to.add(this);
40 public Result__u832APIErrorZ create_channel(Uint8Array their_network_key, number channel_value_satoshis, number push_msat, number user_channel_id, UserConfig override_config) {
41 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);
42 Result__u832APIErrorZ ret_hu_conv = Result__u832APIErrorZ.constr_from_ptr(ret);
46 public ChannelDetails[] list_channels() {
47 number[] ret = bindings.ChannelManager_list_channels(this.ptr);
48 ChannelDetails[] ret_conv_16_arr = new ChannelDetails[ret.length];
49 for (int q = 0; q < ret.length; q++) {
50 number ret_conv_16 = ret[q];
51 const ret_conv_16_hu_conv: ChannelDetails = new ChannelDetails(null, ret_conv_16);
52 ret_conv_16_hu_conv.ptrs_to.add(this);
53 ret_conv_16_arr[q] = ret_conv_16_hu_conv;
55 return ret_conv_16_arr;
58 public ChannelDetails[] list_usable_channels() {
59 number[] ret = bindings.ChannelManager_list_usable_channels(this.ptr);
60 ChannelDetails[] ret_conv_16_arr = new ChannelDetails[ret.length];
61 for (int q = 0; q < ret.length; q++) {
62 number ret_conv_16 = ret[q];
63 const ret_conv_16_hu_conv: ChannelDetails = new ChannelDetails(null, ret_conv_16);
64 ret_conv_16_hu_conv.ptrs_to.add(this);
65 ret_conv_16_arr[q] = ret_conv_16_hu_conv;
67 return ret_conv_16_arr;
70 public Result_NoneAPIErrorZ close_channel(Uint8Array channel_id) {
71 number ret = bindings.ChannelManager_close_channel(this.ptr, InternalUtils.check_arr_len(channel_id, 32));
72 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
76 public Result_NoneAPIErrorZ close_channel_with_target_feerate(Uint8Array channel_id, number target_feerate_sats_per_1000_weight) {
77 number ret = bindings.ChannelManager_close_channel_with_target_feerate(this.ptr, InternalUtils.check_arr_len(channel_id, 32), target_feerate_sats_per_1000_weight);
78 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
82 public Result_NoneAPIErrorZ force_close_channel(Uint8Array channel_id) {
83 number ret = bindings.ChannelManager_force_close_channel(this.ptr, InternalUtils.check_arr_len(channel_id, 32));
84 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
88 public void force_close_all_channels() {
89 bindings.ChannelManager_force_close_all_channels(this.ptr);
92 public Result_PaymentIdPaymentSendFailureZ send_payment(Route route, Uint8Array payment_hash, Uint8Array payment_secret) {
93 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));
94 Result_PaymentIdPaymentSendFailureZ ret_hu_conv = Result_PaymentIdPaymentSendFailureZ.constr_from_ptr(ret);
95 this.ptrs_to.add(route);
99 public Result_NonePaymentSendFailureZ retry_payment(Route route, Uint8Array payment_id) {
100 number ret = bindings.ChannelManager_retry_payment(this.ptr, route == null ? 0 : route.ptr & ~1, InternalUtils.check_arr_len(payment_id, 32));
101 Result_NonePaymentSendFailureZ ret_hu_conv = Result_NonePaymentSendFailureZ.constr_from_ptr(ret);
102 this.ptrs_to.add(route);
106 public Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ send_spontaneous_payment(Route route, Uint8Array payment_preimage) {
107 number ret = bindings.ChannelManager_send_spontaneous_payment(this.ptr, route == null ? 0 : route.ptr & ~1, InternalUtils.check_arr_len(payment_preimage, 32));
108 Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ.constr_from_ptr(ret);
109 this.ptrs_to.add(route);
113 public Result_NoneAPIErrorZ funding_transaction_generated(Uint8Array temporary_channel_id, Uint8Array funding_transaction) {
114 number ret = bindings.ChannelManager_funding_transaction_generated(this.ptr, InternalUtils.check_arr_len(temporary_channel_id, 32), funding_transaction);
115 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
119 public void broadcast_node_announcement(Uint8Array rgb, Uint8Array alias, NetAddress[] addresses) {
120 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);
123 public void process_pending_htlc_forwards() {
124 bindings.ChannelManager_process_pending_htlc_forwards(this.ptr);
127 public void timer_tick_occurred() {
128 bindings.ChannelManager_timer_tick_occurred(this.ptr);
131 public boolean fail_htlc_backwards(Uint8Array payment_hash) {
132 boolean ret = bindings.ChannelManager_fail_htlc_backwards(this.ptr, InternalUtils.check_arr_len(payment_hash, 32));
136 public boolean claim_funds(Uint8Array payment_preimage) {
137 boolean ret = bindings.ChannelManager_claim_funds(this.ptr, InternalUtils.check_arr_len(payment_preimage, 32));
141 public Uint8Array get_our_node_id() {
142 Uint8Array ret = bindings.ChannelManager_get_our_node_id(this.ptr);
146 public TwoTuple_PaymentHashPaymentSecretZ create_inbound_payment(Option_u64Z min_value_msat, number invoice_expiry_delta_secs, number user_payment_id) {
147 number ret = bindings.ChannelManager_create_inbound_payment(this.ptr, min_value_msat.ptr, invoice_expiry_delta_secs, user_payment_id);
148 TwoTuple_PaymentHashPaymentSecretZ ret_hu_conv = new TwoTuple_PaymentHashPaymentSecretZ(null, ret);
149 ret_hu_conv.ptrs_to.add(this);
153 public Result_PaymentSecretAPIErrorZ create_inbound_payment_for_hash(Uint8Array payment_hash, Option_u64Z min_value_msat, number invoice_expiry_delta_secs, number user_payment_id) {
154 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, user_payment_id);
155 Result_PaymentSecretAPIErrorZ ret_hu_conv = Result_PaymentSecretAPIErrorZ.constr_from_ptr(ret);
159 public MessageSendEventsProvider as_MessageSendEventsProvider() {
160 number ret = bindings.ChannelManager_as_MessageSendEventsProvider(this.ptr);
161 MessageSendEventsProvider ret_hu_conv = new MessageSendEventsProvider(null, ret);
162 ret_hu_conv.ptrs_to.add(this);
166 public EventsProvider as_EventsProvider() {
167 number ret = bindings.ChannelManager_as_EventsProvider(this.ptr);
168 EventsProvider ret_hu_conv = new EventsProvider(null, ret);
169 ret_hu_conv.ptrs_to.add(this);
173 public Listen as_Listen() {
174 number ret = bindings.ChannelManager_as_Listen(this.ptr);
175 Listen ret_hu_conv = new Listen(null, ret);
176 ret_hu_conv.ptrs_to.add(this);
180 public Confirm as_Confirm() {
181 number ret = bindings.ChannelManager_as_Confirm(this.ptr);
182 Confirm ret_hu_conv = new Confirm(null, ret);
183 ret_hu_conv.ptrs_to.add(this);
187 public boolean await_persistable_update_timeout(number max_wait) {
188 boolean ret = bindings.ChannelManager_await_persistable_update_timeout(this.ptr, max_wait);
192 public void await_persistable_update() {
193 bindings.ChannelManager_await_persistable_update(this.ptr);
196 public BestBlock current_best_block() {
197 number ret = bindings.ChannelManager_current_best_block(this.ptr);
198 const ret_hu_conv: BestBlock = new BestBlock(null, ret);
199 ret_hu_conv.ptrs_to.add(this);
203 public ChannelMessageHandler as_ChannelMessageHandler() {
204 number ret = bindings.ChannelManager_as_ChannelMessageHandler(this.ptr);
205 ChannelMessageHandler ret_hu_conv = new ChannelMessageHandler(null, ret);
206 ret_hu_conv.ptrs_to.add(this);
210 public Uint8Array write() {
211 Uint8Array ret = bindings.ChannelManager_write(this.ptr);
215 public Payer as_Payer() {
216 number ret = bindings.ChannelManager_as_Payer(this.ptr);
217 Payer ret_hu_conv = new Payer(null, ret);
218 ret_hu_conv.ptrs_to.add(this);