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 this.funding_txo = funding_txo_hu_conv;
59 this.user_channel_id = obj.user_channel_id;
62 export class PaymentReceived extends Event {
63 public payment_hash: Uint8Array;
64 public payment_secret: Uint8Array;
66 private constructor(ptr: number, obj: bindings.LDKEvent.PaymentReceived) {
68 this.payment_hash = obj.payment_hash;
69 this.payment_secret = obj.payment_secret;
73 export class PaymentSent extends Event {
74 public payment_preimage: Uint8Array;
75 private constructor(ptr: number, obj: bindings.LDKEvent.PaymentSent) {
77 this.payment_preimage = obj.payment_preimage;
80 export class PaymentFailed extends Event {
81 public payment_hash: Uint8Array;
82 public rejected_by_dest: boolean;
83 private constructor(ptr: number, obj: bindings.LDKEvent.PaymentFailed) {
85 this.payment_hash = obj.payment_hash;
86 this.rejected_by_dest = obj.rejected_by_dest;
89 export class PendingHTLCsForwardable extends Event {
90 public time_forwardable: number;
91 private constructor(ptr: number, obj: bindings.LDKEvent.PendingHTLCsForwardable) {
93 this.time_forwardable = obj.time_forwardable;
96 export class SpendableOutputs extends Event {
97 public outputs: SpendableOutputDescriptor[];
98 private constructor(ptr: number, obj: bindings.LDKEvent.SpendableOutputs) {
100 const outputs: number[] = obj.outputs;
101 SpendableOutputDescriptor[] arr_conv_27_arr = new SpendableOutputDescriptor[outputs.length];
102 for (int b = 0; b < outputs.length; b++) {
103 number arr_conv_27 = outputs[b];
104 SpendableOutputDescriptor arr_conv_27_hu_conv = SpendableOutputDescriptor.constr_from_ptr(arr_conv_27);
105 arr_conv_27_hu_conv.ptrs_to.add(this);
106 arr_conv_27_arr[b] = arr_conv_27_hu_conv;
108 this.outputs = arr_conv_27_arr;