Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -12,16 +12,18 @@ import jp.co.soramitsu.shared_utils.runtime.metadata.storage
import jp.co.soramitsu.shared_utils.runtime.metadata.storageKey
import jp.co.soramitsu.shared_utils.wsrpc.SocketService
import jp.co.soramitsu.staking.impl.data.network.blockhain.bindings.bindActiveEra
import java.math.BigInteger
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import java.math.BigInteger

fun RuntimeMetadata.activeEraStorageKeyOrNull() = moduleOrNull(Modules.STAKING)?.storage("ActiveEra")?.storageKey()
fun RuntimeMetadata.stakingRoundKey() = parachainStaking().storage("Round").storageKey()

suspend fun StorageCache.observeActiveEraIndex(runtime: RuntimeSnapshot, chainId: String): Flow<BigInteger> {
return observeEntry(runtime.metadata.activeEraStorageKeyOrNull(), chainId)
.map { bindActiveEra(it.content!!, runtime) }
.map { entry ->
entry.content?.let { bindActiveEra(it, runtime) }
}
}

suspend fun BulkRetriever.fetchValuesToCache(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import jp.co.soramitsu.runtime.multiNetwork.ChainRegistry
import jp.co.soramitsu.runtime.multiNetwork.chain.model.Chain
import jp.co.soramitsu.runtime.multiNetwork.chain.model.ChainId
import jp.co.soramitsu.runtime.storage.source.StorageDataSource
import jp.co.soramitsu.runtime.storage.source.observeNonNull
import jp.co.soramitsu.runtime.storage.source.queryNonNull
import jp.co.soramitsu.shared_utils.extensions.fromHex
import jp.co.soramitsu.shared_utils.extensions.toHexString
Expand Down Expand Up @@ -197,11 +196,11 @@ class StakingRelayChainScenarioRepository(
}

fun observeActiveEraIndex(chainId: String): Flow<BigInteger> {
return localStorage.observeNonNull(
return localStorage.observe(
chainId = chainId,
keyBuilder = { it.metadata.activeEraStorageKeyOrNull() },
binding = { scale, runtime -> bindActiveEra(scale, runtime) }
)
binder = { scale, runtime -> scale?.let { bindActiveEra(it, runtime) } }
).filterNotNull()
}

@OptIn(ExperimentalCoroutinesApi::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,23 @@ class ChainEnvironmentConfiguratorProvider(
private val ethereumConnectionPool: EthereumConnectionPool
) {
fun provide(chain: Chain): ChainEnvironmentConfigurator {
return when (chain.ecosystem) {
Ecosystem.Substrate,
Ecosystem.EthereumBased -> SubstrateEnvironmentConfigurator(
return when {
chain.isEthereumChain -> EthereumEnvironmentConfigurator(
ethereumConnectionPool,
chainsRepository
)
chain.ecosystem == Ecosystem.Ethereum -> EthereumEnvironmentConfigurator(
ethereumConnectionPool,
chainsRepository
)
chain.ecosystem == Ecosystem.Ton -> TonEnvironmentConfigurator()
else -> SubstrateEnvironmentConfigurator(
connectionPool,
runtimeProviderPool,
runtimeSyncService,
runtimeSubscriptionPool,
chainsRepository
)

Ecosystem.Ethereum -> EthereumEnvironmentConfigurator(
ethereumConnectionPool,
chainsRepository
)

Ecosystem.Ton -> TonEnvironmentConfigurator()
}
}
}
}