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 if (raw_val instanceof bindings.LDKEvent.PaymentForwarded) {
32 return new PaymentForwarded(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 PaymentReceived extends Event {
52 public payment_hash: Uint8Array;
54 public purpose: PaymentPurpose;
55 private constructor(ptr: number, obj: bindings.LDKEvent.PaymentReceived) {
57 this.payment_hash = obj.payment_hash;
59 const purpose: number = obj.purpose;
60 PaymentPurpose purpose_hu_conv = PaymentPurpose.constr_from_ptr(purpose);
61 purpose_hu_conv.ptrs_to.add(this);
62 this.purpose = purpose_hu_conv;
65 export class PaymentSent extends Event {
66 public payment_preimage: Uint8Array;
67 private constructor(ptr: number, obj: bindings.LDKEvent.PaymentSent) {
69 this.payment_preimage = obj.payment_preimage;
72 export class PaymentFailed extends Event {
73 public payment_hash: Uint8Array;
74 public rejected_by_dest: boolean;
75 private constructor(ptr: number, obj: bindings.LDKEvent.PaymentFailed) {
77 this.payment_hash = obj.payment_hash;
78 this.rejected_by_dest = obj.rejected_by_dest;
81 export class PendingHTLCsForwardable extends Event {
82 public time_forwardable: number;
83 private constructor(ptr: number, obj: bindings.LDKEvent.PendingHTLCsForwardable) {
85 this.time_forwardable = obj.time_forwardable;
88 export class SpendableOutputs extends Event {
89 public outputs: SpendableOutputDescriptor[];
90 private constructor(ptr: number, obj: bindings.LDKEvent.SpendableOutputs) {
92 const outputs: number[] = obj.outputs;
93 SpendableOutputDescriptor[] outputs_conv_27_arr = new SpendableOutputDescriptor[outputs.length];
94 for (int b = 0; b < outputs.length; b++) {
95 number outputs_conv_27 = outputs[b];
96 SpendableOutputDescriptor outputs_conv_27_hu_conv = SpendableOutputDescriptor.constr_from_ptr(outputs_conv_27);
97 outputs_conv_27_hu_conv.ptrs_to.add(this);
98 outputs_conv_27_arr[b] = outputs_conv_27_hu_conv;
100 this.outputs = outputs_conv_27_arr;
103 export class PaymentForwarded extends Event {
104 public fee_earned_msat: Option_u64Z;
105 public claim_from_onchain_tx: boolean;
106 private constructor(ptr: number, obj: bindings.LDKEvent.PaymentForwarded) {
108 const fee_earned_msat: number = obj.fee_earned_msat;
109 Option_u64Z fee_earned_msat_hu_conv = Option_u64Z.constr_from_ptr(fee_earned_msat);
110 fee_earned_msat_hu_conv.ptrs_to.add(this);
111 this.fee_earned_msat = fee_earned_msat_hu_conv;
112 this.claim_from_onchain_tx = obj.claim_from_onchain_tx;
115 public Event clone() {
116 number ret = bindings.Event_clone(this.ptr);
117 Event ret_hu_conv = Event.constr_from_ptr(ret);
118 ret_hu_conv.ptrs_to.add(this);
122 public static Event constructor_funding_generation_ready(Uint8Array temporary_channel_id, number channel_value_satoshis, Uint8Array output_script, number user_channel_id) {
123 number ret = bindings.Event_funding_generation_ready(temporary_channel_id, channel_value_satoshis, output_script, user_channel_id);
124 Event ret_hu_conv = Event.constr_from_ptr(ret);
125 ret_hu_conv.ptrs_to.add(ret_hu_conv);
129 public static Event constructor_payment_received(Uint8Array payment_hash, number amt, PaymentPurpose purpose) {
130 number ret = bindings.Event_payment_received(payment_hash, amt, purpose.ptr);
131 Event ret_hu_conv = Event.constr_from_ptr(ret);
132 ret_hu_conv.ptrs_to.add(ret_hu_conv);
136 public static Event constructor_payment_sent(Uint8Array payment_preimage) {
137 number ret = bindings.Event_payment_sent(payment_preimage);
138 Event ret_hu_conv = Event.constr_from_ptr(ret);
139 ret_hu_conv.ptrs_to.add(ret_hu_conv);
143 public static Event constructor_payment_failed(Uint8Array payment_hash, boolean rejected_by_dest) {
144 number ret = bindings.Event_payment_failed(payment_hash, rejected_by_dest);
145 Event ret_hu_conv = Event.constr_from_ptr(ret);
146 ret_hu_conv.ptrs_to.add(ret_hu_conv);
150 public static Event constructor_pending_htlcs_forwardable(number time_forwardable) {
151 number ret = bindings.Event_pending_htlcs_forwardable(time_forwardable);
152 Event ret_hu_conv = Event.constr_from_ptr(ret);
153 ret_hu_conv.ptrs_to.add(ret_hu_conv);
157 public static Event constructor_spendable_outputs(SpendableOutputDescriptor[] outputs) {
158 number ret = bindings.Event_spendable_outputs(outputs != null ? Arrays.stream(outputs).map(outputs_conv_27 -> outputs_conv_27.ptr).toArray(number[]::new) : null);
159 Event ret_hu_conv = Event.constr_from_ptr(ret);
160 ret_hu_conv.ptrs_to.add(ret_hu_conv);
161 /* TODO 2 SpendableOutputDescriptor */;
165 public static Event constructor_payment_forwarded(Option_u64Z fee_earned_msat, boolean claim_from_onchain_tx) {
166 number ret = bindings.Event_payment_forwarded(fee_earned_msat.ptr, claim_from_onchain_tx);
167 Event ret_hu_conv = Event.constr_from_ptr(ret);
168 ret_hu_conv.ptrs_to.add(ret_hu_conv);
172 public Uint8Array write() {
173 Uint8Array ret = bindings.Event_write(this.ptr);