X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=sidebyside;f=ts%2Fstructs%2FMonitorEvent.mts;h=03ee0c53986b91a777336fe47906a2d889df9868;hb=c629a01650402c8e2f9b9db8ced9ed63ce687727;hp=2da07ee44e0c9e6d3ad4cbadbb17f148638274d4;hpb=bf08029c1ad5244b59902eada723b634dcade62d;p=ldk-java diff --git a/ts/structs/MonitorEvent.mts b/ts/structs/MonitorEvent.mts index 2da07ee4..03ee0c53 100644 --- a/ts/structs/MonitorEvent.mts +++ b/ts/structs/MonitorEvent.mts @@ -279,26 +279,23 @@ import { MultiThreadedLockableScore } from '../structs/MultiThreadedLockableScor import CommonBase from './CommonBase.mjs'; import * as bindings from '../bindings.mjs' -import * as InternalUtils from '../InternalUtils.mjs' +/** + * An event to be processed by the ChannelManager. + */ export class MonitorEvent extends CommonBase { protected constructor(_dummy: object, ptr: number) { super(ptr, bindings.MonitorEvent_free); } /* @internal */ public static constr_from_ptr(ptr: number): MonitorEvent { - const raw_val: bindings.LDKMonitorEvent = bindings.LDKMonitorEvent_ref_from_ptr(ptr); - if (raw_val instanceof bindings.LDKMonitorEvent_HTLCEvent) { - return new MonitorEvent_HTLCEvent(ptr, raw_val); + const raw_ty: number = bindings.LDKMonitorEvent_ty_from_ptr(ptr); + switch (raw_ty) { + case 0: return new MonitorEvent_HTLCEvent(ptr); + case 1: return new MonitorEvent_CommitmentTxConfirmed(ptr); + case 2: return new MonitorEvent_UpdateCompleted(ptr); + case 3: return new MonitorEvent_UpdateFailed(ptr); + default: + throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface } - if (raw_val instanceof bindings.LDKMonitorEvent_CommitmentTxConfirmed) { - return new MonitorEvent_CommitmentTxConfirmed(ptr, raw_val); - } - if (raw_val instanceof bindings.LDKMonitorEvent_UpdateCompleted) { - return new MonitorEvent_UpdateCompleted(ptr, raw_val); - } - if (raw_val instanceof bindings.LDKMonitorEvent_UpdateFailed) { - return new MonitorEvent_UpdateFailed(ptr, raw_val); - } - throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface } public clone_ptr(): number { @@ -306,6 +303,9 @@ export class MonitorEvent extends CommonBase { return ret; } + /** + * Creates a copy of the MonitorEvent + */ public clone(): MonitorEvent { const ret: number = bindings.MonitorEvent_clone(this.ptr); const ret_hu_conv: MonitorEvent = MonitorEvent.constr_from_ptr(ret); @@ -313,6 +313,9 @@ export class MonitorEvent extends CommonBase { return ret_hu_conv; } + /** + * Utility method to constructs a new HTLCEvent-variant MonitorEvent + */ public static constructor_htlcevent(a: HTLCUpdate): MonitorEvent { const ret: number = bindings.MonitorEvent_htlcevent(a == null ? 0 : CommonBase.get_ptr_of(a) & ~1); const ret_hu_conv: MonitorEvent = MonitorEvent.constr_from_ptr(ret); @@ -320,6 +323,9 @@ export class MonitorEvent extends CommonBase { return ret_hu_conv; } + /** + * Utility method to constructs a new CommitmentTxConfirmed-variant MonitorEvent + */ public static constructor_commitment_tx_confirmed(a: OutPoint): MonitorEvent { const ret: number = bindings.MonitorEvent_commitment_tx_confirmed(a == null ? 0 : CommonBase.get_ptr_of(a) & ~1); const ret_hu_conv: MonitorEvent = MonitorEvent.constr_from_ptr(ret); @@ -327,13 +333,19 @@ export class MonitorEvent extends CommonBase { return ret_hu_conv; } - public static constructor_update_completed(funding_txo: OutPoint, monitor_update_id: number): MonitorEvent { + /** + * Utility method to constructs a new UpdateCompleted-variant MonitorEvent + */ + public static constructor_update_completed(funding_txo: OutPoint, monitor_update_id: bigint): MonitorEvent { const ret: number = bindings.MonitorEvent_update_completed(funding_txo == null ? 0 : CommonBase.get_ptr_of(funding_txo) & ~1, monitor_update_id); const ret_hu_conv: MonitorEvent = MonitorEvent.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } + /** + * Utility method to constructs a new UpdateFailed-variant MonitorEvent + */ public static constructor_update_failed(a: OutPoint): MonitorEvent { const ret: number = bindings.MonitorEvent_update_failed(a == null ? 0 : CommonBase.get_ptr_of(a) & ~1); const ret_hu_conv: MonitorEvent = MonitorEvent.constr_from_ptr(ret); @@ -341,53 +353,71 @@ export class MonitorEvent extends CommonBase { return ret_hu_conv; } + /** + * Serialize the MonitorEvent object into a byte array which can be read by MonitorEvent_read + */ public write(): Uint8Array { - const ret: Uint8Array = bindings.MonitorEvent_write(this.ptr); - return ret; + const ret: number = bindings.MonitorEvent_write(this.ptr); + const ret_conv: Uint8Array = bindings.decodeUint8Array(ret); + return ret_conv; } } +/** A MonitorEvent of type HTLCEvent */ export class MonitorEvent_HTLCEvent extends MonitorEvent { public htlc_event: HTLCUpdate; /* @internal */ - public constructor(ptr: number, obj: bindings.LDKMonitorEvent_HTLCEvent) { + public constructor(ptr: number) { super(null, ptr); - const htlc_event: number = obj.htlc_event; + const htlc_event: number = bindings.LDKMonitorEvent_HTLCEvent_get_htlc_event(ptr); const htlc_event_hu_conv: HTLCUpdate = new HTLCUpdate(null, htlc_event); CommonBase.add_ref_from(htlc_event_hu_conv, this); this.htlc_event = htlc_event_hu_conv; } } +/** A MonitorEvent of type CommitmentTxConfirmed */ export class MonitorEvent_CommitmentTxConfirmed extends MonitorEvent { public commitment_tx_confirmed: OutPoint; /* @internal */ - public constructor(ptr: number, obj: bindings.LDKMonitorEvent_CommitmentTxConfirmed) { + public constructor(ptr: number) { super(null, ptr); - const commitment_tx_confirmed: number = obj.commitment_tx_confirmed; + const commitment_tx_confirmed: number = bindings.LDKMonitorEvent_CommitmentTxConfirmed_get_commitment_tx_confirmed(ptr); const commitment_tx_confirmed_hu_conv: OutPoint = new OutPoint(null, commitment_tx_confirmed); CommonBase.add_ref_from(commitment_tx_confirmed_hu_conv, this); this.commitment_tx_confirmed = commitment_tx_confirmed_hu_conv; } } +/** A MonitorEvent of type UpdateCompleted */ export class MonitorEvent_UpdateCompleted extends MonitorEvent { + /** + * The funding outpoint of the [`ChannelMonitor`] that was updated + */ public funding_txo: OutPoint; - public monitor_update_id: number; + /** + * The Update ID from [`ChannelMonitorUpdate::update_id`] which was applied or + * [`ChannelMonitor::get_latest_update_id`]. + * + * Note that this should only be set to a given update's ID if all previous updates for the + * same [`ChannelMonitor`] have been applied and persisted. + */ + public monitor_update_id: bigint; /* @internal */ - public constructor(ptr: number, obj: bindings.LDKMonitorEvent_UpdateCompleted) { + public constructor(ptr: number) { super(null, ptr); - const funding_txo: number = obj.funding_txo; + const funding_txo: number = bindings.LDKMonitorEvent_UpdateCompleted_get_funding_txo(ptr); const funding_txo_hu_conv: OutPoint = new OutPoint(null, funding_txo); CommonBase.add_ref_from(funding_txo_hu_conv, this); this.funding_txo = funding_txo_hu_conv; - this.monitor_update_id = obj.monitor_update_id; + this.monitor_update_id = bindings.LDKMonitorEvent_UpdateCompleted_get_monitor_update_id(ptr); } } +/** A MonitorEvent of type UpdateFailed */ export class MonitorEvent_UpdateFailed extends MonitorEvent { public update_failed: OutPoint; /* @internal */ - public constructor(ptr: number, obj: bindings.LDKMonitorEvent_UpdateFailed) { + public constructor(ptr: number) { super(null, ptr); - const update_failed: number = obj.update_failed; + const update_failed: number = bindings.LDKMonitorEvent_UpdateFailed_get_update_failed(ptr); const update_failed_hu_conv: OutPoint = new OutPoint(null, update_failed); CommonBase.add_ref_from(update_failed_hu_conv, this); this.update_failed = update_failed_hu_conv;