-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #852 from tangem/feature/AND-8828_clore_ai_support
AND-8828 CloreAI blockchain support
- Loading branch information
Showing
19 changed files
with
192 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
blockchain/src/main/java/com/tangem/blockchain/blockchains/clore/CloreMainNetParams.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.tangem.blockchain.blockchains.clore | ||
|
||
import org.bitcoinj.core.Block | ||
import org.bitcoinj.core.Utils | ||
import org.bitcoinj.params.AbstractBitcoinNetParams | ||
|
||
@Suppress("MagicNumber") | ||
internal class CloreMainNetParams : AbstractBitcoinNetParams() { | ||
init { | ||
interval = INTERVAL | ||
targetTimespan = TARGET_TIMESPAN | ||
|
||
// 00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff | ||
maxTarget = Utils.decodeCompactBits(0x1e0fffffL) | ||
addressHeader = 23 | ||
p2shHeader = 122 | ||
port = 8788 | ||
bip32HeaderP2PKHpub = 0x0488b21e // The 4 byte header that serializes in base58 to "xpub". | ||
bip32HeaderP2PKHpriv = 0x0488ade4 // The 4 byte header that serializes in base58 to "xprv" | ||
majorityEnforceBlockUpgrade = MAINNET_MAJORITY_ENFORCE_BLOCK_UPGRADE | ||
majorityRejectBlockOutdated = MAINNET_MAJORITY_REJECT_BLOCK_OUTDATED | ||
majorityWindow = MAINNET_MAJORITY_WINDOW | ||
id = ID_MAINNET | ||
dnsSeeds = arrayOf( | ||
"seed.clore.ai", | ||
"seed1.clore.ai", | ||
"seed2.clore.ai", | ||
) | ||
} | ||
|
||
override fun getPaymentProtocolId(): String { | ||
return PAYMENT_PROTOCOL_ID_MAINNET | ||
} | ||
|
||
override fun getGenesisBlock(): Block { | ||
return Block.createGenesis(this) // Stub genesis block | ||
} | ||
|
||
private companion object { | ||
private const val MAINNET_MAJORITY_WINDOW = 1000 | ||
private const val MAINNET_MAJORITY_REJECT_BLOCK_OUTDATED = 950 | ||
private const val MAINNET_MAJORITY_ENFORCE_BLOCK_UPGRADE = 750 | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
blockchain/src/main/java/com/tangem/blockchain/blockchains/clore/CloreProvidersBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.tangem.blockchain.blockchains.clore | ||
|
||
import com.tangem.blockchain.blockchains.bitcoin.network.BitcoinNetworkProvider | ||
import com.tangem.blockchain.common.Blockchain | ||
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.network.blockbook.BlockBookNetworkProviderFactory | ||
|
||
internal class CloreProvidersBuilder( | ||
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.mapNotNull { | ||
when (it) { | ||
is ProviderType.Public -> | ||
blockBookProviderFactory | ||
.createCloreBlockProvider(blockchain = blockchain, baseHost = it.url) | ||
else -> null | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...in/src/main/java/com/tangem/blockchain/common/assembly/impl/CloreWalletManagerAssembly.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.tangem.blockchain.common.assembly.impl | ||
|
||
import com.tangem.blockchain.blockchains.bitcoin.BitcoinTransactionBuilder | ||
import com.tangem.blockchain.blockchains.bitcoin.network.BitcoinNetworkService | ||
import com.tangem.blockchain.blockchains.clore.CloreProvidersBuilder | ||
import com.tangem.blockchain.blockchains.ravencoin.RavencoinFeesCalculator | ||
import com.tangem.blockchain.blockchains.ravencoin.RavencoinWalletManager | ||
import com.tangem.blockchain.common.assembly.WalletManagerAssembly | ||
import com.tangem.blockchain.common.assembly.WalletManagerAssemblyInput | ||
import com.tangem.blockchain.transactionhistory.TransactionHistoryProviderFactory | ||
|
||
internal object CloreWalletManagerAssembly : WalletManagerAssembly<RavencoinWalletManager>() { | ||
|
||
override fun make(input: WalletManagerAssemblyInput): RavencoinWalletManager { | ||
with(input.wallet) { | ||
return RavencoinWalletManager( | ||
wallet = this, | ||
transactionBuilder = BitcoinTransactionBuilder( | ||
walletPublicKey = publicKey.blockchainKey, | ||
blockchain = blockchain, | ||
walletAddresses = addresses, | ||
), | ||
networkProvider = BitcoinNetworkService( | ||
providers = CloreProvidersBuilder(input.providerTypes, input.config).build(blockchain), | ||
), | ||
transactionHistoryProvider = TransactionHistoryProviderFactory.makeProvider(blockchain, input.config), | ||
feesCalculator = RavencoinFeesCalculator(blockchain), | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...in/java/com/tangem/blockchain/externallinkprovider/providers/CloreExternalLinkProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.tangem.blockchain.externallinkprovider.providers | ||
|
||
import com.tangem.blockchain.externallinkprovider.ExternalLinkProvider | ||
import com.tangem.blockchain.externallinkprovider.TxExploreState | ||
|
||
internal class CloreExternalLinkProvider : ExternalLinkProvider { | ||
|
||
override val explorerBaseUrl: String = "https://clore.cryptoscope.io/" | ||
|
||
override fun explorerUrl(walletAddress: String, contractAddress: String?): String { | ||
return explorerBaseUrl + "address/?address=$walletAddress" | ||
} | ||
|
||
override fun getExplorerTxUrl(transactionHash: String): TxExploreState { | ||
return TxExploreState.Url(explorerBaseUrl + "tx/?txid=$transactionHash") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...hain/src/main/java/com/tangem/blockchain/network/blockbook/config/CloreBlockBookConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.tangem.blockchain.network.blockbook.config | ||
|
||
import com.tangem.blockchain.common.Blockchain | ||
|
||
internal class CloreBlockBookConfig(override val baseHost: String) : BlockBookConfig(credentials = null) { | ||
|
||
override fun getHost(blockchain: Blockchain, request: BlockBookRequest): String = baseHost | ||
|
||
override fun path(request: BlockBookRequest): String = "api/v2" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...rc/main/java/com/tangem/blockchain/network/blockbook/network/responses/GetFeesResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.tangem.blockchain.network.blockbook.network.responses | ||
|
||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
|
||
@JsonClass(generateAdapter = true) | ||
data class GetFeesResponse( | ||
@Json(name = "result") val result: Double, | ||
) |