fix(android): 进一步修复交易记录同步问题
- 将扫描区块数从 50000 增加到 200000(确保覆盖足够长时间) - 统一地址格式为 lowercase,避免大小写不匹配导致记录无法同步 - 添加详细的交易哈希日志用于调试 - 修复 saveTransactionRecord 和 syncNativeTransactionHistory 中的地址格式问题 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
a516006117
commit
6e03c1c798
|
|
@ -2992,11 +2992,15 @@ data class ParticipantStatusInfo(
|
|||
direction: String = "SENT"
|
||||
): Long {
|
||||
return withContext(Dispatchers.IO) {
|
||||
// 统一转换为 lowercase 确保地址匹配
|
||||
val normalizedFrom = fromAddress.lowercase()
|
||||
val normalizedTo = toAddress.lowercase()
|
||||
|
||||
android.util.Log.d("TssRepository", "[TX-RECORD] Saving transaction record: txHash=${txHash.take(20)}...")
|
||||
val entity = TransactionRecordEntity(
|
||||
shareId = shareId,
|
||||
fromAddress = fromAddress,
|
||||
toAddress = toAddress,
|
||||
fromAddress = normalizedFrom,
|
||||
toAddress = normalizedTo,
|
||||
amount = amount,
|
||||
tokenType = tokenType.name,
|
||||
txHash = txHash,
|
||||
|
|
@ -3175,14 +3179,16 @@ data class ParticipantStatusInfo(
|
|||
val currentBlockHex = getCurrentBlockNumber(client, rpcUrl)
|
||||
val currentBlock = currentBlockHex?.removePrefix("0x")?.toLongOrNull(16) ?: 0L
|
||||
|
||||
// 只查询最近 50000 个区块的历史(约 1-2 个月)
|
||||
val fromBlock = if (currentBlock > 50000) {
|
||||
"0x${(currentBlock - 50000).toString(16)}"
|
||||
// 查询最近 200000 个区块的历史(Kava 出块快,确保覆盖足够长的时间)
|
||||
val scanBlockCount = 200000L
|
||||
val fromBlock = if (currentBlock > scanBlockCount) {
|
||||
"0x${(currentBlock - scanBlockCount).toString(16)}"
|
||||
} else {
|
||||
"0x0"
|
||||
}
|
||||
|
||||
android.util.Log.d("TssRepository", "[SYNC-ERC20] Scanning from block $fromBlock to latest (current: $currentBlockHex)")
|
||||
android.util.Log.d("TssRepository", "[SYNC-ERC20] Current block: $currentBlock ($currentBlockHex)")
|
||||
android.util.Log.d("TssRepository", "[SYNC-ERC20] Scanning from block $fromBlock to latest (${scanBlockCount} blocks)")
|
||||
|
||||
// Transfer event signature: keccak256("Transfer(address,address,uint256)")
|
||||
val transferTopic = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
|
||||
|
|
@ -3298,12 +3304,14 @@ data class ParticipantStatusInfo(
|
|||
|
||||
// 解析 from 和 to 地址 (topics[1] 和 topics[2])
|
||||
val fromAddress = if (topics.size() > 1) {
|
||||
"0x" + topics[1].asString.removePrefix("0x").takeLast(40)
|
||||
"0x" + topics[1].asString.removePrefix("0x").takeLast(40).lowercase()
|
||||
} else continue
|
||||
val toAddress = if (topics.size() > 2) {
|
||||
"0x" + topics[2].asString.removePrefix("0x").takeLast(40)
|
||||
"0x" + topics[2].asString.removePrefix("0x").takeLast(40).lowercase()
|
||||
} else continue
|
||||
|
||||
android.util.Log.d("TssRepository", "[SYNC-ERC20] Processing tx $txHash: $fromAddress -> $toAddress")
|
||||
|
||||
// 解析金额 (data 字段)
|
||||
val valueHex = data.removePrefix("0x")
|
||||
val valueBig = if (valueHex.isNotEmpty()) {
|
||||
|
|
@ -3432,13 +3440,17 @@ data class ParticipantStatusInfo(
|
|||
.toPlainString()
|
||||
} else ""
|
||||
|
||||
// 统一转换为 lowercase
|
||||
val normalizedFrom = fromAddr.lowercase()
|
||||
val normalizedTo = toAddr.lowercase()
|
||||
|
||||
// 判断方向
|
||||
val direction = if (fromAddr.equals(address, ignoreCase = true)) "SENT" else "RECEIVED"
|
||||
val direction = if (normalizedFrom == address.lowercase()) "SENT" else "RECEIVED"
|
||||
|
||||
val entity = TransactionRecordEntity(
|
||||
shareId = shareId,
|
||||
fromAddress = fromAddr,
|
||||
toAddress = toAddr,
|
||||
fromAddress = normalizedFrom,
|
||||
toAddress = normalizedTo,
|
||||
amount = valueKava,
|
||||
tokenType = TokenType.KAVA.name,
|
||||
txHash = txHash,
|
||||
|
|
|
|||
Loading…
Reference in New Issue