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.FundingBroadcastSafe) {
17 return new FundingBroadcastSafe(this.ptr, raw_val);
19 if (raw_val instanceof bindings.LDKEvent.PaymentReceived) {
20 return new PaymentReceived(this.ptr, raw_val);
22 if (raw_val instanceof bindings.LDKEvent.PaymentSent) {
23 return new PaymentSent(this.ptr, raw_val);
25 if (raw_val instanceof bindings.LDKEvent.PaymentFailed) {
26 return new PaymentFailed(this.ptr, raw_val);
28 if (raw_val instanceof bindings.LDKEvent.PendingHTLCsForwardable) {
29 return new PendingHTLCsForwardable(this.ptr, raw_val);
31 if (raw_val instanceof bindings.LDKEvent.SpendableOutputs) {
32 return new SpendableOutputs(this.ptr, raw_val);
34 throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
38 export class FundingGenerationReady extends Event {
39 public temporary_channel_id: Uint8Array;
40 public channel_value_satoshis: number;
41 public output_script: Uint8Array;
42 public user_channel_id: number;
43 private constructor(ptr: number, obj: bindings.LDKEvent.FundingGenerationReady) {
45 this.temporary_channel_id = obj.temporary_channel_id;
46 this.channel_value_satoshis = obj.channel_value_satoshis;
47 this.output_script = obj.output_script;
48 this.user_channel_id = obj.user_channel_id;
51 export class FundingBroadcastSafe extends Event {
52 public funding_txo: OutPoint;
53 public user_channel_id: number;
54 private constructor(ptr: number, obj: bindings.LDKEvent.FundingBroadcastSafe) {
56 const funding_txo: number = obj.funding_txo;
57 const funding_txo_hu_conv: OutPoint = new OutPoint(null, funding_txo);
58 funding_txo_hu_conv.ptrs_to.add(this);
59 this.funding_txo = funding_txo_hu_conv;
60 this.user_channel_id = obj.user_channel_id;
63 export class PaymentReceived extends Event {
64 public payment_hash: Uint8Array;
65 public payment_secret: Uint8Array;
67 private constructor(ptr: number, obj: bindings.LDKEvent.PaymentReceived) {
69 this.payment_hash = obj.payment_hash;
70 this.payment_secret = obj.payment_secret;
74 export class PaymentSent extends Event {
75 public payment_preimage: Uint8Array;
76 private constructor(ptr: number, obj: bindings.LDKEvent.PaymentSent) {
78 this.payment_preimage = obj.payment_preimage;
81 export class PaymentFailed extends Event {
82 public payment_hash: Uint8Array;
83 public rejected_by_dest: boolean;
84 private constructor(ptr: number, obj: bindings.LDKEvent.PaymentFailed) {
86 this.payment_hash = obj.payment_hash;
87 this.rejected_by_dest = obj.rejected_by_dest;
90 export class PendingHTLCsForwardable extends Event {
91 public time_forwardable: number;
92 private constructor(ptr: number, obj: bindings.LDKEvent.PendingHTLCsForwardable) {
94 this.time_forwardable = obj.time_forwardable;
97 export class SpendableOutputs extends Event {
98 public outputs: SpendableOutputDescriptor[];
99 private constructor(ptr: number, obj: bindings.LDKEvent.SpendableOutputs) {
101 const outputs: number[] = obj.outputs;
102 SpendableOutputDescriptor[] outputs_conv_27_arr = new SpendableOutputDescriptor[outputs.length];
103 for (int b = 0; b < outputs.length; b++) {
104 number outputs_conv_27 = outputs[b];
105 SpendableOutputDescriptor outputs_conv_27_hu_conv = SpendableOutputDescriptor.constr_from_ptr(outputs_conv_27);
106 outputs_conv_27_hu_conv.ptrs_to.add(this);
107 outputs_conv_27_arr[b] = outputs_conv_27_hu_conv;
109 this.outputs = outputs_conv_27_arr;