]> git.bitcoin.ninja Git - ldk-java/blob - ts/structs/Event.ts
Update bindings to latest upstream + ChannelMonitor_clone patch
[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.FundingBroadcastSafe) {
17                         return new FundingBroadcastSafe(this.ptr, raw_val);
18                 }
19                 if (raw_val instanceof bindings.LDKEvent.PaymentReceived) {
20                         return new PaymentReceived(this.ptr, raw_val);
21                 }
22                 if (raw_val instanceof bindings.LDKEvent.PaymentSent) {
23                         return new PaymentSent(this.ptr, raw_val);
24                 }
25                 if (raw_val instanceof bindings.LDKEvent.PaymentFailed) {
26                         return new PaymentFailed(this.ptr, raw_val);
27                 }
28                 if (raw_val instanceof bindings.LDKEvent.PendingHTLCsForwardable) {
29                         return new PendingHTLCsForwardable(this.ptr, raw_val);
30                 }
31                 if (raw_val instanceof bindings.LDKEvent.SpendableOutputs) {
32                         return new SpendableOutputs(this.ptr, raw_val);
33                 }
34                 throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
35         }
36
37 }
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) {
44                 super(null, ptr);
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;
49         }
50 }
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) {
55                 super(null, ptr);
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;
61         }
62 }
63 export class PaymentReceived extends Event {
64         public payment_hash: Uint8Array;
65         public payment_secret: Uint8Array;
66         public amt: number;
67         private constructor(ptr: number, obj: bindings.LDKEvent.PaymentReceived) {
68                 super(null, ptr);
69                 this.payment_hash = obj.payment_hash;
70                 this.payment_secret = obj.payment_secret;
71                 this.amt = obj.amt;
72         }
73 }
74 export class PaymentSent extends Event {
75         public payment_preimage: Uint8Array;
76         private constructor(ptr: number, obj: bindings.LDKEvent.PaymentSent) {
77                 super(null, ptr);
78                 this.payment_preimage = obj.payment_preimage;
79         }
80 }
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) {
85                 super(null, ptr);
86                 this.payment_hash = obj.payment_hash;
87                 this.rejected_by_dest = obj.rejected_by_dest;
88         }
89 }
90 export class PendingHTLCsForwardable extends Event {
91         public time_forwardable: number;
92         private constructor(ptr: number, obj: bindings.LDKEvent.PendingHTLCsForwardable) {
93                 super(null, ptr);
94                 this.time_forwardable = obj.time_forwardable;
95         }
96 }
97 export class SpendableOutputs extends Event {
98         public outputs: SpendableOutputDescriptor[];
99         private constructor(ptr: number, obj: bindings.LDKEvent.SpendableOutputs) {
100                 super(null, ptr);
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;
108                         }
109                 this.outputs = outputs_conv_27_arr;
110         }
111 }