From 07fab464be8f3277cc9ff5edf04110e089412cf0 Mon Sep 17 00:00:00 2001 From: Doston Kamalov Date: Tue, 5 Dec 2023 12:20:25 +0500 Subject: [PATCH] AND-5378 Enabled transaction history for ETC --- .../ethereum/EthereumAddressService.kt | 2 +- .../EthereumTransactionHistoryProvider.kt | 17 ++++++++++++++--- .../txhistory/TransactionHistoryProviderExt.kt | 1 + .../network/blockbook/config/BlockBookConfig.kt | 1 + 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/EthereumAddressService.kt b/blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/EthereumAddressService.kt index b6e69da05..5d1fba4b3 100644 --- a/blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/EthereumAddressService.kt +++ b/blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/EthereumAddressService.kt @@ -16,4 +16,4 @@ class EthereumAddressService : AddressService() { ).toAddress().withERC55Checksum().hex override fun validate(address: String): Boolean = Address(address).hasValidERC55ChecksumOrNoChecksum() -} \ No newline at end of file +} diff --git a/blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/EthereumTransactionHistoryProvider.kt b/blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/EthereumTransactionHistoryProvider.kt index b4bfa6010..44dd6450d 100644 --- a/blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/EthereumTransactionHistoryProvider.kt +++ b/blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/EthereumTransactionHistoryProvider.kt @@ -17,6 +17,8 @@ import kotlinx.coroutines.withContext import java.math.BigDecimal import java.util.concurrent.TimeUnit +private const val ETHEREUM_METHOD_ID_LENGTH = 8 + internal class EthereumTransactionHistoryProvider( private val blockchain: Blockchain, private val blockBookApi: BlockBookApi, @@ -121,9 +123,13 @@ internal class EthereumTransactionHistoryProvider( } private fun extractType(tx: GetAddressResponse.Transaction): TransactionHistoryItem.TransactionType { - val methodId = tx.ethereumSpecific?.parsedData?.methodId.guard { - return TransactionHistoryItem.TransactionType.Transfer - } + val ethereumSpecific = tx.ethereumSpecific + + // Retrieve the methodId from a specific field in the response or parse it from ethereumSpecific. If unable to + // extract the methodId from either, return the default transaction type. + val methodId = ethereumSpecific?.parsedData?.methodId + ?: methodIdFromRawData(ethereumSpecific?.data) + ?: return TransactionHistoryItem.TransactionType.Transfer // MethodId is empty for the coin transfers if (methodId.isEmpty()) return TransactionHistoryItem.TransactionType.Transfer @@ -131,6 +137,11 @@ internal class EthereumTransactionHistoryProvider( return TransactionHistoryItem.TransactionType.ContractMethod(id = methodId) } + private fun methodIdFromRawData(rawData: String?): String? { + val methodId = rawData?.removePrefix("0x")?.take(ETHEREUM_METHOD_ID_LENGTH) + return if (methodId?.length == ETHEREUM_METHOD_ID_LENGTH) methodId else null + } + private fun isOutgoing( walletAddress: String, transaction: GetAddressResponse.Transaction, diff --git a/blockchain/src/main/java/com/tangem/blockchain/common/txhistory/TransactionHistoryProviderExt.kt b/blockchain/src/main/java/com/tangem/blockchain/common/txhistory/TransactionHistoryProviderExt.kt index d9d6983eb..153decbaf 100644 --- a/blockchain/src/main/java/com/tangem/blockchain/common/txhistory/TransactionHistoryProviderExt.kt +++ b/blockchain/src/main/java/com/tangem/blockchain/common/txhistory/TransactionHistoryProviderExt.kt @@ -29,6 +29,7 @@ internal fun Blockchain.getTransactionHistoryProvider( Blockchain.Ethereum, Blockchain.EthereumTestnet, + Blockchain.EthereumClassic, // Blockchain.Arbitrum, Blockchain.Avalanche, Blockchain.BSC, diff --git a/blockchain/src/main/java/com/tangem/blockchain/network/blockbook/config/BlockBookConfig.kt b/blockchain/src/main/java/com/tangem/blockchain/network/blockbook/config/BlockBookConfig.kt index 870e6f941..749346c46 100644 --- a/blockchain/src/main/java/com/tangem/blockchain/network/blockbook/config/BlockBookConfig.kt +++ b/blockchain/src/main/java/com/tangem/blockchain/network/blockbook/config/BlockBookConfig.kt @@ -36,6 +36,7 @@ sealed class BlockBookConfig(val credentials: BlockBookCredentials?) { Blockchain.Polygon -> "https://${prefix}book.$baseHost" Blockchain.Kava -> "https://kava-tendermint.$baseHost" Blockchain.Ethereum, + Blockchain.EthereumClassic, Blockchain.Avalanche, Blockchain.EthereumPow, Blockchain.Tron,