Skip to content

Commit

Permalink
Merge pull request #394 from tangem/feature/AND-5378_enable_tx_histor…
Browse files Browse the repository at this point in the history
…y_for_etc

AND-5378 Enabled transaction history for ETC
  • Loading branch information
Yoggam1 authored Dec 5, 2023
2 parents fc06d97 + 07fab46 commit 85d5631
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ class EthereumAddressService : AddressService() {
).toAddress().withERC55Checksum().hex

override fun validate(address: String): Boolean = Address(address).hasValidERC55ChecksumOrNoChecksum()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -121,16 +123,25 @@ 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

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ internal fun Blockchain.getTransactionHistoryProvider(

Blockchain.Ethereum,
Blockchain.EthereumTestnet,
Blockchain.EthereumClassic,
// Blockchain.Arbitrum,
Blockchain.Avalanche,
Blockchain.BSC,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 85d5631

Please sign in to comment.