+typedef struct LDKPayer_JCalls {
+ atomic_size_t refcnt;
+ uint32_t node_id_meth;
+ uint32_t first_hops_meth;
+ uint32_t send_payment_meth;
+ uint32_t retry_payment_meth;
+} LDKPayer_JCalls;
+static void LDKPayer_JCalls_free(void* this_arg) {
+ LDKPayer_JCalls *j_calls = (LDKPayer_JCalls*) this_arg;
+ if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
+ js_free(j_calls->node_id_meth);
+ js_free(j_calls->first_hops_meth);
+ js_free(j_calls->send_payment_meth);
+ js_free(j_calls->retry_payment_meth);
+ FREE(j_calls);
+ }
+}
+LDKPublicKey node_id_LDKPayer_jcall(const void* this_arg) {
+ LDKPayer_JCalls *j_calls = (LDKPayer_JCalls*) this_arg;
+ int8_tArray ret = js_invoke_function_0(j_calls->node_id_meth);
+ LDKPublicKey ret_ref;
+ CHECK(*((uint32_t*)ret) == 33);
+ memcpy(ret_ref.compressed_form, (uint8_t*)(ret + 4), 33);
+ return ret_ref;
+}
+LDKCVec_ChannelDetailsZ first_hops_LDKPayer_jcall(const void* this_arg) {
+ LDKPayer_JCalls *j_calls = (LDKPayer_JCalls*) this_arg;
+ uint32_tArray ret = js_invoke_function_0(j_calls->first_hops_meth);
+ LDKCVec_ChannelDetailsZ ret_constr;
+ ret_constr.datalen = *((uint32_t*)ret);
+ if (ret_constr.datalen > 0)
+ ret_constr.data = MALLOC(ret_constr.datalen * sizeof(LDKChannelDetails), "LDKCVec_ChannelDetailsZ Elements");
+ else
+ ret_constr.data = NULL;
+ uint32_t* ret_vals = (uint32_t*)(ret + 4);
+ for (size_t q = 0; q < ret_constr.datalen; q++) {
+ uint32_t ret_conv_16 = ret_vals[q];
+ LDKChannelDetails ret_conv_16_conv;
+ ret_conv_16_conv.inner = (void*)(ret_conv_16 & (~1));
+ ret_conv_16_conv.is_owned = (ret_conv_16 & 1) || (ret_conv_16 == 0);
+ ret_conv_16_conv = ChannelDetails_clone(&ret_conv_16_conv);
+ ret_constr.data[q] = ret_conv_16_conv;
+ }
+ return ret_constr;
+}
+LDKCResult_PaymentIdPaymentSendFailureZ send_payment_LDKPayer_jcall(const void* this_arg, const LDKRoute * route, LDKThirtyTwoBytes payment_hash, LDKThirtyTwoBytes payment_secret) {
+ LDKPayer_JCalls *j_calls = (LDKPayer_JCalls*) this_arg;
+ LDKRoute route_var = *route;
+ uint64_t route_ref = 0;
+ route_var = Route_clone(route);
+ CHECK((((uint64_t)route_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
+ CHECK((((uint64_t)&route_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
+ route_ref = (uint64_t)route_var.inner;
+ if (route_var.is_owned) {
+ route_ref |= 1;
+ }
+ int8_tArray payment_hash_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
+ memcpy((uint8_t*)(payment_hash_arr + 4), payment_hash.data, 32);
+ int8_tArray payment_secret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
+ memcpy((uint8_t*)(payment_secret_arr + 4), payment_secret.data, 32);
+ uint32_t ret = js_invoke_function_3(j_calls->send_payment_meth, route_ref, payment_hash_arr, payment_secret_arr);
+ void* ret_ptr = (void*)(((uint64_t)ret) & ~1);
+ CHECK_ACCESS(ret_ptr);
+ LDKCResult_PaymentIdPaymentSendFailureZ ret_conv = *(LDKCResult_PaymentIdPaymentSendFailureZ*)(ret_ptr);
+ ret_conv = CResult_PaymentIdPaymentSendFailureZ_clone((LDKCResult_PaymentIdPaymentSendFailureZ*)(((uint64_t)ret) & ~1));
+ return ret_conv;
+}
+LDKCResult_NonePaymentSendFailureZ retry_payment_LDKPayer_jcall(const void* this_arg, const LDKRoute * route, LDKThirtyTwoBytes payment_id) {
+ LDKPayer_JCalls *j_calls = (LDKPayer_JCalls*) this_arg;
+ LDKRoute route_var = *route;
+ uint64_t route_ref = 0;
+ route_var = Route_clone(route);
+ CHECK((((uint64_t)route_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
+ CHECK((((uint64_t)&route_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
+ route_ref = (uint64_t)route_var.inner;
+ if (route_var.is_owned) {
+ route_ref |= 1;
+ }
+ int8_tArray payment_id_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
+ memcpy((uint8_t*)(payment_id_arr + 4), payment_id.data, 32);
+ uint32_t ret = js_invoke_function_2(j_calls->retry_payment_meth, route_ref, payment_id_arr);
+ void* ret_ptr = (void*)(((uint64_t)ret) & ~1);
+ CHECK_ACCESS(ret_ptr);
+ LDKCResult_NonePaymentSendFailureZ ret_conv = *(LDKCResult_NonePaymentSendFailureZ*)(ret_ptr);
+ ret_conv = CResult_NonePaymentSendFailureZ_clone((LDKCResult_NonePaymentSendFailureZ*)(((uint64_t)ret) & ~1));
+ return ret_conv;
+}
+static void LDKPayer_JCalls_cloned(LDKPayer* new_obj) {
+ LDKPayer_JCalls *j_calls = (LDKPayer_JCalls*) new_obj->this_arg;
+ atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
+}
+static inline LDKPayer LDKPayer_init (/*TODO: JS Object Reference */void* o) {
+ LDKPayer_JCalls *calls = MALLOC(sizeof(LDKPayer_JCalls), "LDKPayer_JCalls");
+ atomic_init(&calls->refcnt, 1);
+ //TODO: Assign calls->o from o
+
+ LDKPayer ret = {
+ .this_arg = (void*) calls,
+ .node_id = node_id_LDKPayer_jcall,
+ .first_hops = first_hops_LDKPayer_jcall,
+ .send_payment = send_payment_LDKPayer_jcall,
+ .retry_payment = retry_payment_LDKPayer_jcall,
+ .free = LDKPayer_JCalls_free,
+ };
+ return ret;
+}
+long __attribute__((visibility("default"))) TS_LDKPayer_new(/*TODO: JS Object Reference */void* o) {
+ LDKPayer *res_ptr = MALLOC(sizeof(LDKPayer), "LDKPayer");
+ *res_ptr = LDKPayer_init(o);
+ return (long)res_ptr;
+}
+int8_tArray __attribute__((visibility("default"))) TS_Payer_node_id(uint32_t this_arg) {
+ void* this_arg_ptr = (void*)(((uint64_t)this_arg) & ~1);
+ if (!(this_arg & 1)) { CHECK_ACCESS(this_arg_ptr); }
+ LDKPayer* this_arg_conv = (LDKPayer*)this_arg_ptr;
+ int8_tArray ret_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
+ memcpy((uint8_t*)(ret_arr + 4), (this_arg_conv->node_id)(this_arg_conv->this_arg).compressed_form, 33);
+ return ret_arr;
+}
+
+uint32_tArray __attribute__((visibility("default"))) TS_Payer_first_hops(uint32_t this_arg) {
+ void* this_arg_ptr = (void*)(((uint64_t)this_arg) & ~1);
+ if (!(this_arg & 1)) { CHECK_ACCESS(this_arg_ptr); }
+ LDKPayer* this_arg_conv = (LDKPayer*)this_arg_ptr;
+ LDKCVec_ChannelDetailsZ ret_var = (this_arg_conv->first_hops)(this_arg_conv->this_arg);
+ uint32_tArray ret_arr = NULL;
+ ret_arr = init_arr(ret_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
+ uint32_t *ret_arr_ptr = (uint32_t*)(ret_arr + 4);
+ for (size_t q = 0; q < ret_var.datalen; q++) {
+ LDKChannelDetails ret_conv_16_var = ret_var.data[q];
+ uint64_t ret_conv_16_ref = 0;
+ CHECK((((uint64_t)ret_conv_16_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
+ CHECK((((uint64_t)&ret_conv_16_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
+ ret_conv_16_ref = (uint64_t)ret_conv_16_var.inner;
+ if (ret_conv_16_var.is_owned) {
+ ret_conv_16_ref |= 1;
+ }
+ ret_arr_ptr[q] = ret_conv_16_ref;
+ }
+
+ FREE(ret_var.data);
+ return ret_arr;
+}
+
+uint32_t __attribute__((visibility("default"))) TS_Payer_send_payment(uint32_t this_arg, uint32_t route, int8_tArray payment_hash, int8_tArray payment_secret) {
+ void* this_arg_ptr = (void*)(((uint64_t)this_arg) & ~1);
+ if (!(this_arg & 1)) { CHECK_ACCESS(this_arg_ptr); }
+ LDKPayer* this_arg_conv = (LDKPayer*)this_arg_ptr;
+ LDKRoute route_conv;
+ route_conv.inner = (void*)(route & (~1));
+ route_conv.is_owned = false;
+ LDKThirtyTwoBytes payment_hash_ref;
+ CHECK(*((uint32_t*)payment_hash) == 32);
+ memcpy(payment_hash_ref.data, (uint8_t*)(payment_hash + 4), 32);
+ LDKThirtyTwoBytes payment_secret_ref;
+ CHECK(*((uint32_t*)payment_secret) == 32);
+ memcpy(payment_secret_ref.data, (uint8_t*)(payment_secret + 4), 32);
+ LDKCResult_PaymentIdPaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_PaymentIdPaymentSendFailureZ), "LDKCResult_PaymentIdPaymentSendFailureZ");
+ *ret_conv = (this_arg_conv->send_payment)(this_arg_conv->this_arg, &route_conv, payment_hash_ref, payment_secret_ref);
+ return (uint64_t)ret_conv;
+}
+
+uint32_t __attribute__((visibility("default"))) TS_Payer_retry_payment(uint32_t this_arg, uint32_t route, int8_tArray payment_id) {
+ void* this_arg_ptr = (void*)(((uint64_t)this_arg) & ~1);
+ if (!(this_arg & 1)) { CHECK_ACCESS(this_arg_ptr); }
+ LDKPayer* this_arg_conv = (LDKPayer*)this_arg_ptr;
+ LDKRoute route_conv;
+ route_conv.inner = (void*)(route & (~1));
+ route_conv.is_owned = false;
+ LDKThirtyTwoBytes payment_id_ref;
+ CHECK(*((uint32_t*)payment_id) == 32);
+ memcpy(payment_id_ref.data, (uint8_t*)(payment_id + 4), 32);
+ LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
+ *ret_conv = (this_arg_conv->retry_payment)(this_arg_conv->this_arg, &route_conv, payment_id_ref);
+ return (uint64_t)ret_conv;
+}
+
+typedef struct LDKRouter_JCalls {
+ atomic_size_t refcnt;
+ uint32_t find_route_meth;
+} LDKRouter_JCalls;
+static void LDKRouter_JCalls_free(void* this_arg) {
+ LDKRouter_JCalls *j_calls = (LDKRouter_JCalls*) this_arg;
+ if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
+ js_free(j_calls->find_route_meth);
+ FREE(j_calls);
+ }
+}
+LDKCResult_RouteLightningErrorZ find_route_LDKRouter_jcall(const void* this_arg, LDKPublicKey payer, const LDKRouteParameters * params, LDKCVec_ChannelDetailsZ * first_hops, const LDKScore * scorer) {
+ LDKRouter_JCalls *j_calls = (LDKRouter_JCalls*) this_arg;
+ int8_tArray payer_arr = init_arr(33, sizeof(uint8_t), "Native int8_tArray Bytes");
+ memcpy((uint8_t*)(payer_arr + 4), payer.compressed_form, 33);
+ LDKRouteParameters params_var = *params;
+ uint64_t params_ref = 0;
+ params_var = RouteParameters_clone(params);
+ CHECK((((uint64_t)params_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
+ CHECK((((uint64_t)¶ms_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
+ params_ref = (uint64_t)params_var.inner;
+ if (params_var.is_owned) {
+ params_ref |= 1;
+ }
+ LDKCVec_ChannelDetailsZ *first_hops_var_ptr = first_hops;
+ uint32_tArray first_hops_arr = NULL;
+ if (first_hops != NULL) {
+ LDKCVec_ChannelDetailsZ first_hops_var = *first_hops_var_ptr;
+ first_hops_arr = init_arr(first_hops_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
+ uint32_t *first_hops_arr_ptr = (uint32_t*)(first_hops_arr + 4);
+ for (size_t q = 0; q < first_hops_var.datalen; q++) {
+ LDKChannelDetails first_hops_conv_16_var = first_hops_var.data[q];
+ uint64_t first_hops_conv_16_ref = 0;
+ CHECK((((uint64_t)first_hops_conv_16_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
+ CHECK((((uint64_t)&first_hops_conv_16_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
+ first_hops_conv_16_ref = (uint64_t)first_hops_conv_16_var.inner;
+ if (first_hops_conv_16_var.is_owned) {
+ first_hops_conv_16_ref |= 1;
+ }
+ first_hops_arr_ptr[q] = first_hops_conv_16_ref;
+ }
+
+ }
+ // WARNING: This object doesn't live past this scope, needs clone!
+ uint64_t ret_scorer = ((uint64_t)scorer) | 1;
+ uint32_t ret = js_invoke_function_4(j_calls->find_route_meth, payer_arr, params_ref, first_hops_arr, ret_scorer);
+ void* ret_ptr = (void*)(((uint64_t)ret) & ~1);
+ CHECK_ACCESS(ret_ptr);
+ LDKCResult_RouteLightningErrorZ ret_conv = *(LDKCResult_RouteLightningErrorZ*)(ret_ptr);
+ ret_conv = CResult_RouteLightningErrorZ_clone((LDKCResult_RouteLightningErrorZ*)(((uint64_t)ret) & ~1));
+ return ret_conv;
+}
+static void LDKRouter_JCalls_cloned(LDKRouter* new_obj) {
+ LDKRouter_JCalls *j_calls = (LDKRouter_JCalls*) new_obj->this_arg;
+ atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
+}
+static inline LDKRouter LDKRouter_init (/*TODO: JS Object Reference */void* o) {
+ LDKRouter_JCalls *calls = MALLOC(sizeof(LDKRouter_JCalls), "LDKRouter_JCalls");
+ atomic_init(&calls->refcnt, 1);
+ //TODO: Assign calls->o from o
+
+ LDKRouter ret = {
+ .this_arg = (void*) calls,
+ .find_route = find_route_LDKRouter_jcall,
+ .free = LDKRouter_JCalls_free,
+ };
+ return ret;
+}
+long __attribute__((visibility("default"))) TS_LDKRouter_new(/*TODO: JS Object Reference */void* o) {
+ LDKRouter *res_ptr = MALLOC(sizeof(LDKRouter), "LDKRouter");
+ *res_ptr = LDKRouter_init(o);
+ return (long)res_ptr;
+}
+uint32_t __attribute__((visibility("default"))) TS_Router_find_route(uint32_t this_arg, int8_tArray payer, uint32_t params, uint32_tArray first_hops, uint32_t scorer) {
+ void* this_arg_ptr = (void*)(((uint64_t)this_arg) & ~1);
+ if (!(this_arg & 1)) { CHECK_ACCESS(this_arg_ptr); }
+ LDKRouter* this_arg_conv = (LDKRouter*)this_arg_ptr;
+ LDKPublicKey payer_ref;
+ CHECK(*((uint32_t*)payer) == 33);
+ memcpy(payer_ref.compressed_form, (uint8_t*)(payer + 4), 33);
+ LDKRouteParameters params_conv;
+ params_conv.inner = (void*)(params & (~1));
+ params_conv.is_owned = false;
+ LDKCVec_ChannelDetailsZ first_hops_constr;
+ LDKCVec_ChannelDetailsZ *first_hops_ptr = NULL;
+ if (first_hops != 0) {
+ first_hops_constr.datalen = *((uint32_t*)first_hops);
+ if (first_hops_constr.datalen > 0)
+ first_hops_constr.data = MALLOC(first_hops_constr.datalen * sizeof(LDKChannelDetails), "LDKCVec_ChannelDetailsZ Elements");
+ else
+ first_hops_constr.data = NULL;
+ uint32_t* first_hops_vals = (uint32_t*)(first_hops + 4);
+ for (size_t q = 0; q < first_hops_constr.datalen; q++) {
+ uint32_t first_hops_conv_16 = first_hops_vals[q];
+ LDKChannelDetails first_hops_conv_16_conv;
+ first_hops_conv_16_conv.inner = (void*)(first_hops_conv_16 & (~1));
+ first_hops_conv_16_conv.is_owned = (first_hops_conv_16 & 1) || (first_hops_conv_16 == 0);
+ first_hops_constr.data[q] = first_hops_conv_16_conv;
+ }
+ first_hops_ptr = &first_hops_constr;
+ }
+ void* scorer_ptr = (void*)(((uint64_t)scorer) & ~1);
+ if (!(scorer & 1)) { CHECK_ACCESS(scorer_ptr); }
+ LDKScore* scorer_conv = (LDKScore*)scorer_ptr;
+ LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
+ *ret_conv = (this_arg_conv->find_route)(this_arg_conv->this_arg, payer_ref, ¶ms_conv, first_hops_ptr, scorer_conv);
+ if (first_hops_ptr != NULL) { FREE(first_hops_constr.data); }
+ return (uint64_t)ret_conv;
+}
+