Skip to content

Commit

Permalink
AND-5051 Added support for transaction history in ETH like blockchains
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoggam1 committed Nov 8, 2023
1 parent d1fa70d commit 2ae7de5
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,8 +20,9 @@ internal object EthereumLikeWalletManagerAssembly : WalletManagerAssembly<Ethere
),
networkProvider = EthereumNetworkService(
jsonRpcProviders = blockchain.getEthereumJsonRpcProviders(input.config),
)
),
transactionHistoryProvider = blockchain.getEthereumTransactionHistoryProvider(input.config)
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package com.tangem.blockchain.common.assembly.impl

import com.tangem.blockchain.blockchains.ethereum.EthereumTransactionBuilder
import com.tangem.blockchain.blockchains.ethereum.EthereumTransactionHistoryProvider
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.Blockchain
import com.tangem.blockchain.common.assembly.WalletManagerAssembly
import com.tangem.blockchain.common.assembly.WalletManagerAssemblyInput
import com.tangem.blockchain.common.txhistory.DefaultTransactionHistoryProvider
import com.tangem.blockchain.network.blockbook.config.BlockBookConfig
import com.tangem.blockchain.network.blockbook.network.BlockBookApi
import com.tangem.blockchain.network.blockcypher.BlockcypherNetworkProvider

internal object EthereumWalletManagerAssembly : WalletManagerAssembly<EthereumWalletManager>() {
Expand All @@ -30,23 +26,7 @@ internal object EthereumWalletManagerAssembly : WalletManagerAssembly<EthereumWa
tokens = input.config.blockcypherTokens
),
),
transactionHistoryProvider = when (blockchain) {
Blockchain.Ethereum -> {
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)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down

0 comments on commit 2ae7de5

Please sign in to comment.