From 2ae7de5e67af02059e07751f31652e895dcce31b Mon Sep 17 00:00:00 2001 From: Doston Kamalov Date: Wed, 8 Nov 2023 12:04:14 +0500 Subject: [PATCH] AND-5051 Added support for transaction history in ETH like blockchains --- .../EthereumTransactionHistoryProviderExt.kt | 37 +++++++++++++++++++ .../blockchains/ton/TonWalletManager.kt | 1 + .../impl/EthereumLikeWalletManagerAssembly.kt | 6 ++- .../impl/EthereumWalletManagerAssembly.kt | 24 +----------- .../blockbook/config/BlockBookConfig.kt | 11 +++++- 5 files changed, 54 insertions(+), 25 deletions(-) create mode 100644 blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/EthereumTransactionHistoryProviderExt.kt diff --git a/blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/EthereumTransactionHistoryProviderExt.kt b/blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/EthereumTransactionHistoryProviderExt.kt new file mode 100644 index 000000000..597c53ad7 --- /dev/null +++ b/blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/EthereumTransactionHistoryProviderExt.kt @@ -0,0 +1,37 @@ +package com.tangem.blockchain.blockchains.ethereum + +import com.tangem.blockchain.common.Blockchain +import com.tangem.blockchain.common.BlockchainSdkConfig +import com.tangem.blockchain.common.txhistory.DefaultTransactionHistoryProvider +import com.tangem.blockchain.common.txhistory.TransactionHistoryProvider +import com.tangem.blockchain.network.blockbook.config.BlockBookConfig +import com.tangem.blockchain.network.blockbook.network.BlockBookApi + +internal fun Blockchain.getEthereumTransactionHistoryProvider( + config: BlockchainSdkConfig, +): TransactionHistoryProvider { + return when (this) { + Blockchain.Ethereum, + Blockchain.EthereumTestnet, + Blockchain.Arbitrum, + Blockchain.Avalanche, + Blockchain.BSC, + Blockchain.Polygon, + Blockchain.EthereumPow, + Blockchain.Kava, + -> { + if (config.nowNodeCredentials != null && config.nowNodeCredentials.apiKey.isNotBlank()) { + EthereumTransactionHistoryProvider( + blockchain = this, + BlockBookApi( + config = BlockBookConfig.NowNodes(nowNodesCredentials = config.nowNodeCredentials), + blockchain = this, + ) + ) + } else { + DefaultTransactionHistoryProvider + } + } + else -> DefaultTransactionHistoryProvider + } +} diff --git a/blockchain/src/main/java/com/tangem/blockchain/blockchains/ton/TonWalletManager.kt b/blockchain/src/main/java/com/tangem/blockchain/blockchains/ton/TonWalletManager.kt index c2a214fec..1391897be 100644 --- a/blockchain/src/main/java/com/tangem/blockchain/blockchains/ton/TonWalletManager.kt +++ b/blockchain/src/main/java/com/tangem/blockchain/blockchains/ton/TonWalletManager.kt @@ -42,6 +42,7 @@ class TonWalletManager( is Result.Failure -> updateError(walletInfoResult.error) is Result.Success -> updateWallet(walletInfoResult.data) } + wallet.blockchain.getSupportedCurves() } override suspend fun send(transactionData: TransactionData, signer: TransactionSigner): SimpleResult { diff --git a/blockchain/src/main/java/com/tangem/blockchain/common/assembly/impl/EthereumLikeWalletManagerAssembly.kt b/blockchain/src/main/java/com/tangem/blockchain/common/assembly/impl/EthereumLikeWalletManagerAssembly.kt index 57df07ba4..718e025f5 100644 --- a/blockchain/src/main/java/com/tangem/blockchain/common/assembly/impl/EthereumLikeWalletManagerAssembly.kt +++ b/blockchain/src/main/java/com/tangem/blockchain/common/assembly/impl/EthereumLikeWalletManagerAssembly.kt @@ -3,6 +3,7 @@ package com.tangem.blockchain.common.assembly.impl import com.tangem.blockchain.blockchains.ethereum.EthereumTransactionBuilder import com.tangem.blockchain.blockchains.ethereum.EthereumWalletManager import com.tangem.blockchain.blockchains.ethereum.getEthereumJsonRpcProviders +import com.tangem.blockchain.blockchains.ethereum.getEthereumTransactionHistoryProvider import com.tangem.blockchain.blockchains.ethereum.network.EthereumNetworkService import com.tangem.blockchain.common.assembly.WalletManagerAssembly import com.tangem.blockchain.common.assembly.WalletManagerAssemblyInput @@ -19,8 +20,9 @@ internal object EthereumLikeWalletManagerAssembly : WalletManagerAssembly() { @@ -30,23 +26,7 @@ internal object EthereumWalletManagerAssembly : WalletManagerAssembly { - if (input.config.nowNodeCredentials != null && input.config.nowNodeCredentials.apiKey.isNotBlank()) { - EthereumTransactionHistoryProvider( - blockchain = blockchain, - blockBookApi = BlockBookApi( - config = BlockBookConfig.NowNodes(nowNodesCredentials = input.config.nowNodeCredentials), - blockchain = blockchain, - ) - ) - } else { - DefaultTransactionHistoryProvider - } - } - - else -> DefaultTransactionHistoryProvider - } + transactionHistoryProvider = blockchain.getEthereumTransactionHistoryProvider(input.config) ) } } 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 b061e8871..a9e76c8d7 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 @@ -31,7 +31,16 @@ sealed class BlockBookConfig(val credentials: BlockBookCredentials) { "https://${prefix}book${testnetSuffix}.${baseHost}" } - Blockchain.Ethereum -> "https://${prefix}-blockbook.${baseHost}" + Blockchain.Arbitrum -> "https://arb-blockbook.$baseHost" + Blockchain.BSC -> "https://bsc-blockbook.$baseHost" + Blockchain.EthereumTestnet -> "https://${prefix}book-goerli.${baseHost}" + Blockchain.Polygon -> "https://${prefix}book.$baseHost" + Blockchain.Kava -> "https://kava-tendermint.$baseHost" + Blockchain.Ethereum, + Blockchain.Avalanche, + Blockchain.EthereumPow, + -> "https://${prefix}-blockbook.${baseHost}" + else -> error("BlockBookConfig.NowNodes don't support blockchain $blockchain") } }