X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=sidebyside;f=ts%2Fstructs%2FEvent.mts;h=6204b4d115f930361ada303413ea760fcd732156;hb=c629a01650402c8e2f9b9db8ced9ed63ce687727;hp=96d219675cd500ec577f2893a00e8f25c8882a82;hpb=2a65456aa0b540060dcf3ca707a54dc98cc3f38a;p=ldk-java diff --git a/ts/structs/Event.mts b/ts/structs/Event.mts index 96d21967..6204b4d1 100644 --- a/ts/structs/Event.mts +++ b/ts/structs/Event.mts @@ -279,47 +279,34 @@ import { MultiThreadedLockableScore } from '../structs/MultiThreadedLockableScor import CommonBase from './CommonBase.mjs'; import * as bindings from '../bindings.mjs' -import * as InternalUtils from '../InternalUtils.mjs' +/** + * An Event which you should probably take some action in response to. + * + * Note that while Writeable and Readable are implemented for Event, you probably shouldn't use + * them directly as they don't round-trip exactly (for example FundingGenerationReady is never + * written as it makes no sense to respond to it after reconnecting to peers). + */ export class Event extends CommonBase { protected constructor(_dummy: object, ptr: number) { super(ptr, bindings.Event_free); } /* @internal */ public static constr_from_ptr(ptr: number): Event { - const raw_val: bindings.LDKEvent = bindings.LDKEvent_ref_from_ptr(ptr); - if (raw_val instanceof bindings.LDKEvent_FundingGenerationReady) { - return new Event_FundingGenerationReady(ptr, raw_val); + const raw_ty: number = bindings.LDKEvent_ty_from_ptr(ptr); + switch (raw_ty) { + case 0: return new Event_FundingGenerationReady(ptr); + case 1: return new Event_PaymentReceived(ptr); + case 2: return new Event_PaymentSent(ptr); + case 3: return new Event_PaymentPathFailed(ptr); + case 4: return new Event_PaymentFailed(ptr); + case 5: return new Event_PendingHTLCsForwardable(ptr); + case 6: return new Event_SpendableOutputs(ptr); + case 7: return new Event_PaymentForwarded(ptr); + case 8: return new Event_ChannelClosed(ptr); + case 9: return new Event_DiscardFunding(ptr); + case 10: return new Event_PaymentPathSuccessful(ptr); + default: + throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface } - if (raw_val instanceof bindings.LDKEvent_PaymentReceived) { - return new Event_PaymentReceived(ptr, raw_val); - } - if (raw_val instanceof bindings.LDKEvent_PaymentSent) { - return new Event_PaymentSent(ptr, raw_val); - } - if (raw_val instanceof bindings.LDKEvent_PaymentPathFailed) { - return new Event_PaymentPathFailed(ptr, raw_val); - } - if (raw_val instanceof bindings.LDKEvent_PaymentFailed) { - return new Event_PaymentFailed(ptr, raw_val); - } - if (raw_val instanceof bindings.LDKEvent_PendingHTLCsForwardable) { - return new Event_PendingHTLCsForwardable(ptr, raw_val); - } - if (raw_val instanceof bindings.LDKEvent_SpendableOutputs) { - return new Event_SpendableOutputs(ptr, raw_val); - } - if (raw_val instanceof bindings.LDKEvent_PaymentForwarded) { - return new Event_PaymentForwarded(ptr, raw_val); - } - if (raw_val instanceof bindings.LDKEvent_ChannelClosed) { - return new Event_ChannelClosed(ptr, raw_val); - } - if (raw_val instanceof bindings.LDKEvent_DiscardFunding) { - return new Event_DiscardFunding(ptr, raw_val); - } - if (raw_val instanceof bindings.LDKEvent_PaymentPathSuccessful) { - return new Event_PaymentPathSuccessful(ptr, raw_val); - } - throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface } public clone_ptr(): number { @@ -327,6 +314,9 @@ export class Event extends CommonBase { return ret; } + /** + * Creates a copy of the Event + */ public clone(): Event { const ret: number = bindings.Event_clone(this.ptr); const ret_hu_conv: Event = Event.constr_from_ptr(ret); @@ -334,55 +324,79 @@ export class Event extends CommonBase { return ret_hu_conv; } - public static constructor_funding_generation_ready(temporary_channel_id: Uint8Array, channel_value_satoshis: number, output_script: Uint8Array, user_channel_id: number): Event { - const ret: number = bindings.Event_funding_generation_ready(InternalUtils.check_arr_len(temporary_channel_id, 32), channel_value_satoshis, output_script, user_channel_id); + /** + * Utility method to constructs a new FundingGenerationReady-variant Event + */ + public static constructor_funding_generation_ready(temporary_channel_id: Uint8Array, channel_value_satoshis: bigint, output_script: Uint8Array, user_channel_id: bigint): Event { + const ret: number = bindings.Event_funding_generation_ready(bindings.encodeUint8Array(bindings.check_arr_len(temporary_channel_id, 32)), channel_value_satoshis, bindings.encodeUint8Array(output_script), user_channel_id); const ret_hu_conv: Event = Event.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } - public static constructor_payment_received(payment_hash: Uint8Array, amt: number, purpose: PaymentPurpose): Event { - const ret: number = bindings.Event_payment_received(InternalUtils.check_arr_len(payment_hash, 32), amt, CommonBase.get_ptr_of(purpose)); + /** + * Utility method to constructs a new PaymentReceived-variant Event + */ + public static constructor_payment_received(payment_hash: Uint8Array, amt: bigint, purpose: PaymentPurpose): Event { + const ret: number = bindings.Event_payment_received(bindings.encodeUint8Array(bindings.check_arr_len(payment_hash, 32)), amt, CommonBase.get_ptr_of(purpose)); const ret_hu_conv: Event = Event.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } + /** + * Utility method to constructs a new PaymentSent-variant Event + */ public static constructor_payment_sent(payment_id: Uint8Array, payment_preimage: Uint8Array, payment_hash: Uint8Array, fee_paid_msat: Option_u64Z): Event { - const ret: number = bindings.Event_payment_sent(InternalUtils.check_arr_len(payment_id, 32), InternalUtils.check_arr_len(payment_preimage, 32), InternalUtils.check_arr_len(payment_hash, 32), CommonBase.get_ptr_of(fee_paid_msat)); + const ret: number = bindings.Event_payment_sent(bindings.encodeUint8Array(bindings.check_arr_len(payment_id, 32)), bindings.encodeUint8Array(bindings.check_arr_len(payment_preimage, 32)), bindings.encodeUint8Array(bindings.check_arr_len(payment_hash, 32)), CommonBase.get_ptr_of(fee_paid_msat)); const ret_hu_conv: Event = Event.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } + /** + * Utility method to constructs a new PaymentPathFailed-variant Event + */ public static constructor_payment_path_failed(payment_id: Uint8Array, payment_hash: Uint8Array, rejected_by_dest: boolean, network_update: Option_NetworkUpdateZ, all_paths_failed: boolean, path: RouteHop[], short_channel_id: Option_u64Z, retry: RouteParameters): Event { - const ret: number = bindings.Event_payment_path_failed(InternalUtils.check_arr_len(payment_id, 32), InternalUtils.check_arr_len(payment_hash, 32), rejected_by_dest, CommonBase.get_ptr_of(network_update), all_paths_failed, path != null ? path.map(path_conv_10 => path_conv_10 == null ? 0 : CommonBase.get_ptr_of(path_conv_10) & ~1) : null, CommonBase.get_ptr_of(short_channel_id), retry == null ? 0 : CommonBase.get_ptr_of(retry) & ~1); + const ret: number = bindings.Event_payment_path_failed(bindings.encodeUint8Array(bindings.check_arr_len(payment_id, 32)), bindings.encodeUint8Array(bindings.check_arr_len(payment_hash, 32)), rejected_by_dest, CommonBase.get_ptr_of(network_update), all_paths_failed, bindings.encodeUint32Array(path != null ? path.map(path_conv_10 => path_conv_10 == null ? 0 : CommonBase.get_ptr_of(path_conv_10) & ~1) : null), CommonBase.get_ptr_of(short_channel_id), retry == null ? 0 : CommonBase.get_ptr_of(retry) & ~1); const ret_hu_conv: Event = Event.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } + /** + * Utility method to constructs a new PaymentFailed-variant Event + */ public static constructor_payment_failed(payment_id: Uint8Array, payment_hash: Uint8Array): Event { - const ret: number = bindings.Event_payment_failed(InternalUtils.check_arr_len(payment_id, 32), InternalUtils.check_arr_len(payment_hash, 32)); + const ret: number = bindings.Event_payment_failed(bindings.encodeUint8Array(bindings.check_arr_len(payment_id, 32)), bindings.encodeUint8Array(bindings.check_arr_len(payment_hash, 32))); const ret_hu_conv: Event = Event.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } - public static constructor_pending_htlcs_forwardable(time_forwardable: number): Event { + /** + * Utility method to constructs a new PendingHTLCsForwardable-variant Event + */ + public static constructor_pending_htlcs_forwardable(time_forwardable: bigint): Event { const ret: number = bindings.Event_pending_htlcs_forwardable(time_forwardable); const ret_hu_conv: Event = Event.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } + /** + * Utility method to constructs a new SpendableOutputs-variant Event + */ public static constructor_spendable_outputs(outputs: SpendableOutputDescriptor[]): Event { - const ret: number = bindings.Event_spendable_outputs(outputs != null ? outputs.map(outputs_conv_27 => CommonBase.get_ptr_of(outputs_conv_27)) : null); + const ret: number = bindings.Event_spendable_outputs(bindings.encodeUint32Array(outputs != null ? outputs.map(outputs_conv_27 => CommonBase.get_ptr_of(outputs_conv_27)) : null)); const ret_hu_conv: Event = Event.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } + /** + * Utility method to constructs a new PaymentForwarded-variant Event + */ public static constructor_payment_forwarded(fee_earned_msat: Option_u64Z, claim_from_onchain_tx: boolean): Event { const ret: number = bindings.Event_payment_forwarded(CommonBase.get_ptr_of(fee_earned_msat), claim_from_onchain_tx); const ret_hu_conv: Event = Event.constr_from_ptr(ret); @@ -390,207 +404,472 @@ export class Event extends CommonBase { return ret_hu_conv; } - public static constructor_channel_closed(channel_id: Uint8Array, user_channel_id: number, reason: ClosureReason): Event { - const ret: number = bindings.Event_channel_closed(InternalUtils.check_arr_len(channel_id, 32), user_channel_id, CommonBase.get_ptr_of(reason)); + /** + * Utility method to constructs a new ChannelClosed-variant Event + */ + public static constructor_channel_closed(channel_id: Uint8Array, user_channel_id: bigint, reason: ClosureReason): Event { + const ret: number = bindings.Event_channel_closed(bindings.encodeUint8Array(bindings.check_arr_len(channel_id, 32)), user_channel_id, CommonBase.get_ptr_of(reason)); const ret_hu_conv: Event = Event.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } + /** + * Utility method to constructs a new DiscardFunding-variant Event + */ public static constructor_discard_funding(channel_id: Uint8Array, transaction: Uint8Array): Event { - const ret: number = bindings.Event_discard_funding(InternalUtils.check_arr_len(channel_id, 32), transaction); + const ret: number = bindings.Event_discard_funding(bindings.encodeUint8Array(bindings.check_arr_len(channel_id, 32)), bindings.encodeUint8Array(transaction)); const ret_hu_conv: Event = Event.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } + /** + * Utility method to constructs a new PaymentPathSuccessful-variant Event + */ public static constructor_payment_path_successful(payment_id: Uint8Array, payment_hash: Uint8Array, path: RouteHop[]): Event { - const ret: number = bindings.Event_payment_path_successful(InternalUtils.check_arr_len(payment_id, 32), InternalUtils.check_arr_len(payment_hash, 32), path != null ? path.map(path_conv_10 => path_conv_10 == null ? 0 : CommonBase.get_ptr_of(path_conv_10) & ~1) : null); + const ret: number = bindings.Event_payment_path_successful(bindings.encodeUint8Array(bindings.check_arr_len(payment_id, 32)), bindings.encodeUint8Array(bindings.check_arr_len(payment_hash, 32)), bindings.encodeUint32Array(path != null ? path.map(path_conv_10 => path_conv_10 == null ? 0 : CommonBase.get_ptr_of(path_conv_10) & ~1) : null)); const ret_hu_conv: Event = Event.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } + /** + * Serialize the Event object into a byte array which can be read by Event_read + */ public write(): Uint8Array { - const ret: Uint8Array = bindings.Event_write(this.ptr); - return ret; + const ret: number = bindings.Event_write(this.ptr); + const ret_conv: Uint8Array = bindings.decodeUint8Array(ret); + return ret_conv; } } +/** A Event of type FundingGenerationReady */ export class Event_FundingGenerationReady extends Event { + /** + * The random channel_id we picked which you'll need to pass into + * ChannelManager::funding_transaction_generated. + */ public temporary_channel_id: Uint8Array; - public channel_value_satoshis: number; + /** + * The value, in satoshis, that the output should have. + */ + public channel_value_satoshis: bigint; + /** + * The script which should be used in the transaction output. + */ public output_script: Uint8Array; - public user_channel_id: number; + /** + * The `user_channel_id` value passed in to [`ChannelManager::create_channel`], or 0 for + * an inbound channel. + * + * [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel + */ + public user_channel_id: bigint; /* @internal */ - public constructor(ptr: number, obj: bindings.LDKEvent_FundingGenerationReady) { + public constructor(ptr: number) { super(null, ptr); - this.temporary_channel_id = obj.temporary_channel_id; - this.channel_value_satoshis = obj.channel_value_satoshis; - this.output_script = obj.output_script; - this.user_channel_id = obj.user_channel_id; + const temporary_channel_id: number = bindings.LDKEvent_FundingGenerationReady_get_temporary_channel_id(ptr); + const temporary_channel_id_conv: Uint8Array = bindings.decodeUint8Array(temporary_channel_id); + this.temporary_channel_id = temporary_channel_id_conv; + this.channel_value_satoshis = bindings.LDKEvent_FundingGenerationReady_get_channel_value_satoshis(ptr); + const output_script: number = bindings.LDKEvent_FundingGenerationReady_get_output_script(ptr); + const output_script_conv: Uint8Array = bindings.decodeUint8Array(output_script); + this.output_script = output_script_conv; + this.user_channel_id = bindings.LDKEvent_FundingGenerationReady_get_user_channel_id(ptr); } } +/** A Event of type PaymentReceived */ export class Event_PaymentReceived extends Event { + /** + * The hash for which the preimage should be handed to the ChannelManager. Note that LDK will + * not stop you from registering duplicate payment hashes for inbound payments. + */ public payment_hash: Uint8Array; - public amt: number; + /** + * The value, in thousandths of a satoshi, that this payment is for. + */ + public amt: bigint; + /** + * Information for claiming this received payment, based on whether the purpose of the + * payment is to pay an invoice or to send a spontaneous payment. + */ public purpose: PaymentPurpose; /* @internal */ - public constructor(ptr: number, obj: bindings.LDKEvent_PaymentReceived) { + public constructor(ptr: number) { super(null, ptr); - this.payment_hash = obj.payment_hash; - this.amt = obj.amt; - const purpose: number = obj.purpose; + const payment_hash: number = bindings.LDKEvent_PaymentReceived_get_payment_hash(ptr); + const payment_hash_conv: Uint8Array = bindings.decodeUint8Array(payment_hash); + this.payment_hash = payment_hash_conv; + this.amt = bindings.LDKEvent_PaymentReceived_get_amt(ptr); + const purpose: number = bindings.LDKEvent_PaymentReceived_get_purpose(ptr); const purpose_hu_conv: PaymentPurpose = PaymentPurpose.constr_from_ptr(purpose); CommonBase.add_ref_from(purpose_hu_conv, this); this.purpose = purpose_hu_conv; } } +/** A Event of type PaymentSent */ export class Event_PaymentSent extends Event { + /** + * The id returned by [`ChannelManager::send_payment`] and used with + * [`ChannelManager::retry_payment`]. + * + * [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment + * [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment + * + * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None + */ public payment_id: Uint8Array; + /** + * The preimage to the hash given to ChannelManager::send_payment. + * Note that this serves as a payment receipt, if you wish to have such a thing, you must + * store it somehow! + */ public payment_preimage: Uint8Array; + /** + * The hash that was given to [`ChannelManager::send_payment`]. + * + * [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment + */ public payment_hash: Uint8Array; + /** + * The total fee which was spent at intermediate hops in this payment, across all paths. + * + * Note that, like [`Route::get_total_fees`] this does *not* include any potential + * overpayment to the recipient node. + * + * If the recipient or an intermediate node misbehaves and gives us free money, this may + * overstate the amount paid, though this is unlikely. + * + * [`Route::get_total_fees`]: crate::routing::router::Route::get_total_fees + */ public fee_paid_msat: Option_u64Z; /* @internal */ - public constructor(ptr: number, obj: bindings.LDKEvent_PaymentSent) { + public constructor(ptr: number) { super(null, ptr); - this.payment_id = obj.payment_id; - this.payment_preimage = obj.payment_preimage; - this.payment_hash = obj.payment_hash; - const fee_paid_msat: number = obj.fee_paid_msat; + const payment_id: number = bindings.LDKEvent_PaymentSent_get_payment_id(ptr); + const payment_id_conv: Uint8Array = bindings.decodeUint8Array(payment_id); + this.payment_id = payment_id_conv; + const payment_preimage: number = bindings.LDKEvent_PaymentSent_get_payment_preimage(ptr); + const payment_preimage_conv: Uint8Array = bindings.decodeUint8Array(payment_preimage); + this.payment_preimage = payment_preimage_conv; + const payment_hash: number = bindings.LDKEvent_PaymentSent_get_payment_hash(ptr); + const payment_hash_conv: Uint8Array = bindings.decodeUint8Array(payment_hash); + this.payment_hash = payment_hash_conv; + const fee_paid_msat: number = bindings.LDKEvent_PaymentSent_get_fee_paid_msat(ptr); const fee_paid_msat_hu_conv: Option_u64Z = Option_u64Z.constr_from_ptr(fee_paid_msat); CommonBase.add_ref_from(fee_paid_msat_hu_conv, this); this.fee_paid_msat = fee_paid_msat_hu_conv; } } +/** A Event of type PaymentPathFailed */ export class Event_PaymentPathFailed extends Event { + /** + * The id returned by [`ChannelManager::send_payment`] and used with + * [`ChannelManager::retry_payment`] and [`ChannelManager::abandon_payment`]. + * + * [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment + * [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment + * [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment + * + * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None + */ public payment_id: Uint8Array; + /** + * The hash that was given to [`ChannelManager::send_payment`]. + * + * [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment + */ public payment_hash: Uint8Array; + /** + * Indicates the payment was rejected for some reason by the recipient. This implies that + * the payment has failed, not just the route in question. If this is not set, you may + * retry the payment via a different route. + */ public rejected_by_dest: boolean; + /** + * Any failure information conveyed via the Onion return packet by a node along the failed + * payment route. + * + * Should be applied to the [`NetworkGraph`] so that routing decisions can take into + * account the update. [`NetGraphMsgHandler`] is capable of doing this. + * + * [`NetworkGraph`]: crate::routing::network_graph::NetworkGraph + * [`NetGraphMsgHandler`]: crate::routing::network_graph::NetGraphMsgHandler + */ public network_update: Option_NetworkUpdateZ; + /** + * For both single-path and multi-path payments, this is set if all paths of the payment have + * failed. This will be set to false if (1) this is an MPP payment and (2) other parts of the + * larger MPP payment were still in flight when this event was generated. + * + * Note that if you are retrying individual MPP parts, using this value to determine if a + * payment has fully failed is race-y. Because multiple failures can happen prior to events + * being processed, you may retry in response to a first failure, with a second failure + * (with `all_paths_failed` set) still pending. Then, when the second failure is processed + * you will see `all_paths_failed` set even though the retry of the first failure still + * has an associated in-flight HTLC. See (1) for an example of such a failure. + * + * If you wish to retry individual MPP parts and learn when a payment has failed, you must + * call [`ChannelManager::abandon_payment`] and wait for a [`Event::PaymentFailed`] event. + * + * (1) + * + * [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment + */ public all_paths_failed: boolean; + /** + * The payment path that failed. + */ public path: RouteHop[]; + /** + * The channel responsible for the failed payment path. + * + * If this is `Some`, then the corresponding channel should be avoided when the payment is + * retried. May be `None` for older [`Event`] serializations. + */ public short_channel_id: Option_u64Z; + /** + * Parameters needed to compute a new [`Route`] when retrying the failed payment path. + * + * See [`find_route`] for details. + * + * [`Route`]: crate::routing::router::Route + * [`find_route`]: crate::routing::router::find_route + * + * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None + */ public retry: RouteParameters; /* @internal */ - public constructor(ptr: number, obj: bindings.LDKEvent_PaymentPathFailed) { + public constructor(ptr: number) { super(null, ptr); - this.payment_id = obj.payment_id; - this.payment_hash = obj.payment_hash; - this.rejected_by_dest = obj.rejected_by_dest; - const network_update: number = obj.network_update; + const payment_id: number = bindings.LDKEvent_PaymentPathFailed_get_payment_id(ptr); + const payment_id_conv: Uint8Array = bindings.decodeUint8Array(payment_id); + this.payment_id = payment_id_conv; + const payment_hash: number = bindings.LDKEvent_PaymentPathFailed_get_payment_hash(ptr); + const payment_hash_conv: Uint8Array = bindings.decodeUint8Array(payment_hash); + this.payment_hash = payment_hash_conv; + this.rejected_by_dest = bindings.LDKEvent_PaymentPathFailed_get_rejected_by_dest(ptr); + const network_update: number = bindings.LDKEvent_PaymentPathFailed_get_network_update(ptr); const network_update_hu_conv: Option_NetworkUpdateZ = Option_NetworkUpdateZ.constr_from_ptr(network_update); CommonBase.add_ref_from(network_update_hu_conv, this); this.network_update = network_update_hu_conv; - this.all_paths_failed = obj.all_paths_failed; - const path: number[] = obj.path; - const path_conv_10_arr: RouteHop[] = new Array(path.length).fill(null); - for (var k = 0; k < path.length; k++) { - const path_conv_10: number = path[k]; + this.all_paths_failed = bindings.LDKEvent_PaymentPathFailed_get_all_paths_failed(ptr); + const path: number = bindings.LDKEvent_PaymentPathFailed_get_path(ptr); + const path_conv_10_len: number = bindings.getArrayLength(path); + const path_conv_10_arr: RouteHop[] = new Array(path_conv_10_len).fill(null); + for (var k = 0; k < path_conv_10_len; k++) { + const path_conv_10: number = bindings.getU32ArrayElem(path, k); const path_conv_10_hu_conv: RouteHop = new RouteHop(null, path_conv_10); CommonBase.add_ref_from(path_conv_10_hu_conv, this); path_conv_10_arr[k] = path_conv_10_hu_conv; } + bindings.freeWasmMemory(path) this.path = path_conv_10_arr; - const short_channel_id: number = obj.short_channel_id; + const short_channel_id: number = bindings.LDKEvent_PaymentPathFailed_get_short_channel_id(ptr); const short_channel_id_hu_conv: Option_u64Z = Option_u64Z.constr_from_ptr(short_channel_id); CommonBase.add_ref_from(short_channel_id_hu_conv, this); this.short_channel_id = short_channel_id_hu_conv; - const retry: number = obj.retry; + const retry: number = bindings.LDKEvent_PaymentPathFailed_get_retry(ptr); const retry_hu_conv: RouteParameters = new RouteParameters(null, retry); CommonBase.add_ref_from(retry_hu_conv, this); this.retry = retry_hu_conv; } } +/** A Event of type PaymentFailed */ export class Event_PaymentFailed extends Event { + /** + * The id returned by [`ChannelManager::send_payment`] and used with + * [`ChannelManager::retry_payment`] and [`ChannelManager::abandon_payment`]. + * + * [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment + * [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment + * [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment + */ public payment_id: Uint8Array; + /** + * The hash that was given to [`ChannelManager::send_payment`]. + * + * [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment + */ public payment_hash: Uint8Array; /* @internal */ - public constructor(ptr: number, obj: bindings.LDKEvent_PaymentFailed) { + public constructor(ptr: number) { super(null, ptr); - this.payment_id = obj.payment_id; - this.payment_hash = obj.payment_hash; + const payment_id: number = bindings.LDKEvent_PaymentFailed_get_payment_id(ptr); + const payment_id_conv: Uint8Array = bindings.decodeUint8Array(payment_id); + this.payment_id = payment_id_conv; + const payment_hash: number = bindings.LDKEvent_PaymentFailed_get_payment_hash(ptr); + const payment_hash_conv: Uint8Array = bindings.decodeUint8Array(payment_hash); + this.payment_hash = payment_hash_conv; } } +/** A Event of type PendingHTLCsForwardable */ export class Event_PendingHTLCsForwardable extends Event { - public time_forwardable: number; + /** + * The minimum amount of time that should be waited prior to calling + * process_pending_htlc_forwards. To increase the effort required to correlate payments, + * you should wait a random amount of time in roughly the range (now + time_forwardable, + * now + 5*time_forwardable). + */ + public time_forwardable: bigint; /* @internal */ - public constructor(ptr: number, obj: bindings.LDKEvent_PendingHTLCsForwardable) { + public constructor(ptr: number) { super(null, ptr); - this.time_forwardable = obj.time_forwardable; + this.time_forwardable = bindings.LDKEvent_PendingHTLCsForwardable_get_time_forwardable(ptr); } } +/** A Event of type SpendableOutputs */ export class Event_SpendableOutputs extends Event { + /** + * The outputs which you should store as spendable by you. + */ public outputs: SpendableOutputDescriptor[]; /* @internal */ - public constructor(ptr: number, obj: bindings.LDKEvent_SpendableOutputs) { + public constructor(ptr: number) { super(null, ptr); - const outputs: number[] = obj.outputs; - const outputs_conv_27_arr: SpendableOutputDescriptor[] = new Array(outputs.length).fill(null); - for (var b = 0; b < outputs.length; b++) { - const outputs_conv_27: number = outputs[b]; + const outputs: number = bindings.LDKEvent_SpendableOutputs_get_outputs(ptr); + const outputs_conv_27_len: number = bindings.getArrayLength(outputs); + const outputs_conv_27_arr: SpendableOutputDescriptor[] = new Array(outputs_conv_27_len).fill(null); + for (var b = 0; b < outputs_conv_27_len; b++) { + const outputs_conv_27: number = bindings.getU32ArrayElem(outputs, b); const outputs_conv_27_hu_conv: SpendableOutputDescriptor = SpendableOutputDescriptor.constr_from_ptr(outputs_conv_27); CommonBase.add_ref_from(outputs_conv_27_hu_conv, this); outputs_conv_27_arr[b] = outputs_conv_27_hu_conv; } + bindings.freeWasmMemory(outputs) this.outputs = outputs_conv_27_arr; } } +/** A Event of type PaymentForwarded */ export class Event_PaymentForwarded extends Event { + /** + * The fee, in milli-satoshis, which was earned as a result of the payment. + * + * Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC + * was pending, the amount the next hop claimed will have been rounded down to the nearest + * whole satoshi. Thus, the fee calculated here may be higher than expected as we still + * claimed the full value in millisatoshis from the source. In this case, + * `claim_from_onchain_tx` will be set. + * + * If the channel which sent us the payment has been force-closed, we will claim the funds + * via an on-chain transaction. In that case we do not yet know the on-chain transaction + * fees which we will spend and will instead set this to `None`. It is possible duplicate + * `PaymentForwarded` events are generated for the same payment iff `fee_earned_msat` is + * `None`. + */ public fee_earned_msat: Option_u64Z; + /** + * If this is `true`, the forwarded HTLC was claimed by our counterparty via an on-chain + * transaction. + */ public claim_from_onchain_tx: boolean; /* @internal */ - public constructor(ptr: number, obj: bindings.LDKEvent_PaymentForwarded) { + public constructor(ptr: number) { super(null, ptr); - const fee_earned_msat: number = obj.fee_earned_msat; + const fee_earned_msat: number = bindings.LDKEvent_PaymentForwarded_get_fee_earned_msat(ptr); const fee_earned_msat_hu_conv: Option_u64Z = Option_u64Z.constr_from_ptr(fee_earned_msat); CommonBase.add_ref_from(fee_earned_msat_hu_conv, this); this.fee_earned_msat = fee_earned_msat_hu_conv; - this.claim_from_onchain_tx = obj.claim_from_onchain_tx; + this.claim_from_onchain_tx = bindings.LDKEvent_PaymentForwarded_get_claim_from_onchain_tx(ptr); } } +/** A Event of type ChannelClosed */ export class Event_ChannelClosed extends Event { + /** + * The channel_id of the channel which has been closed. Note that on-chain transactions + * resolving the channel are likely still awaiting confirmation. + */ public channel_id: Uint8Array; - public user_channel_id: number; + /** + * The `user_channel_id` value passed in to [`ChannelManager::create_channel`], or 0 for + * an inbound channel. This will always be zero for objects serialized with LDK versions + * prior to 0.0.102. + * + * [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel + */ + public user_channel_id: bigint; + /** + * The reason the channel was closed. + */ public reason: ClosureReason; /* @internal */ - public constructor(ptr: number, obj: bindings.LDKEvent_ChannelClosed) { + public constructor(ptr: number) { super(null, ptr); - this.channel_id = obj.channel_id; - this.user_channel_id = obj.user_channel_id; - const reason: number = obj.reason; + const channel_id: number = bindings.LDKEvent_ChannelClosed_get_channel_id(ptr); + const channel_id_conv: Uint8Array = bindings.decodeUint8Array(channel_id); + this.channel_id = channel_id_conv; + this.user_channel_id = bindings.LDKEvent_ChannelClosed_get_user_channel_id(ptr); + const reason: number = bindings.LDKEvent_ChannelClosed_get_reason(ptr); const reason_hu_conv: ClosureReason = ClosureReason.constr_from_ptr(reason); CommonBase.add_ref_from(reason_hu_conv, this); this.reason = reason_hu_conv; } } +/** A Event of type DiscardFunding */ export class Event_DiscardFunding extends Event { + /** + * The channel_id of the channel which has been closed. + */ public channel_id: Uint8Array; + /** + * The full transaction received from the user + */ public transaction: Uint8Array; /* @internal */ - public constructor(ptr: number, obj: bindings.LDKEvent_DiscardFunding) { + public constructor(ptr: number) { super(null, ptr); - this.channel_id = obj.channel_id; - this.transaction = obj.transaction; + const channel_id: number = bindings.LDKEvent_DiscardFunding_get_channel_id(ptr); + const channel_id_conv: Uint8Array = bindings.decodeUint8Array(channel_id); + this.channel_id = channel_id_conv; + const transaction: number = bindings.LDKEvent_DiscardFunding_get_transaction(ptr); + const transaction_conv: Uint8Array = bindings.decodeUint8Array(transaction); + this.transaction = transaction_conv; } } +/** A Event of type PaymentPathSuccessful */ export class Event_PaymentPathSuccessful extends Event { + /** + * The id returned by [`ChannelManager::send_payment`] and used with + * [`ChannelManager::retry_payment`]. + * + * [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment + * [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment + */ public payment_id: Uint8Array; + /** + * The hash that was given to [`ChannelManager::send_payment`]. + * + * [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment + * + * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None + */ public payment_hash: Uint8Array; + /** + * The payment path that was successful. + * + * May contain a closed channel if the HTLC sent along the path was fulfilled on chain. + */ public path: RouteHop[]; /* @internal */ - public constructor(ptr: number, obj: bindings.LDKEvent_PaymentPathSuccessful) { + public constructor(ptr: number) { super(null, ptr); - this.payment_id = obj.payment_id; - this.payment_hash = obj.payment_hash; - const path: number[] = obj.path; - const path_conv_10_arr: RouteHop[] = new Array(path.length).fill(null); - for (var k = 0; k < path.length; k++) { - const path_conv_10: number = path[k]; + const payment_id: number = bindings.LDKEvent_PaymentPathSuccessful_get_payment_id(ptr); + const payment_id_conv: Uint8Array = bindings.decodeUint8Array(payment_id); + this.payment_id = payment_id_conv; + const payment_hash: number = bindings.LDKEvent_PaymentPathSuccessful_get_payment_hash(ptr); + const payment_hash_conv: Uint8Array = bindings.decodeUint8Array(payment_hash); + this.payment_hash = payment_hash_conv; + const path: number = bindings.LDKEvent_PaymentPathSuccessful_get_path(ptr); + const path_conv_10_len: number = bindings.getArrayLength(path); + const path_conv_10_arr: RouteHop[] = new Array(path_conv_10_len).fill(null); + for (var k = 0; k < path_conv_10_len; k++) { + const path_conv_10: number = bindings.getU32ArrayElem(path, k); const path_conv_10_hu_conv: RouteHop = new RouteHop(null, path_conv_10); CommonBase.add_ref_from(path_conv_10_hu_conv, this); path_conv_10_arr[k] = path_conv_10_hu_conv; } + bindings.freeWasmMemory(path) this.path = path_conv_10_arr; } }