From 3939ab180169d37f76e2c1166989488faa49640d Mon Sep 17 00:00:00 2001 From: Dominique Padiou <5765435+dpad85@users.noreply.github.com> Date: Thu, 30 Nov 2023 17:37:10 +0100 Subject: [PATCH] (android) Use TxId whenever possible See a1d972e6 for details. --- .../fr/acinq/phoenix/android/components/Buttons.kt | 7 ++++--- .../payments/details/PaymentDetailsSplashView.kt | 9 +++++---- .../payments/details/PaymentDetailsTechnicalView.kt | 12 ++++++------ .../fr/acinq/phoenix/android/services/NodeService.kt | 3 ++- .../android/settings/channels/ChannelDetailsView.kt | 2 +- .../android/settings/walletinfo/WalletInfoView.kt | 4 ++-- .../phoenix/android/utils/LegacyMigrationHelper.kt | 11 ++++++----- 7 files changed, 26 insertions(+), 22 deletions(-) diff --git a/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/components/Buttons.kt b/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/components/Buttons.kt index fb4565ff0..a230d9012 100644 --- a/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/components/Buttons.kt +++ b/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/components/Buttons.kt @@ -46,6 +46,7 @@ import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.TextUnit import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import fr.acinq.bitcoin.TxId import fr.acinq.phoenix.android.R import fr.acinq.phoenix.android.business import fr.acinq.phoenix.android.utils.copyToClipboard @@ -398,10 +399,10 @@ fun WebLink( @Composable fun TransactionLinkButton( modifier: Modifier = Modifier, - txId: String, + txId: TxId, ) { WebLink( - text = txId, + text = txId.toString(), url = txUrl(txId = txId), space = 4.dp, maxLines = 1, @@ -413,7 +414,7 @@ fun TransactionLinkButton( } @Composable -fun txUrl(txId: String): String { +fun txUrl(txId: TxId): String { return business.blockchainExplorer.txUrl(txId = txId, website = BlockchainExplorer.Website.MempoolSpace) } diff --git a/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/payments/details/PaymentDetailsSplashView.kt b/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/payments/details/PaymentDetailsSplashView.kt index 6182b64aa..a9e90ebb2 100644 --- a/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/payments/details/PaymentDetailsSplashView.kt +++ b/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/payments/details/PaymentDetailsSplashView.kt @@ -41,6 +41,7 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import fr.acinq.bitcoin.ByteVector32 +import fr.acinq.bitcoin.TxId import fr.acinq.lightning.blockchain.electrum.ElectrumConnectionStatus import fr.acinq.lightning.blockchain.electrum.getConfirmations import fr.acinq.lightning.db.* @@ -576,7 +577,7 @@ private fun EditPaymentDetails( @Composable private fun ConfirmationView( - txId: ByteVector32, + txId: TxId, channelId: ByteVector32, isConfirmed: Boolean, canBeBumped: Boolean, @@ -584,7 +585,7 @@ private fun ConfirmationView( minDepth: Int? = null, // sometimes we know how many confirmations are needed ) { val log = logger("PaymentDetailsSplashView") - val txUrl = txUrl(txId = txId.toHex()) + val txUrl = txUrl(txId = txId) val context = LocalContext.current val electrumClient = business.electrumClient var showBumpTxDialog by remember { mutableStateOf(false) } @@ -604,9 +605,9 @@ private fun ConfirmationView( suspend fun getConfirmations(): Int { val confirmations = electrumClient.getConfirmations(txId) - log.debug { "retrieved confirmations count=$confirmations from electrum for tx=${txId.toHex()}" } + log.debug { "retrieved confirmations=$confirmations from electrum for tx=$txId" } return confirmations ?: run { - log.debug { "retrying getConfirmations from Electrum in 5 sec" } + log.debug { "retrying getConfirmations from electrum in 5 sec" } delay(5_000) getConfirmations() } diff --git a/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/payments/details/PaymentDetailsTechnicalView.kt b/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/payments/details/PaymentDetailsTechnicalView.kt index 6e6f661db..5bc1ab132 100644 --- a/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/payments/details/PaymentDetailsTechnicalView.kt +++ b/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/payments/details/PaymentDetailsTechnicalView.kt @@ -309,7 +309,7 @@ private fun DetailsForChannelClose( ) TechnicalRow( label = stringResource(id = R.string.paymentdetails_closing_tx_label), - content = { TransactionLinkButton(txId = payment.txId.toHex()) } + content = { TransactionLinkButton(txId = payment.txId) } ) TechnicalRowSelectable( label = stringResource(id = R.string.paymentdetails_closing_type_label), @@ -329,7 +329,7 @@ private fun DetailsForCpfp( ) { TechnicalRow( label = stringResource(id = R.string.paymentdetails_splice_cpfp_transaction_label), - content = { TransactionLinkButton(txId = payment.txId.toHex()) } + content = { TransactionLinkButton(txId = payment.txId) } ) } @@ -347,7 +347,7 @@ private fun DetailsForSpliceOut( ) TechnicalRow( label = stringResource(id = R.string.paymentdetails_splice_out_tx_label), - content = { TransactionLinkButton(txId = payment.txId.toHex()) } + content = { TransactionLinkButton(txId = payment.txId) } ) } @@ -374,7 +374,7 @@ private fun DetailsForIncoming( Row { Text(text = stringResource(id = R.string.paymentdetails_dualswapin_tx_value, index + 1)) Spacer(modifier = Modifier.width(4.dp)) - TransactionLinkButton(txId = outpoint.txid.toHex()) + TransactionLinkButton(txId = outpoint.txid) } } } @@ -414,7 +414,7 @@ private fun ReceivedWithNewChannel( } TechnicalRow( label = stringResource(id = R.string.paymentdetails_tx_id_label), - content = { TransactionLinkButton(txId = receivedWith.txId.toHex()) } + content = { TransactionLinkButton(txId = receivedWith.txId) } ) TechnicalRowAmount(label = stringResource(id = R.string.paymentdetails_amount_received_label), amount = receivedWith.amount, rateThen = rateThen) } @@ -435,7 +435,7 @@ private fun ReceivedWithSpliceIn( } TechnicalRow( label = stringResource(id = R.string.paymentdetails_tx_id_label), - content = { TransactionLinkButton(txId = receivedWith.txId.toHex()) } + content = { TransactionLinkButton(txId = receivedWith.txId) } ) TechnicalRowAmount(label = stringResource(id = R.string.paymentdetails_amount_received_label), amount = receivedWith.amount, rateThen = rateThen) } diff --git a/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/services/NodeService.kt b/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/services/NodeService.kt index 5cf02eee0..8fe1689f0 100644 --- a/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/services/NodeService.kt +++ b/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/services/NodeService.kt @@ -14,6 +14,7 @@ import androidx.lifecycle.MutableLiveData import com.google.android.gms.tasks.OnCompleteListener import com.google.firebase.messaging.FirebaseMessaging import fr.acinq.bitcoin.ByteVector32 +import fr.acinq.bitcoin.TxId import fr.acinq.lightning.LiquidityEvents import fr.acinq.lightning.MilliSatoshi import fr.acinq.lightning.io.PaymentReceived @@ -239,7 +240,7 @@ class NodeService : Service() { requestCheckLegacyChannels = requestCheckLegacyChannels, isTorEnabled = isTorEnabled, liquidityPolicy = liquidityPolicy, - trustedSwapInTxs = trustedSwapInTxs.map { ByteVector32.fromValidHex(it) }.toSet() + trustedSwapInTxs = trustedSwapInTxs.map { TxId(it) }.toSet() ) ) diff --git a/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/settings/channels/ChannelDetailsView.kt b/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/settings/channels/ChannelDetailsView.kt index b77b2be3d..914a83824 100644 --- a/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/settings/channels/ChannelDetailsView.kt +++ b/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/settings/channels/ChannelDetailsView.kt @@ -174,7 +174,7 @@ private fun CommitmentDetailsView( val btcUnit = LocalBitcoinUnit.current val paymentsManager = business.paymentsManager val linkedPayments by produceState>(initialValue = emptyList()) { - value = paymentsManager.listPaymentsForTxId(ByteVector32.fromValidHex(commitment.fundingTxId)) + value = paymentsManager.listPaymentsForTxId(commitment.fundingTxId) } SettingWithDecoration( diff --git a/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/settings/walletinfo/WalletInfoView.kt b/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/settings/walletinfo/WalletInfoView.kt index 8895bffb4..a99a8e358 100644 --- a/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/settings/walletinfo/WalletInfoView.kt +++ b/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/settings/walletinfo/WalletInfoView.kt @@ -195,7 +195,7 @@ private fun OnchainBalanceView( @Composable fun UtxoRow(utxo: WalletState.Utxo, progress: Pair?) { val context = LocalContext.current - val txUrl = txUrl(txId = utxo.outPoint.txid.toHex()) + val txUrl = txUrl(txId = utxo.outPoint.txid) Row( modifier = Modifier .clickable(role = Role.Button, onClickLabel = stringResource(id = R.string.accessibility_explorer_link)) { @@ -217,7 +217,7 @@ fun UtxoRow(utxo: WalletState.Utxo, progress: Pair?) { ) } Text( - text = utxo.outPoint.txid.toHex(), + text = utxo.outPoint.txid.toString(), modifier = Modifier.weight(1f), maxLines = 1, overflow = TextOverflow.Ellipsis, diff --git a/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/utils/LegacyMigrationHelper.kt b/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/utils/LegacyMigrationHelper.kt index 0c7de83b6..6aede954a 100644 --- a/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/utils/LegacyMigrationHelper.kt +++ b/phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/utils/LegacyMigrationHelper.kt @@ -21,6 +21,7 @@ import com.google.common.net.HostAndPort import fr.acinq.bitcoin.ByteVector32 import fr.acinq.bitcoin.PublicKey import fr.acinq.bitcoin.Satoshi +import fr.acinq.bitcoin.TxId import fr.acinq.bitcoin.byteVector32 import fr.acinq.eclair.db.IncomingPaymentStatus import fr.acinq.eclair.db.OutgoingPaymentStatus @@ -167,7 +168,7 @@ object LegacyMigrationHelper { try { val parentId = it.key val paymentMeta = legacyMetaRepository.get(parentId.toString()) - val payment = modernizeLegacyOutgoingPayment(business.chain.chainHash, parentId, it.value, paymentMeta) + val payment = modernizeLegacyOutgoingPayment(business.chain, parentId, it.value, paymentMeta) // save payment to database newPaymentsDb.addOutgoingPayment(payment) @@ -300,7 +301,7 @@ object LegacyMigrationHelper { serviceFee = payToOpenMeta?.fee_sat?.sat?.toMilliSatoshi() ?: 0.msat, miningFee = 0.sat, channelId = ByteVector32.Zeroes, - txId = ByteVector32.Zeroes, + txId = TxId(ByteVector32.Zeroes), confirmedAt = status.receivedAt(), lockedAt = status.receivedAt() ) @@ -325,7 +326,7 @@ object LegacyMigrationHelper { JavaConversions.asJavaCollection(payments).toList().groupBy { UUID.fromString(it.parentId().toString()) } fun modernizeLegacyOutgoingPayment( - chainHash: ByteVector32, + chain: NodeParams.Chain, parentId: UUID, listOfParts: List, paymentMeta: PaymentMeta?, @@ -344,7 +345,7 @@ object LegacyMigrationHelper { address = paymentMeta?.closing_main_output_script ?: "", isSentToDefaultAddress = paymentMeta?.closing_type != ClosingType.Mutual.code, miningFees = 0.sat, - txId = paymentMeta?.getSpendingTxs()?.firstOrNull()?.let { ByteVector32.fromValidHex(it) } ?: ByteVector32.Zeroes, + txId = TxId(paymentMeta?.getSpendingTxs()?.firstOrNull()?.let { ByteVector32.fromValidHex(it) } ?: ByteVector32.Zeroes), createdAt = head.createdAt(), confirmedAt = closedAt, lockedAt = closedAt, @@ -367,7 +368,7 @@ object LegacyMigrationHelper { LightningOutgoingPayment.Details.SwapOut( address = paymentMeta.swap_out_address ?: "", paymentRequest = paymentRequest ?: PaymentRequest.create( - chainHash = chainHash, + chainHash = chain.chainHash, amount = head.recipientAmount().toLong().msat, paymentHash = head.paymentHash().bytes().toArray().byteVector32(), privateKey = Lightning.randomKey(),