Updated on 2026-08-14

This commit is contained in:
Tangem 2020-05-01 18:47:42 +03:00
parent fa34a56048
commit 816facfb27
5 changed files with 16 additions and 16 deletions

View file

@ -5,7 +5,6 @@ import com.tangem.blockchain.common.AmountType
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.TransactionData
import com.tangem.common.extensions.hexToBytes
import org.kethereum.DEFAULT_GAS_LIMIT
import org.kethereum.crypto.api.ec.ECDSASignature
import org.kethereum.crypto.determineRecId
import org.kethereum.crypto.impl.ec.canonicalise
@ -22,6 +21,7 @@ class EthereumTransactionBuilder(private val walletPublicKey: ByteArray, blockch
private val chainId = when (blockchain) {
Blockchain.Ethereum -> Chain.Mainnet.id
Blockchain.RSK -> Chain.RskMainnet.id
else -> throw Exception("${blockchain.fullName} blockchain is not supported by EthereumTransactionBuilder")
}
@ -36,14 +36,15 @@ class EthereumTransactionBuilder(private val walletPublicKey: ByteArray, blockch
val to: Address
val value: BigInteger
val input: ByteArray//data for smart contract
val input: ByteArray //data for smart contract
if (transactionData.amount.type == AmountType.Coin) { //ETH transfer
if (transactionData.amount.type == AmountType.Coin) { //coin transfer
to = Address(transactionData.destinationAddress)
value = bigIntegerAmount
input = ByteArray(0)
} else { //Token transfer
to = Address(transactionData.contractAddress ?: throw Exception("Contract address is not specified!"))
} else { //token transfer
to = Address(transactionData.contractAddress
?: throw Exception("Contract address is not specified!"))
value = BigInteger.ZERO
input = createErc20TransferData(transactionData.destinationAddress, bigIntegerAmount)
}
@ -104,8 +105,8 @@ enum class Chain(val id: Int) {
Morden(2),
Ropsten(3),
Rinkeby(4),
RootstockMainnet(30),
RootstockTestnet(31),
RskMainnet(30),
RskTestnet(31),
Kovan(42),
EthereumClassicMainnet(61),
EthereumClassicTestnet(62),

View file

@ -5,6 +5,7 @@ import com.tangem.blockchain.extensions.Result
import com.tangem.blockchain.extensions.SimpleResult
import com.tangem.blockchain.extensions.retryIO
import com.tangem.blockchain.network.API_INFURA
import com.tangem.blockchain.network.API_RSK
import com.tangem.blockchain.network.createRetrofitInstance
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.async
@ -20,6 +21,7 @@ class EthereumNetworkManager(blockchain: Blockchain) {
private val api: InfuraApi by lazy {
val baseUrl = when (blockchain) {
Blockchain.Ethereum -> API_INFURA
Blockchain.RSK -> API_RSK
else -> throw Exception("${blockchain.fullName} blockchain is not supported by EthereumNetworkManager")
}
createRetrofitInstance(baseUrl).create(InfuraApi::class.java)

View file

@ -8,8 +8,6 @@ import com.tangem.blockchain.blockchains.ethereum.EthereumAddressService
import com.tangem.blockchain.blockchains.stellar.StellarAddressService
import com.tangem.blockchain.blockchains.xrp.XrpAddressService
import java.math.BigDecimal
enum class Blockchain(
val id: String,
val currency: String,
@ -20,7 +18,7 @@ enum class Blockchain(
BitcoinTestnet("BTC/test", "BTCt", "Bitcoin Testnet"),
BitcoinCash("BCH", "BCH", "Bitcoin Cash"),
Ethereum("ETH", "ETH", "Ethereum"),
Rootstock("", "", ""),
RSK("RSK", "RBTC", "RSK"),
Cardano("CARDANO", "ADA", "Cardano"),
XRP("XRP", "XRP", "XRP Ledger"),
Binance("BINANCE", "BNB", "Binance"),
@ -30,7 +28,7 @@ enum class Blockchain(
fun decimals(): Int = when (this) {
Bitcoin, BitcoinTestnet, BitcoinCash, Binance, BinanceTestnet -> 8
Cardano, XRP -> 6
Ethereum, Rootstock -> 18
Ethereum, RSK -> 18
Stellar -> 7
Unknown -> 0
}
@ -49,7 +47,7 @@ enum class Blockchain(
BitcoinTestnet -> BitcoinAddressService(true)
BitcoinCash -> BitcoinCashAddressService()
Ethereum -> EthereumAddressService()
Rootstock -> throw Exception("unsupported blockchain")
RSK -> throw Exception("unsupported blockchain")
Cardano -> CardanoAddressService()
XRP -> XrpAddressService()
Binance -> BinanceAddressService()
@ -75,7 +73,7 @@ enum class Blockchain(
} else {
"https://etherscan.io/token/${token.contractAddress}?a=$address"
}
Rootstock -> {
RSK -> {
var url = "https://explorer.rsk.co/address/$address"
if (token != null) {
url += "?__tab=tokens"

View file

@ -12,7 +12,6 @@ import com.tangem.blockchain.blockchains.bitcoincash.BitcoinCashWalletManager
import com.tangem.blockchain.blockchains.cardano.CardanoTransactionBuilder
import com.tangem.blockchain.blockchains.cardano.CardanoWalletManager
import com.tangem.blockchain.blockchains.cardano.network.CardanoNetworkManager
import com.tangem.blockchain.blockchains.ethereum.Chain
import com.tangem.blockchain.blockchains.ethereum.EthereumTransactionBuilder
import com.tangem.blockchain.blockchains.ethereum.EthereumWalletManager
import com.tangem.blockchain.blockchains.ethereum.network.EthereumNetworkManager
@ -61,7 +60,7 @@ object WalletManagerFactory {
BitcoinCashNetworkManager()
)
}
Blockchain.Ethereum -> {
Blockchain.Ethereum, Blockchain.RSK -> {
return EthereumWalletManager(
cardId, wallet,
EthereumTransactionBuilder(walletPublicKey, blockchain),

View file

@ -40,7 +40,7 @@ const val API_INFURA = "https://mainnet.infura.io/"
const val API_SOCHAIN_V2 = "https://chain.so/"
const val API_ESTIMATEFEE = "https://estimatefee.com/"
const val API_UPDATE_VERSION = "https://raw.githubusercontent.com/"
const val API_ROOTSTOCK = "https://public-node.rsk.co/"
const val API_RSK = "https://public-node.rsk.co/"
const val API_BLOCKCYPHER = "https://api.blockcypher.com/"
const val API_BINANCE = "https://dex.binance.org/"
const val API_BINANCE_TESTNET = "https://testnet-dex.binance.org/"