-uint32_t __attribute__((visibility("default"))) TS_LDKPaymentPurpose_ref_from_ptr(uint32_t ptr) {
- LDKPaymentPurpose *obj = (LDKPaymentPurpose*)(ptr & ~1);
- switch(obj->tag) {
- case LDKPaymentPurpose_InvoicePayment: {
- int8_tArray payment_preimage_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
- memcpy((uint8_t*)(payment_preimage_arr + 4), obj->invoice_payment.payment_preimage.data, 32);
- int8_tArray payment_secret_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
- memcpy((uint8_t*)(payment_secret_arr + 4), obj->invoice_payment.payment_secret.data, 32);
- return 0 /* LDKPaymentPurpose - InvoicePayment */; (void) payment_preimage_arr; (void) payment_secret_arr; (void) obj->invoice_payment.user_payment_id;
- }
- case LDKPaymentPurpose_SpontaneousPayment: {
- int8_tArray spontaneous_payment_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
- memcpy((uint8_t*)(spontaneous_payment_arr + 4), obj->spontaneous_payment.data, 32);
- return 0 /* LDKPaymentPurpose - SpontaneousPayment */; (void) spontaneous_payment_arr;
- }
- default: abort();
- }
-}
-uint32_t __attribute__((visibility("default"))) TS_LDKClosureReason_ref_from_ptr(uint32_t ptr) {
- LDKClosureReason *obj = (LDKClosureReason*)(ptr & ~1);
- switch(obj->tag) {
- case LDKClosureReason_CounterpartyForceClosed: {
- LDKStr peer_msg_str = obj->counterparty_force_closed.peer_msg;
- jstring peer_msg_conv = str_ref_to_ts(peer_msg_str.chars, peer_msg_str.len);
- return 0 /* LDKClosureReason - CounterpartyForceClosed */; (void) peer_msg_conv;
- }
- case LDKClosureReason_HolderForceClosed: {
- return 0 /* LDKClosureReason - HolderForceClosed */;
- }
- case LDKClosureReason_CooperativeClosure: {
- return 0 /* LDKClosureReason - CooperativeClosure */;
- }
- case LDKClosureReason_CommitmentTxConfirmed: {
- return 0 /* LDKClosureReason - CommitmentTxConfirmed */;
- }
- case LDKClosureReason_ProcessingError: {
- LDKStr err_str = obj->processing_error.err;
- jstring err_conv = str_ref_to_ts(err_str.chars, err_str.len);
- return 0 /* LDKClosureReason - ProcessingError */; (void) err_conv;
- }
- case LDKClosureReason_DisconnectedPeer: {
- return 0 /* LDKClosureReason - DisconnectedPeer */;
- }
- case LDKClosureReason_OutdatedChannelManager: {
- return 0 /* LDKClosureReason - OutdatedChannelManager */;
- }
- default: abort();
- }
-}
-uint32_t __attribute__((visibility("default"))) TS_LDKEvent_ref_from_ptr(uint32_t ptr) {
- LDKEvent *obj = (LDKEvent*)(ptr & ~1);
- switch(obj->tag) {
- case LDKEvent_FundingGenerationReady: {
- int8_tArray temporary_channel_id_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
- memcpy((uint8_t*)(temporary_channel_id_arr + 4), obj->funding_generation_ready.temporary_channel_id.data, 32);
- LDKCVec_u8Z output_script_var = obj->funding_generation_ready.output_script;
- int8_tArray output_script_arr = init_arr(output_script_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
- memcpy((uint8_t*)(output_script_arr + 4), output_script_var.data, output_script_var.datalen);
- return 0 /* LDKEvent - FundingGenerationReady */; (void) temporary_channel_id_arr; (void) obj->funding_generation_ready.channel_value_satoshis; (void) output_script_arr; (void) obj->funding_generation_ready.user_channel_id;
- }
- case LDKEvent_PaymentReceived: {
- int8_tArray payment_hash_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
- memcpy((uint8_t*)(payment_hash_arr + 4), obj->payment_received.payment_hash.data, 32);
- uint64_t purpose_ref = ((uint64_t)&obj->payment_received.purpose) | 1;
- return 0 /* LDKEvent - PaymentReceived */; (void) payment_hash_arr; (void) obj->payment_received.amt; (void) purpose_ref;
- }
- case LDKEvent_PaymentSent: {
- int8_tArray payment_id_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
- memcpy((uint8_t*)(payment_id_arr + 4), obj->payment_sent.payment_id.data, 32);
- int8_tArray payment_preimage_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
- memcpy((uint8_t*)(payment_preimage_arr + 4), obj->payment_sent.payment_preimage.data, 32);
- int8_tArray payment_hash_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
- memcpy((uint8_t*)(payment_hash_arr + 4), obj->payment_sent.payment_hash.data, 32);
- uint64_t fee_paid_msat_ref = ((uint64_t)&obj->payment_sent.fee_paid_msat) | 1;
- return 0 /* LDKEvent - PaymentSent */; (void) payment_id_arr; (void) payment_preimage_arr; (void) payment_hash_arr; (void) fee_paid_msat_ref;
- }
- case LDKEvent_PaymentPathFailed: {
- int8_tArray payment_id_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
- memcpy((uint8_t*)(payment_id_arr + 4), obj->payment_path_failed.payment_id.data, 32);
- int8_tArray payment_hash_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
- memcpy((uint8_t*)(payment_hash_arr + 4), obj->payment_path_failed.payment_hash.data, 32);
- uint64_t network_update_ref = ((uint64_t)&obj->payment_path_failed.network_update) | 1;
- LDKCVec_RouteHopZ path_var = obj->payment_path_failed.path;
- uint32_tArray path_arr = NULL;
- path_arr = init_arr(path_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
- uint32_t *path_arr_ptr = (uint32_t*)(path_arr + 4);
- for (size_t k = 0; k < path_var.datalen; k++) {
- LDKRouteHop path_conv_10_var = path_var.data[k];
- uint64_t path_conv_10_ref = 0;
- CHECK((((uint64_t)path_conv_10_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
- CHECK((((uint64_t)&path_conv_10_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
- path_conv_10_ref = (uint64_t)path_conv_10_var.inner & ~1;
- path_arr_ptr[k] = path_conv_10_ref;
- }
-
- uint64_t short_channel_id_ref = ((uint64_t)&obj->payment_path_failed.short_channel_id) | 1;
- LDKRouteParameters retry_var = obj->payment_path_failed.retry;
- uint64_t retry_ref = 0;
- if ((uint64_t)retry_var.inner > 4096) {
- CHECK((((uint64_t)retry_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
- CHECK((((uint64_t)&retry_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
- retry_ref = (uint64_t)retry_var.inner & ~1;
- }
- return 0 /* LDKEvent - PaymentPathFailed */; (void) payment_id_arr; (void) payment_hash_arr; (void) obj->payment_path_failed.rejected_by_dest; (void) network_update_ref; (void) obj->payment_path_failed.all_paths_failed; (void) path_arr; (void) short_channel_id_ref; (void) retry_ref;
- }
- case LDKEvent_PendingHTLCsForwardable: {
- return 0 /* LDKEvent - PendingHTLCsForwardable */; (void) obj->pending_htl_cs_forwardable.time_forwardable;
- }
- case LDKEvent_SpendableOutputs: {
- LDKCVec_SpendableOutputDescriptorZ outputs_var = obj->spendable_outputs.outputs;
- uint32_tArray outputs_arr = NULL;
- outputs_arr = init_arr(outputs_var.datalen, sizeof(uint32_t), "Native uint32_tArray Bytes");
- uint32_t *outputs_arr_ptr = (uint32_t*)(outputs_arr + 4);
- for (size_t b = 0; b < outputs_var.datalen; b++) {
- uint64_t outputs_conv_27_ref = ((uint64_t)&outputs_var.data[b]) | 1;
- outputs_arr_ptr[b] = outputs_conv_27_ref;
- }
-
- return 0 /* LDKEvent - SpendableOutputs */; (void) outputs_arr;
- }
- case LDKEvent_PaymentForwarded: {
- uint64_t fee_earned_msat_ref = ((uint64_t)&obj->payment_forwarded.fee_earned_msat) | 1;
- return 0 /* LDKEvent - PaymentForwarded */; (void) fee_earned_msat_ref; (void) obj->payment_forwarded.claim_from_onchain_tx;
- }
- case LDKEvent_ChannelClosed: {
- int8_tArray channel_id_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
- memcpy((uint8_t*)(channel_id_arr + 4), obj->channel_closed.channel_id.data, 32);
- uint64_t reason_ref = ((uint64_t)&obj->channel_closed.reason) | 1;
- return 0 /* LDKEvent - ChannelClosed */; (void) channel_id_arr; (void) obj->channel_closed.user_channel_id; (void) reason_ref;
- }
- case LDKEvent_DiscardFunding: {
- int8_tArray channel_id_arr = init_arr(32, sizeof(uint8_t), "Native int8_tArray Bytes");
- memcpy((uint8_t*)(channel_id_arr + 4), obj->discard_funding.channel_id.data, 32);
- LDKTransaction transaction_var = obj->discard_funding.transaction;
- int8_tArray transaction_arr = init_arr(transaction_var.datalen, sizeof(uint8_t), "Native int8_tArray Bytes");
- memcpy((uint8_t*)(transaction_arr + 4), transaction_var.data, transaction_var.datalen);
- return 0 /* LDKEvent - DiscardFunding */; (void) channel_id_arr; (void) transaction_arr;
- }
- default: abort();
- }
-}
-uint32_t __attribute__((visibility("default"))) TS_LDKCVec_EventZ_new(uint32_tArray elems) {
- LDKCVec_EventZ *ret = MALLOC(sizeof(LDKCVec_EventZ), "LDKCVec_EventZ");
- ret->datalen = *((uint32_t*)elems);
- if (ret->datalen == 0) {
- ret->data = NULL;
- } else {
- ret->data = MALLOC(sizeof(LDKEvent) * ret->datalen, "LDKCVec_EventZ Data");
- uint32_t *java_elems = (uint32_t*)(elems + 4);
- for (size_t i = 0; i < ret->datalen; i++) {
- uint32_t arr_elem = java_elems[i];
- void* arr_elem_ptr = (void*)(((uint64_t)arr_elem) & ~1);
- CHECK_ACCESS(arr_elem_ptr);
- LDKEvent arr_elem_conv = *(LDKEvent*)(arr_elem_ptr);
- arr_elem_conv = Event_clone((LDKEvent*)(((uint64_t)arr_elem) & ~1));
- ret->data[i] = arr_elem_conv;
- }
- }
- return (uint64_t)ret;
-}