Skip to content

Commit

Permalink
(android) Use TxId whenever possible
Browse files Browse the repository at this point in the history
See a1d972e6 for details.
  • Loading branch information
dpad85 committed Nov 30, 2023
1 parent a723176 commit 3939ab1
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -576,15 +577,15 @@ private fun EditPaymentDetails(

@Composable
private fun ConfirmationView(
txId: ByteVector32,
txId: TxId,
channelId: ByteVector32,
isConfirmed: Boolean,
canBeBumped: Boolean,
onCpfpSuccess: () -> Unit,
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) }
Expand All @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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) }
)
}

Expand All @@ -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) }
)

}
Expand All @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private fun CommitmentDetailsView(
val btcUnit = LocalBitcoinUnit.current
val paymentsManager = business.paymentsManager
val linkedPayments by produceState<List<WalletPayment>>(initialValue = emptyList()) {
value = paymentsManager.listPaymentsForTxId(ByteVector32.fromValidHex(commitment.fundingTxId))
value = paymentsManager.listPaymentsForTxId(commitment.fundingTxId)
}

SettingWithDecoration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private fun OnchainBalanceView(
@Composable
fun UtxoRow(utxo: WalletState.Utxo, progress: Pair<Int?, Int>?) {
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)) {
Expand All @@ -217,7 +217,7 @@ fun UtxoRow(utxo: WalletState.Utxo, progress: Pair<Int?, Int>?) {
)
}
Text(
text = utxo.outPoint.txid.toHex(),
text = utxo.outPoint.txid.toString(),
modifier = Modifier.weight(1f),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
)
Expand All @@ -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<fr.acinq.eclair.db.OutgoingPayment>,
paymentMeta: PaymentMeta?,
Expand All @@ -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,
Expand All @@ -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(),
Expand Down

0 comments on commit 3939ab1

Please sign in to comment.