2 import CommonBase from './CommonBase';
3 import * as bindings from '../bindings' // TODO: figure out location
5 export default class Event extends CommonBase {
6 protected constructor(_dummy: object, ptr: number) { super(ptr); }
9 if (this.ptr != 0) { bindings.Event_free(this.ptr); }
11 static constr_from_ptr(ptr: number): Event {
12 const raw_val: bindings.LDKEvent = bindings.LDKEvent_ref_from_ptr(ptr);
13 if (raw_val instanceof bindings.LDKEvent.FundingGenerationReady) {
14 return new FundingGenerationReady(this.ptr, raw_val);
16 if (raw_val instanceof bindings.LDKEvent.PaymentReceived) {
17 return new PaymentReceived(this.ptr, raw_val);
19 if (raw_val instanceof bindings.LDKEvent.PaymentSent) {
20 return new PaymentSent(this.ptr, raw_val);
22 if (raw_val instanceof bindings.LDKEvent.PaymentFailed) {
23 return new PaymentFailed(this.ptr, raw_val);
25 if (raw_val instanceof bindings.LDKEvent.PendingHTLCsForwardable) {
26 return new PendingHTLCsForwardable(this.ptr, raw_val);
28 if (raw_val instanceof bindings.LDKEvent.SpendableOutputs) {
29 return new SpendableOutputs(this.ptr, raw_val);
31 throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
35 export class FundingGenerationReady extends Event {
36 public temporary_channel_id: Uint8Array;
37 public channel_value_satoshis: number;
38 public output_script: Uint8Array;
39 public user_channel_id: number;
40 private constructor(ptr: number, obj: bindings.LDKEvent.FundingGenerationReady) {
42 this.temporary_channel_id = obj.temporary_channel_id;
43 this.channel_value_satoshis = obj.channel_value_satoshis;
44 this.output_script = obj.output_script;
45 this.user_channel_id = obj.user_channel_id;
48 export class PaymentReceived extends Event {
49 public payment_hash: Uint8Array;
50 public payment_preimage: Uint8Array;
51 public payment_secret: Uint8Array;
53 public user_payment_id: number;
54 private constructor(ptr: number, obj: bindings.LDKEvent.PaymentReceived) {
56 this.payment_hash = obj.payment_hash;
57 this.payment_preimage = obj.payment_preimage;
58 this.payment_secret = obj.payment_secret;
60 this.user_payment_id = obj.user_payment_id;
63 export class PaymentSent extends Event {
64 public payment_preimage: Uint8Array;
65 private constructor(ptr: number, obj: bindings.LDKEvent.PaymentSent) {
67 this.payment_preimage = obj.payment_preimage;
70 export class PaymentFailed extends Event {
71 public payment_hash: Uint8Array;
72 public rejected_by_dest: boolean;
73 private constructor(ptr: number, obj: bindings.LDKEvent.PaymentFailed) {
75 this.payment_hash = obj.payment_hash;
76 this.rejected_by_dest = obj.rejected_by_dest;
79 export class PendingHTLCsForwardable extends Event {
80 public time_forwardable: number;
81 private constructor(ptr: number, obj: bindings.LDKEvent.PendingHTLCsForwardable) {
83 this.time_forwardable = obj.time_forwardable;
86 export class SpendableOutputs extends Event {
87 public outputs: SpendableOutputDescriptor[];
88 private constructor(ptr: number, obj: bindings.LDKEvent.SpendableOutputs) {
90 const outputs: number[] = obj.outputs;
91 SpendableOutputDescriptor[] outputs_conv_27_arr = new SpendableOutputDescriptor[outputs.length];
92 for (int b = 0; b < outputs.length; b++) {
93 number outputs_conv_27 = outputs[b];
94 SpendableOutputDescriptor outputs_conv_27_hu_conv = SpendableOutputDescriptor.constr_from_ptr(outputs_conv_27);
95 outputs_conv_27_hu_conv.ptrs_to.add(this);
96 outputs_conv_27_arr[b] = outputs_conv_27_hu_conv;
98 this.outputs = outputs_conv_27_arr;
101 public Event clone() {
102 number ret = bindings.Event_clone(this.ptr);
103 Event ret_hu_conv = Event.constr_from_ptr(ret);
104 ret_hu_conv.ptrs_to.add(this);
108 public Uint8Array write() {
109 Uint8Array ret = bindings.Event_write(this.ptr);