]> git.bitcoin.ninja Git - ldk-java/blob - ts/structs/MonitorEvent.ts
Merge pull request #14 from TheBlueMatt/2021-03-fix-enums
[ldk-java] / ts / structs / MonitorEvent.ts
1
2 import CommonBase from './CommonBase';
3 import * as bindings from '../bindings' // TODO: figure out location
4
5 export default class MonitorEvent extends CommonBase {
6         protected constructor(_dummy: object, ptr: number) { super(ptr); }
7         protected finalize() {
8                 super.finalize();
9                 if (this.ptr != 0) { bindings.MonitorEvent_free(this.ptr); }
10         }
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);
15                 }
16                 if (raw_val instanceof bindings.LDKMonitorEvent.CommitmentTxBroadcasted) {
17                         return new CommitmentTxBroadcasted(this.ptr, raw_val);
18                 }
19                 throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
20         }
21
22 }
23 export class HTLCEvent extends MonitorEvent {
24         public htlc_event: HTLCUpdate;
25         private constructor(ptr: number, obj: bindings.LDKMonitorEvent.HTLCEvent) {
26                 super(null, ptr);
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;
31         }
32 }
33 export class CommitmentTxBroadcasted extends MonitorEvent {
34         public commitment_tx_broadcasted: OutPoint;
35         private constructor(ptr: number, obj: bindings.LDKMonitorEvent.CommitmentTxBroadcasted) {
36                 super(null, ptr);
37                 const commitment_tx_broadcasted: number = obj.commitment_tx_broadcasted;
38                 const commitment_tx_broadcasted_hu_conv: OutPoint = new OutPoint(null, commitment_tx_broadcasted);
39                         commitment_tx_broadcasted_hu_conv.ptrs_to.add(this);
40                 this.commitment_tx_broadcasted = commitment_tx_broadcasted_hu_conv;
41         }
42 }
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);
47                 return ret_hu_conv;
48         }
49
50 }