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-9111 AND-9112 add getblock nownodes apis #862

Merged
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 @@ -7,17 +7,23 @@ import com.tangem.blockchain.common.NowNodeCredentials
import com.tangem.blockchain.common.network.providers.NetworkProvidersBuilder
import com.tangem.blockchain.common.network.providers.ProviderType
import com.tangem.blockchain.extensions.letNotBlank
import com.tangem.blockchain.network.blockbook.BlockBookNetworkProviderFactory
import com.tangem.blockchain.network.blockchair.BlockchairNetworkProviderFactory

internal class BitcoinCashProvidersBuilder(
override val providerTypes: List<ProviderType>,
private val config: BlockchainSdkConfig,
) : NetworkProvidersBuilder<BitcoinNetworkProvider>() {

private val blockBookProviderFactory by lazy { BlockBookNetworkProviderFactory(config) }

override fun createProviders(blockchain: Blockchain): List<BitcoinNetworkProvider> {
return providerTypes.flatMap {
when (it) {
ProviderType.NowNodes -> getBitcoinCashNowNodesNetworkProvider().let(::listOfNotNull)
ProviderType.GetBlock -> {
blockBookProviderFactory.createGetBlockProvider(blockchain).let(::listOfNotNull)
}
ProviderType.BitcoinLike.Blockchair -> {
BlockchairNetworkProviderFactory(config).createProviders(blockchain)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ internal class CardanoProvidersBuilder(
return providerTypes.mapNotNull {
when (it) {
ProviderType.GetBlock -> createGetBlockNetworkProvider()
ProviderType.NowNodes -> createNowNodesNetworkProvider()
ProviderType.Cardano.Adalite -> AdaliteNetworkProvider(API_ADALITE)
ProviderType.Cardano.Rosetta -> RosettaNetworkProvider(RosettaNetwork.Tangem)
else -> null
Expand All @@ -32,4 +33,10 @@ internal class CardanoProvidersBuilder(
RosettaNetworkProvider(RosettaNetwork.Getblock(it))
}
}

private fun createNowNodesNetworkProvider(): CardanoNetworkProvider? {
return config.nowNodeCredentials?.apiKey.letNotBlank {
RosettaNetworkProvider(RosettaNetwork.Nownodes(it))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ sealed class RosettaNetwork(val url: String) {

data class Getblock(val accessToken: String) : RosettaNetwork(url = "https://go.getblock.io/$accessToken/")

data class Nownodes(val apiKey: String) : RosettaNetwork(url = "https://ada.nownodes.io/$apiKey/")

object Tangem : RosettaNetwork(url = "https://ada.tangem.com/")
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ internal class DashProvidersBuilder(
ProviderType.NowNodes -> {
blockBookNetworkProviderFactory.createNowNodesProvider(blockchain).let(::listOfNotNull)
}
ProviderType.GetBlock -> {
blockBookNetworkProviderFactory.createGetBlockProvider(blockchain).let(::listOfNotNull)
}
ProviderType.BitcoinLike.Blockcypher -> {
blockcypherNetworkProviderFactory.create(blockchain).let(::listOfNotNull)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ internal class ArbitrumProvidersBuilder(
ProviderType.EthereumLike.Infura -> {
ethereumProviderFactory.getInfuraProvider(baseUrl = "https://arbitrum-mainnet.infura.io/v3/")
}
ProviderType.GetBlock -> {
ethereumProviderFactory.getGetBlockProvider { arbitrum?.jsonRpc }
}
else -> null
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
package com.tangem.blockchain.blockchains.ethereum.providers

import com.tangem.blockchain.blockchains.ethereum.EthereumLikeProvidersBuilder
import com.tangem.blockchain.blockchains.ethereum.network.EthereumJsonRpcProvider
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.BlockchainSdkConfig
import com.tangem.blockchain.common.createWithPostfixIfContained
import com.tangem.blockchain.common.network.providers.OnlyPublicProvidersBuilder
import com.tangem.blockchain.common.network.providers.ProviderType

internal class AuroraProvidersBuilder(
override val providerTypes: List<ProviderType>,
) : OnlyPublicProvidersBuilder<EthereumJsonRpcProvider>(
providerTypes = providerTypes,
testnetProviders = listOf("https://testnet.aurora.dev/"),
) {
override val config: BlockchainSdkConfig,
) : EthereumLikeProvidersBuilder(config) {

override fun createProvider(url: String, blockchain: Blockchain): EthereumJsonRpcProvider {
override fun createProviders(blockchain: Blockchain): List<EthereumJsonRpcProvider> {
return providerTypes.mapNotNull {
when (it) {
is ProviderType.Public -> createPublicProvider(url = it.url)
ProviderType.NowNodes -> {
ethereumProviderFactory.getNowNodesProvider(baseUrl = "https://aurora.nownodes.io/")
}
else -> null
}
}
}

override fun createTestnetProviders(blockchain: Blockchain): List<EthereumJsonRpcProvider> {
return listOf(createPublicProvider("https://testnet.aurora.dev/"))
}

private fun createPublicProvider(url: String): EthereumJsonRpcProvider {
return createWithPostfixIfContained(
baseUrl = url,
postfixUrl = POSTFIX_URL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ internal class EthereumClassicProvidersBuilder(
when (it) {
is ProviderType.Public -> EthereumJsonRpcProvider(baseUrl = it.url)
ProviderType.GetBlock -> ethereumProviderFactory.getGetBlockProvider { etc?.jsonRpc }
ProviderType.NowNodes -> ethereumProviderFactory.getNowNodesProvider("https://etc.nownodes.io/")
else -> null
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
package com.tangem.blockchain.blockchains.ethereum.providers

import com.tangem.blockchain.blockchains.ethereum.EthereumLikeProvidersBuilder
import com.tangem.blockchain.blockchains.ethereum.network.EthereumJsonRpcProvider
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.BlockchainSdkConfig
import com.tangem.blockchain.common.createWithPostfixIfContained
import com.tangem.blockchain.common.network.providers.OnlyPublicProvidersBuilder
import com.tangem.blockchain.common.network.providers.ProviderType
import com.tangem.blockchain.extensions.letNotBlank

internal class FlareProvidersBuilder(
override val providerTypes: List<ProviderType>,
) : OnlyPublicProvidersBuilder<EthereumJsonRpcProvider>(
providerTypes = providerTypes,
testnetProviders = listOf("https://coston2-api.flare.network/ext/C/rpc/"),
) {
override val config: BlockchainSdkConfig,
) : EthereumLikeProvidersBuilder(config) {

override fun createProvider(url: String, blockchain: Blockchain): EthereumJsonRpcProvider {
override fun createProviders(blockchain: Blockchain): List<EthereumJsonRpcProvider> {
return providerTypes.mapNotNull {
when (it) {
is ProviderType.Public -> createPublickProvider(url = it.url)
ProviderType.NowNodes -> config.nowNodeCredentials?.apiKey.letNotBlank { nowNodesApiKey ->
EthereumJsonRpcProvider(baseUrl = "https://flr.nownodes.io/$nowNodesApiKey/ext/bc/C/rpc")
}
else -> null
}
}
}

override fun createTestnetProviders(blockchain: Blockchain): List<EthereumJsonRpcProvider> {
return listOf(createPublickProvider("https://coston2-api.flare.network/ext/C/rpc/"))
}

private fun createPublickProvider(url: String): EthereumJsonRpcProvider {
return createWithPostfixIfContained(
baseUrl = url,
postfixUrl = POSTFIX_URLS.toTypedArray(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
package com.tangem.blockchain.blockchains.ethereum.providers

import com.tangem.blockchain.blockchains.ethereum.EthereumLikeProvidersBuilder
import com.tangem.blockchain.blockchains.ethereum.network.EthereumJsonRpcProvider
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.network.providers.OnlyPublicProvidersBuilder
import com.tangem.blockchain.common.BlockchainSdkConfig
import com.tangem.blockchain.common.network.providers.ProviderType

internal class KavaProvidersBuilder(
override val providerTypes: List<ProviderType>,
) : OnlyPublicProvidersBuilder<EthereumJsonRpcProvider>(
providerTypes = providerTypes,
testnetProviders = listOf("https://evm.testnet.kava.io/"),
) {
override fun createProvider(url: String, blockchain: Blockchain) = EthereumJsonRpcProvider(url)
override val config: BlockchainSdkConfig,
) : EthereumLikeProvidersBuilder(config) {

override fun createProviders(blockchain: Blockchain): List<EthereumJsonRpcProvider> {
return providerTypes.mapNotNull {
when (it) {
is ProviderType.Public -> EthereumJsonRpcProvider(baseUrl = it.url)
ProviderType.NowNodes -> ethereumProviderFactory.getNowNodesProvider("https://kava-evm.nownodes.io/")
else -> null
}
}
}

override fun createTestnetProviders(blockchain: Blockchain): List<EthereumJsonRpcProvider> {
return listOf(EthereumJsonRpcProvider("https://evm.testnet.kava.io/"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ internal class MoonbeamProvidersBuilder(
ProviderType.NowNodes -> {
ethereumProviderFactory.getNowNodesProvider(baseUrl = "https://moonbeam.nownodes.io/")
}
ProviderType.GetBlock -> {
ethereumProviderFactory.getGetBlockProvider { moonbeam?.jsonRpc }
}
else -> null
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
package com.tangem.blockchain.blockchains.ethereum.providers

import com.tangem.blockchain.blockchains.ethereum.EthereumLikeProvidersBuilder
import com.tangem.blockchain.blockchains.ethereum.network.EthereumJsonRpcProvider
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.network.providers.OnlyPublicProvidersBuilder
import com.tangem.blockchain.common.BlockchainSdkConfig
import com.tangem.blockchain.common.network.providers.ProviderType

internal class PulseChainProvidersBuilder(
override val providerTypes: List<ProviderType>,
) : OnlyPublicProvidersBuilder<EthereumJsonRpcProvider>(
providerTypes = providerTypes,
testnetProviders = listOf(
"https://rpc.v4.testnet.pulsechain.com/",
"https://pulsechain-testnet.publicnode.com/",
"https://rpc-testnet-pulsechain.g4mm4.io/",
),
) {
override val config: BlockchainSdkConfig,
) : EthereumLikeProvidersBuilder(config) {

override fun createProvider(url: String, blockchain: Blockchain) = EthereumJsonRpcProvider(url)
override fun createProviders(blockchain: Blockchain): List<EthereumJsonRpcProvider> {
return providerTypes.mapNotNull {
when (it) {
is ProviderType.Public -> EthereumJsonRpcProvider(baseUrl = it.url)
ProviderType.NowNodes -> ethereumProviderFactory.getNowNodesProvider("https://pulse.nownodes.io/")
else -> null
}
}
}

override fun createTestnetProviders(blockchain: Blockchain): List<EthereumJsonRpcProvider> {
return listOf(
EthereumJsonRpcProvider("https://rpc.v4.testnet.pulsechain.com/"),
EthereumJsonRpcProvider("https://pulsechain-testnet.publicnode.com/"),
EthereumJsonRpcProvider("https://rpc-testnet-pulsechain.g4mm4.io/"),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ internal class ShibariumProvidersBuilder(
ProviderType.NowNodes -> {
ethereumProviderFactory.getNowNodesProvider(baseUrl = "https://shib.nownodes.io/")
}
ProviderType.GetBlock -> {
ethereumProviderFactory.getGetBlockProvider { shibarium?.jsonRpc }
}
else -> null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ internal class KaspaProvidersBuilder(
.mapNotNull { type ->
when (type) {
is ProviderType.Public -> type.url
is ProviderType.NowNodes -> config.nowNodeCredentials?.apiKey.letNotBlank { nowNodesApiKey ->
"https://kas.nownodes.io/$nowNodesApiKey/"
}
ProviderType.Kaspa.SecondaryAPI -> config.kaspaSecondaryApiUrl?.letNotBlank { it }
else -> null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ internal class OptimismProvidersBuilder(
ProviderType.NowNodes -> {
ethereumProviderFactory.getNowNodesProvider(baseUrl = "https://optimism.nownodes.io/")
}
ProviderType.GetBlock -> {
ethereumProviderFactory.getGetBlockProvider { optimism?.jsonRpc }
}
else -> null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,40 @@ package com.tangem.blockchain.blockchains.polkadot.providers
import com.tangem.blockchain.blockchains.polkadot.network.PolkadotCombinedProvider
import com.tangem.blockchain.blockchains.polkadot.network.PolkadotNetworkProvider
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.network.providers.OnlyPublicProvidersBuilder
import com.tangem.blockchain.common.BlockchainSdkConfig
import com.tangem.blockchain.common.network.providers.NetworkProvidersBuilder
import com.tangem.blockchain.common.network.providers.ProviderType
import com.tangem.blockchain.extensions.letNotBlank

internal class KusamaProvidersBuilder(
override val providerTypes: List<ProviderType>,
) : OnlyPublicProvidersBuilder<PolkadotNetworkProvider>(providerTypes) {
private val config: BlockchainSdkConfig,
) : NetworkProvidersBuilder<PolkadotNetworkProvider>() {

override fun createProvider(url: String, blockchain: Blockchain): PolkadotNetworkProvider {
override fun createProviders(blockchain: Blockchain): List<PolkadotNetworkProvider> {
return providerTypes.mapNotNull {
when (it) {
is ProviderType.GetBlock -> createGetBlockProvider(blockchain)
is ProviderType.NowNodes -> createNowNodesProvider(blockchain)
is ProviderType.Public -> createPublicProvider(it.url, blockchain)
else -> null
}
}
}

private fun createPublicProvider(url: String, blockchain: Blockchain): PolkadotNetworkProvider {
return PolkadotCombinedProvider(baseUrl = url, blockchain = blockchain)
}

private fun createGetBlockProvider(blockchain: Blockchain): PolkadotNetworkProvider? {
return config.getBlockCredentials?.kusama?.jsonRpc.letNotBlank { jsonRpcToken ->
PolkadotCombinedProvider(baseUrl = "https://go.getblock.io/$jsonRpcToken/", blockchain = blockchain)
}
}

private fun createNowNodesProvider(blockchain: Blockchain): PolkadotNetworkProvider? {
return config.nowNodeCredentials?.apiKey.letNotBlank {
PolkadotCombinedProvider(baseUrl = "https://ksm.nownodes.io/$it/", blockchain = blockchain)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,37 @@ package com.tangem.blockchain.blockchains.polkadot.providers
import com.tangem.blockchain.blockchains.polkadot.network.PolkadotCombinedProvider
import com.tangem.blockchain.blockchains.polkadot.network.PolkadotNetworkProvider
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.network.providers.OnlyPublicProvidersBuilder
import com.tangem.blockchain.common.BlockchainSdkConfig
import com.tangem.blockchain.common.network.providers.NetworkProvidersBuilder
import com.tangem.blockchain.common.network.providers.ProviderType
import com.tangem.blockchain.extensions.letNotBlank

internal class PolkadotProvidersBuilder(
override val providerTypes: List<ProviderType>,
) : OnlyPublicProvidersBuilder<PolkadotNetworkProvider>(
providerTypes = providerTypes,
testnetProviders = listOf("https://westend-rpc.polkadot.io/"),
) {
private val config: BlockchainSdkConfig,
) : NetworkProvidersBuilder<PolkadotNetworkProvider>() {

override fun createProvider(url: String, blockchain: Blockchain): PolkadotNetworkProvider {
override fun createProviders(blockchain: Blockchain): List<PolkadotNetworkProvider> {
return providerTypes.mapNotNull {
when (it) {
is ProviderType.GetBlock -> createGetBlockProvider(blockchain)
is ProviderType.Public -> createPublicProvider(it.url, blockchain)
else -> null
}
}
}

override fun createTestnetProviders(blockchain: Blockchain): List<PolkadotNetworkProvider> {
return listOf(createPublicProvider("https://westend-rpc.polkadot.io/", blockchain))
}

private fun createPublicProvider(url: String, blockchain: Blockchain): PolkadotNetworkProvider {
return PolkadotCombinedProvider(baseUrl = url, blockchain = blockchain)
}

private fun createGetBlockProvider(blockchain: Blockchain): PolkadotNetworkProvider? {
return config.getBlockCredentials?.polkadot?.jsonRpc.letNotBlank { jsonRpcToken ->
PolkadotCombinedProvider(baseUrl = "https://go.getblock.io/$jsonRpcToken/", blockchain = blockchain)
}
}
}
Loading
Loading