Skip to content

Commit

Permalink
Merge branch 'release-app_5.19' into merge_5.18_5.19
Browse files Browse the repository at this point in the history
  • Loading branch information
kozarezvlad committed Dec 23, 2024
2 parents 3ab37c4 + fa2ce04 commit e61a742
Show file tree
Hide file tree
Showing 77 changed files with 1,519 additions and 248 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import com.tangem.blockchain.common.datastorage.BlockchainDataStorage
internal object DummyBlockchainDataStorage : BlockchainDataStorage {
override suspend fun getOrNull(key: String): String? = null
override suspend fun store(key: String, value: String) = Unit
override suspend fun remove(key: String) = Unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true)
data class BinanceFee(
@Json(name = "fixed_fee_params")
var transactionFee: BinanceFeeData? = null,
val transactionFee: BinanceFeeData? = null,
)

@JsonClass(generateAdapter = true)
data class BinanceFeeData(
@Json(name = "msg_type")
var messageType: String? = null,
val messageType: String? = null,

@Json(name = "fee")
var value: Int? = null,
val value: Int? = null,
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tangem.blockchain.blockchains.bitcoin

import com.tangem.blockchain.blockchains.clore.CloreMainNetParams
import com.tangem.blockchain.blockchains.dash.DashMainNetParams
import com.tangem.blockchain.blockchains.ducatus.DucatusMainNetParams
import com.tangem.blockchain.blockchains.radiant.RadiantMainNetParams
Expand Down Expand Up @@ -39,6 +40,7 @@ open class BitcoinAddressService(
Blockchain.Ravencoin -> RavencoinMainNetParams()
Blockchain.RavencoinTestnet -> RavencoinTestNetParams()
Blockchain.Radiant -> RadiantMainNetParams()
Blockchain.Clore -> CloreMainNetParams()
else -> error(
"${blockchain.fullName} blockchain is not supported by ${this::class.simpleName}",
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tangem.blockchain.blockchains.bitcoin

import com.tangem.blockchain.blockchains.clore.CloreMainNetParams
import com.tangem.blockchain.blockchains.dash.DashMainNetParams
import com.tangem.blockchain.blockchains.ducatus.DucatusMainNetParams
import com.tangem.blockchain.blockchains.ravencoin.RavencoinMainNetParams
Expand Down Expand Up @@ -44,6 +45,7 @@ open class BitcoinTransactionBuilder(
Blockchain.Dash -> DashMainNetParams()
Blockchain.Ravencoin -> RavencoinMainNetParams()
Blockchain.RavencoinTestnet -> RavencoinTestNetParams()
Blockchain.Clore -> CloreMainNetParams()
else -> error("${blockchain.fullName} blockchain is not supported by ${this::class.simpleName}")
}
var unspentOutputs: List<BitcoinUnspentOutput>? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ internal data class RosettaCoinsResponse(

@JsonClass(generateAdapter = true)
data class Currency(
@Json(name = "symbol")
val symbol: String?,
@Json(name = "decimals")
val decimals: Int?,
@Json(name = "metadata")
val metadata: Metadata?,
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import com.squareup.moshi.JsonClass
internal sealed interface CasperRpcResponse {

/** Success response with [result] */
data class Success(val result: Any) : CasperRpcResponse
@JsonClass(generateAdapter = true)
data class Success(
@Json(name = "result")
val result: Any,
) : CasperRpcResponse

/** Failure response with error [message] */
@JsonClass(generateAdapter = true)
Expand Down
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
}
}
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
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true)
data class BitcoreBalance(
@Json(name = "confirmed")
var confirmed: Long? = null,
val confirmed: Long? = null,

@Json(name = "unconfirmed")
var unconfirmed: Long? = null,
val unconfirmed: Long? = null,
)

@JsonClass(generateAdapter = true)
data class BitcoreUtxo(
@Json(name = "mintTxid")
var transactionHash: String? = null,
val transactionHash: String? = null,

@Json(name = "mintIndex")
var index: Int? = null,
val index: Int? = null,

@Json(name = "value")
var amount: Long? = null,
val amount: Long? = null,

@Json(name = "script")
var script: String? = null,
val script: String? = null,
)

@JsonClass(generateAdapter = true)
data class BitcoreSendResponse(
@Json(name = "txid")
var txid: String? = null,
val txid: String? = null,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.tangem.blockchain.blockchains.ducatus.network.bitcore

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class BitcoreSendBody(val rawTx: List<String>)
data class BitcoreSendBody(@Json(name = "rawTx") val rawTx: List<String>)
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,6 @@ enum class Chain(val id: Int, val blockchain: Blockchain?) {
CoreTestnet(id = 1115, blockchain = Blockchain.CoreTestnet),
Xodex(id = 2415, blockchain = Blockchain.Xodex),
Canxium(id = 3003, blockchain = Blockchain.Canxium),
Chiliz(id = 88888, blockchain = Blockchain.Chiliz),
ChilizTestnet(id = 88882, blockchain = Blockchain.ChilizTestnet),
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ internal val Blockchain.isSupportEIP1559: Boolean
Blockchain.EnergyWebChain,
Blockchain.Mantle,
Blockchain.Xodex,
Blockchain.Chiliz,
-> false
else -> error("Don't forget about evm here")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
package com.tangem.blockchain.blockchains.ethereum.models

import kotlinx.serialization.Serializable
import shadow.com.google.gson.annotations.SerializedName
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

/**
* Model of filled Ethereum transaction used in staking
*/
@Serializable
@JsonClass(generateAdapter = true)
data class EthereumCompiledTransaction(
@SerializedName("from")
@Json(name = "from")
val from: String,
@SerializedName("gasLimit")
@Json(name = "gasLimit")
val gasLimit: String,
@SerializedName("value")
@Json(name = "value")
val value: String?,
@SerializedName("to")
@Json(name = "to")
val to: String,
@SerializedName("data")
@Json(name = "data")
val data: String,
@SerializedName("nonce")
@Json(name = "nonce")
val nonce: Int,
@SerializedName("type")
@Json(name = "type")
val type: Int,
@SerializedName("gasPrice")
@Json(name = "gasPrice")
val gasPrice: String?,
@SerializedName("maxFeePerGas")
@Json(name = "maxFeePerGas")
val maxFeePerGas: String?,
@SerializedName("maxPriorityFeePerGas")
@Json(name = "maxPriorityFeePerGas")
val maxPriorityFeePerGas: String?,
@SerializedName("chainId")
@Json(name = "chainId")
val chainId: Int,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.tangem.blockchain.blockchains.ethereum.providers

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.network.providers.ProviderType

internal class ChilizProvidersBuilder(
override val providerTypes: List<ProviderType>,
) : OnlyPublicProvidersBuilder<EthereumJsonRpcProvider>(
providerTypes = providerTypes,
testnetProviders = listOf(
"https://spicy-rpc.chiliz.com/",
"https://chiliz-spicy.publicnode.com/",
),
) {
override fun createProvider(url: String, blockchain: Blockchain) = EthereumJsonRpcProvider(url)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ import com.squareup.moshi.JsonClass
internal sealed interface FilecoinRpcResponse {

/** Success response with [result] */
data class Success(val result: Any) : FilecoinRpcResponse
@JsonClass(generateAdapter = true)
data class Success(
@Json(name = "result")
val result: Any,
) : FilecoinRpcResponse

/** Failure response with error [message] */
@JsonClass(generateAdapter = true)
data class Failure(
@Json(name = "message") val message: String,
@Json(name = "message")
val message: String,
) : FilecoinRpcResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ internal class HederaWalletManager(
if (error is BlockchainSdkError) error("Error isn't BlockchainSdkError")
}

override suspend fun hasRequirements(currencyType: CryptoCurrencyType): Boolean {
private suspend fun assetRequiresAssociation(currencyType: CryptoCurrencyType): Boolean {
return when (currencyType) {
is CryptoCurrencyType.Coin -> false
is CryptoCurrencyType.Token -> {
Expand All @@ -99,7 +99,7 @@ internal class HederaWalletManager(
}

override suspend fun requirementsCondition(currencyType: CryptoCurrencyType): AssetRequirementsCondition? {
if (!hasRequirements(currencyType)) return null
if (!assetRequiresAssociation(currencyType)) return null

return when (currencyType) {
is CryptoCurrencyType.Coin -> null
Expand All @@ -110,7 +110,10 @@ internal class HederaWalletManager(
} else {
val feeValue = exchangeRate * HBAR_TOKEN_ASSOCIATE_USD_COST
val feeAmount = Amount(blockchain = wallet.blockchain, value = feeValue)
AssetRequirementsCondition.PaidTransactionWithFee(feeAmount)
AssetRequirementsCondition.PaidTransactionWithFee(
blockchain = blockchain,
feeAmount = feeAmount,
)
}
}
}
Expand All @@ -120,7 +123,7 @@ internal class HederaWalletManager(
currencyType: CryptoCurrencyType,
signer: TransactionSigner,
): SimpleResult {
if (!hasRequirements(currencyType)) return SimpleResult.Success
if (!assetRequiresAssociation(currencyType)) return SimpleResult.Success

return when (currencyType) {
is CryptoCurrencyType.Coin -> SimpleResult.Success
Expand Down Expand Up @@ -155,6 +158,10 @@ internal class HederaWalletManager(
}
}

override suspend fun discardRequirements(currencyType: CryptoCurrencyType): SimpleResult {
return SimpleResult.Success
}

override suspend fun send(
transactionData: TransactionData,
signer: TransactionSigner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
// based on BitcoinCashTransaction
public class KaspaTransaction extends Transaction {
private final byte[] TRANSACTION_SIGNING_DOMAIN = "TransactionSigningHash".getBytes(StandardCharsets.UTF_8);
private final byte[] TRANSACTION_ID = "TransactionID".getBytes(StandardCharsets.UTF_8);
private final byte[] TRANSACTION_SIGNING_ECDSA_DOMAIN_HASH =
Sha256Hash.of("TransactionSigningHashECDSA".getBytes(StandardCharsets.UTF_8)).getBytes();
private final int BLAKE2B_DIGEST_LENGTH = 32;
Expand Down Expand Up @@ -130,6 +131,41 @@ public synchronized byte[] hashForSignatureWitness(
return Sha256Hash.of(finalBos.toByteArray()).getBytes();
}

public synchronized byte[] transactionHash() {
ByteArrayOutputStream bos = new ByteArrayOutputStream(256);
try {
List<TransactionInput> inputs = getInputs();
List<TransactionOutput> outputs = getOutputs();

uint16ToByteStreamLE(0, bos);

uint64ToByteStreamLE(BigInteger.valueOf(inputs.size()), bos);
for (TransactionInput input: inputs) {
bos.write(input.getOutpoint().getHash().getBytes());
uint32ToByteStreamLE(input.getOutpoint().getIndex(), bos);
uint64ToByteStreamLE(BigInteger.valueOf(0), bos);
uint64ToByteStreamLE(BigInteger.valueOf(0), bos);
}
uint64ToByteStreamLE(BigInteger.valueOf(outputs.size()), bos);
for (TransactionOutput output : outputs) {
byte[] scriptBytes = output.getScriptBytes();
uint64ToByteStreamLE(BigInteger.valueOf(output.getValue().value), bos);
uint16ToByteStreamLE(0, bos); // version
uint64ToByteStreamLE(BigInteger.valueOf(scriptBytes.length), bos);
bos.write(scriptBytes);
}
uint64ToByteStreamLE(BigInteger.valueOf(getLockTime()), bos); // lock time
bos.write(new byte[20]); // subnetwork id
uint64ToByteStreamLE(BigInteger.valueOf(0), bos); // gas
uint64ToByteStreamLE(BigInteger.valueOf(0), bos); // payload size
} catch (IOException e) {
throw new RuntimeException(e);
}

Blake2b.Mac digest = Blake2b.Mac.newInstance(TRANSACTION_ID, BLAKE2B_DIGEST_LENGTH);
return digest.digest(bos.toByteArray());
}

private byte[] blake2bDigestOf(byte[] input) {
Blake2b.Mac digest = Blake2b.Mac.newInstance(TRANSACTION_SIGNING_DOMAIN, BLAKE2B_DIGEST_LENGTH);
return digest.digest(input);
Expand Down
Loading

0 comments on commit e61a742

Please sign in to comment.