2 import CommonBase from './CommonBase';
3 import * as bindings from '../bindings' // TODO: figure out location
5 export default class MonitorEvent extends CommonBase {
6 protected constructor(_dummy: object, ptr: number) { super(ptr); }
9 if (this.ptr != 0) { bindings.MonitorEvent_free(this.ptr); }
11 static constr_from_ptr(ptr: number): MonitorEvent {
12 const raw_val: bindings.LDKMonitorEvent = bindings.LDKMonitorEvent_ref_from_ptr(ptr);
13 if (raw_val instanceof bindings.LDKMonitorEvent.HTLCEvent) {
14 return new HTLCEvent(this.ptr, raw_val);
16 if (raw_val instanceof bindings.LDKMonitorEvent.CommitmentTxConfirmed) {
17 return new CommitmentTxConfirmed(this.ptr, raw_val);
19 throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
23 export class HTLCEvent extends MonitorEvent {
24 public htlc_event: HTLCUpdate;
25 private constructor(ptr: number, obj: bindings.LDKMonitorEvent.HTLCEvent) {
27 const htlc_event: number = obj.htlc_event;
28 const htlc_event_hu_conv: HTLCUpdate = new HTLCUpdate(null, htlc_event);
29 htlc_event_hu_conv.ptrs_to.add(this);
30 this.htlc_event = htlc_event_hu_conv;
33 export class CommitmentTxConfirmed extends MonitorEvent {
34 public commitment_tx_confirmed: OutPoint;
35 private constructor(ptr: number, obj: bindings.LDKMonitorEvent.CommitmentTxConfirmed) {
37 const commitment_tx_confirmed: number = obj.commitment_tx_confirmed;
38 const commitment_tx_confirmed_hu_conv: OutPoint = new OutPoint(null, commitment_tx_confirmed);
39 commitment_tx_confirmed_hu_conv.ptrs_to.add(this);
40 this.commitment_tx_confirmed = commitment_tx_confirmed_hu_conv;
43 public MonitorEvent clone() {
44 number ret = bindings.MonitorEvent_clone(this.ptr);
45 MonitorEvent ret_hu_conv = MonitorEvent.constr_from_ptr(ret);
46 ret_hu_conv.ptrs_to.add(this);
50 public static MonitorEvent constructor_htlcevent(HTLCUpdate a) {
51 number ret = bindings.MonitorEvent_htlcevent(a == null ? 0 : a.ptr & ~1);
52 MonitorEvent ret_hu_conv = MonitorEvent.constr_from_ptr(ret);
53 ret_hu_conv.ptrs_to.add(ret_hu_conv);
54 ret_hu_conv.ptrs_to.add(a);
58 public static MonitorEvent constructor_commitment_tx_confirmed(OutPoint a) {
59 number ret = bindings.MonitorEvent_commitment_tx_confirmed(a == null ? 0 : a.ptr & ~1);
60 MonitorEvent ret_hu_conv = MonitorEvent.constr_from_ptr(ret);
61 ret_hu_conv.ptrs_to.add(ret_hu_conv);
62 ret_hu_conv.ptrs_to.add(a);