]> git.bitcoin.ninja Git - ldk-java/blob - ts/structs/Event.ts
Merge pull request #29 from TheBlueMatt/main
[ldk-java] / ts / structs / Event.ts
1
2 import CommonBase from './CommonBase';
3 import * as bindings from '../bindings' // TODO: figure out location
4
5 export default class Event extends CommonBase {
6         protected constructor(_dummy: object, ptr: number) { super(ptr); }
7         protected finalize() {
8                 super.finalize();
9                 if (this.ptr != 0) { bindings.Event_free(this.ptr); }
10         }
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);
15                 }
16                 if (raw_val instanceof bindings.LDKEvent.PaymentReceived) {
17                         return new PaymentReceived(this.ptr, raw_val);
18                 }
19                 if (raw_val instanceof bindings.LDKEvent.PaymentSent) {
20                         return new PaymentSent(this.ptr, raw_val);
21                 }
22                 if (raw_val instanceof bindings.LDKEvent.PaymentFailed) {
23                         return new PaymentFailed(this.ptr, raw_val);
24                 }
25                 if (raw_val instanceof bindings.LDKEvent.PendingHTLCsForwardable) {
26                         return new PendingHTLCsForwardable(this.ptr, raw_val);
27                 }
28                 if (raw_val instanceof bindings.LDKEvent.SpendableOutputs) {
29                         return new SpendableOutputs(this.ptr, raw_val);
30                 }
31                 throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
32         }
33
34 }
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) {
41                 super(null, ptr);
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;
46         }
47 }
48 export class PaymentReceived extends Event {
49         public payment_hash: Uint8Array;
50         public payment_preimage: Uint8Array;
51         public payment_secret: Uint8Array;
52         public amt: number;
53         public user_payment_id: number;
54         private constructor(ptr: number, obj: bindings.LDKEvent.PaymentReceived) {
55                 super(null, ptr);
56                 this.payment_hash = obj.payment_hash;
57                 this.payment_preimage = obj.payment_preimage;
58                 this.payment_secret = obj.payment_secret;
59                 this.amt = obj.amt;
60                 this.user_payment_id = obj.user_payment_id;
61         }
62 }
63 export class PaymentSent extends Event {
64         public payment_preimage: Uint8Array;
65         private constructor(ptr: number, obj: bindings.LDKEvent.PaymentSent) {
66                 super(null, ptr);
67                 this.payment_preimage = obj.payment_preimage;
68         }
69 }
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) {
74                 super(null, ptr);
75                 this.payment_hash = obj.payment_hash;
76                 this.rejected_by_dest = obj.rejected_by_dest;
77         }
78 }
79 export class PendingHTLCsForwardable extends Event {
80         public time_forwardable: number;
81         private constructor(ptr: number, obj: bindings.LDKEvent.PendingHTLCsForwardable) {
82                 super(null, ptr);
83                 this.time_forwardable = obj.time_forwardable;
84         }
85 }
86 export class SpendableOutputs extends Event {
87         public outputs: SpendableOutputDescriptor[];
88         private constructor(ptr: number, obj: bindings.LDKEvent.SpendableOutputs) {
89                 super(null, ptr);
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;
97                         }
98                 this.outputs = outputs_conv_27_arr;
99         }
100 }
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);
105                 return ret_hu_conv;
106         }
107
108         public Uint8Array write() {
109                 Uint8Array ret = bindings.Event_write(this.ptr);
110                 return ret;
111         }
112
113 }