Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AND-5378 Enabled transaction history for ETC #394

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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