Updated on 2026-08-14
This commit is contained in:
parent
c9be7fa5c5
commit
d47433ee6c
24 changed files with 193 additions and 90 deletions
|
|
@ -2,16 +2,16 @@ package com.tangem.data.wallets.derivations
|
|||
|
||||
import com.tangem.common.CompletionResult
|
||||
import com.tangem.common.extensions.ByteArrayKey
|
||||
import com.tangem.common.map
|
||||
import com.tangem.crypto.hdWallet.DerivationPath
|
||||
import com.tangem.datasource.local.userwallet.UserWalletsStore
|
||||
import com.tangem.domain.wallets.derivations.ColdMapDerivationsRepository
|
||||
import com.tangem.domain.wallets.derivations.DerivationsRepository
|
||||
import com.tangem.domain.wallets.derivations.HotMapDerivationsRepository
|
||||
import com.tangem.domain.models.account.DerivationIndex
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.network.Network
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.domain.wallets.derivations.ColdMapDerivationsRepository
|
||||
import com.tangem.domain.wallets.derivations.DerivationsRepository
|
||||
import com.tangem.domain.wallets.derivations.HotMapDerivationsRepository
|
||||
import com.tangem.domain.wallets.usecase.BackendId
|
||||
import com.tangem.operations.derivation.ExtendedPublicKeysMap
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
|
|
@ -29,11 +29,17 @@ internal class DefaultDerivationsRepository @Inject constructor(
|
|||
derivePublicKeysByNetworks(userWalletId = userWalletId, networks = currencies.map(CryptoCurrency::network))
|
||||
}
|
||||
|
||||
override suspend fun derivePublicKeysByNetworkIds(userWalletId: UserWalletId, networkIds: List<Network.RawID>) {
|
||||
override suspend fun derivePublicKeysByNetworkIds(
|
||||
userWalletId: UserWalletId,
|
||||
networkIds: List<Network.RawID>,
|
||||
accountIndex: DerivationIndex,
|
||||
) {
|
||||
val userWallet = userWalletsStore.getSyncStrict(userWalletId)
|
||||
when (userWallet) {
|
||||
is UserWallet.Cold -> coldDerivationsRepository.derivePublicKeysByNetworkIds(userWallet, networkIds)
|
||||
is UserWallet.Hot -> hotDerivationsRepository.derivePublicKeysByNetworkIds(userWallet, networkIds)
|
||||
is UserWallet.Hot -> {
|
||||
hotDerivationsRepository.derivePublicKeysByNetworkIds(userWallet, networkIds, accountIndex)
|
||||
}
|
||||
}.also {
|
||||
userWallet.update(it)
|
||||
}
|
||||
|
|
@ -57,9 +63,9 @@ internal class DefaultDerivationsRepository @Inject constructor(
|
|||
return when (userWallet) {
|
||||
is UserWallet.Cold -> coldDerivationsRepository.derivePublicKeys(userWallet, derivations)
|
||||
is UserWallet.Hot -> hotDerivationsRepository.derivePublicKeys(userWallet, derivations)
|
||||
}.let {
|
||||
userWallet.update(it.first)
|
||||
it.second
|
||||
}.let { publicKeysMapByUserWallet ->
|
||||
userWallet.update(publicKeysMapByUserWallet.first)
|
||||
publicKeysMapByUserWallet.second
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import com.tangem.crypto.hdWallet.DerivationPath
|
|||
import com.tangem.data.common.network.NetworkFactory
|
||||
import com.tangem.data.wallets.derivations.MissedDerivationsFinder
|
||||
import com.tangem.datasource.local.userwallet.UserWalletsStore
|
||||
import com.tangem.domain.models.account.DerivationIndex
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.network.Network
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
|
|
@ -38,14 +39,16 @@ internal class DefaultHotMapDerivationsRepository @Inject constructor(
|
|||
override suspend fun derivePublicKeysByNetworkIds(
|
||||
userWallet: UserWallet.Hot,
|
||||
networkIds: List<Network.RawID>,
|
||||
accountIndex: DerivationIndex,
|
||||
): UserWallet.Hot {
|
||||
return derivePublicKeysByNetworks(
|
||||
userWallet = userWallet,
|
||||
networks = networkIds.mapNotNull {
|
||||
networks = networkIds.mapNotNull { networkRawId ->
|
||||
networkFactory.create(
|
||||
blockchain = Blockchain.fromNetworkId(it.value) ?: return@mapNotNull null,
|
||||
blockchain = Blockchain.fromNetworkId(networkRawId.value) ?: return@mapNotNull null,
|
||||
extraDerivationPath = null,
|
||||
userWallet = userWallet,
|
||||
accountIndex = accountIndex,
|
||||
)
|
||||
},
|
||||
)
|
||||
|
|
@ -138,7 +141,7 @@ internal class DefaultHotMapDerivationsRepository @Inject constructor(
|
|||
): Map<ByteArrayKey, ExtendedPublicKeysMap> {
|
||||
return (oldKeys.keys + newKeys.keys).toSet()
|
||||
.associateWith { walletKey ->
|
||||
val oldDerivations = ExtendedPublicKeysMap(oldKeys[walletKey] ?: emptyMap())
|
||||
val oldDerivations = ExtendedPublicKeysMap(oldKeys[walletKey].orEmpty())
|
||||
val newDerivations = newKeys[walletKey] ?: ExtendedPublicKeysMap(emptyMap())
|
||||
|
||||
ExtendedPublicKeysMap(oldDerivations + newDerivations)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue