Skip to content

Commit

Permalink
Merge pull request #1149 from soramitsu/staging
Browse files Browse the repository at this point in the history
staging
  • Loading branch information
Deneath authored Apr 26, 2024
2 parents f20e08e + 831f446 commit 89559ac
Show file tree
Hide file tree
Showing 61 changed files with 639 additions and 274 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ apply plugin: "org.sonarqube"
buildscript {
ext {
// App version
versionName = '3.4.3'
versionCode = 168
versionName = '3.4.4'
versionCode = 172

// SDK and tools
compileSdkVersion = 34
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package jp.co.soramitsu.core.model

class StorageEntry(
data class StorageEntry(
val storageKey: String,
val content: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ interface UpdateScope {
fun invalidationFlow(): Flow<Any>
}

object GlobalScope : UpdateScope {
object GlobalUpdaterScope : UpdateScope {

override fun invalidationFlow() = flowOf(Unit)
}

interface GlobalScopeUpdater : Updater {

override val scope
get() = GlobalScope
get() = GlobalUpdaterScope
}

interface Updater : SideEffectScope {
Expand Down
4 changes: 3 additions & 1 deletion core-db/src/main/java/jp/co/soramitsu/coredb/AppDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import jp.co.soramitsu.coredb.migrations.Migration_59_60
import jp.co.soramitsu.coredb.migrations.Migration_60_61
import jp.co.soramitsu.coredb.migrations.Migration_61_62
import jp.co.soramitsu.coredb.migrations.Migration_62_63
import jp.co.soramitsu.coredb.migrations.Migration_63_64
import jp.co.soramitsu.coredb.migrations.RemoveAccountForeignKeyFromAsset_17_18
import jp.co.soramitsu.coredb.migrations.RemoveLegacyData_35_36
import jp.co.soramitsu.coredb.migrations.RemoveStakingRewardsTable_22_23
Expand All @@ -91,7 +92,7 @@ import jp.co.soramitsu.coredb.model.chain.FavoriteChainLocal
import jp.co.soramitsu.coredb.model.chain.MetaAccountLocal

@Database(
version = 63,
version = 64,
entities = [
AccountLocal::class,
AddressBookContact::class,
Expand Down Expand Up @@ -175,6 +176,7 @@ abstract class AppDatabase : RoomDatabase() {
.addMigrations(Migration_60_61)
.addMigrations(Migration_61_62)
.addMigrations(Migration_62_63)
.addMigrations(Migration_63_64)
.build()
}
return instance!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ package jp.co.soramitsu.coredb.migrations
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase

val Migration_63_64 = object : Migration(63, 64) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE chains ADD COLUMN `isUsesAppId` INTEGER NOT NULL DEFAULT 0")
}
}

val Migration_62_63 = object : Migration(62, 63) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE assets ADD COLUMN `status` TEXT NULL")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class ChainLocal(
val supportStakingPool: Boolean,
val isEthereumChain: Boolean,
val isChainlinkProvider: Boolean,
val supportNft: Boolean
val supportNft: Boolean,
val isUsesAppId: Boolean
) {

class ExternalApi(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class CrowdloanContributeInteractor(
}

return runCatching {
walletRepository.performTransfer(accountId, chain, transfer, fee, null, additional, batchAll)
walletRepository.performTransfer(accountId, chain, transfer, fee, null, null, additional, batchAll)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ class StakingSharedState(
val assetWithChain: Flow<SingleAssetSharedState.AssetWithChain> = selectionItem.map {
val (chain, asset) = chainRegistry.chainWithAsset(it.chainId, it.chainAssetId)
SingleAssetSharedState.AssetWithChain(chain, asset)
}.shareIn(scope, SharingStarted.Eagerly, replay = 1)
}
.distinctUntilChanged()
.shareIn(scope, SharingStarted.Eagerly, replay = 1)

suspend fun assetWithChain(selectionItem: StakingAssetSelection) {
val (chain, asset) = chainRegistry.chainWithAsset(
Expand All @@ -112,7 +114,7 @@ class StakingSharedState(
chainAsset = chainAsset,
minSupportedVersion = chain.minSupportedVersion
)
}.shareIn(scope, SharingStarted.Eagerly, replay = 1)
}.distinctUntilChanged().shareIn(scope, SharingStarted.Eagerly, replay = 1)

suspend fun availableAssetsToSelect(): List<Asset> {
val metaAccount = accountRepository.getSelectedMetaAccount()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ package jp.co.soramitsu.staking.api.domain.model

import java.math.BigInteger

class IndividualExposure(val who: ByteArray, val value: BigInteger)
interface ValidatorExposure {
val nominatorCount: Int
val total: BigInteger
val own: BigInteger
}

class Exposure(val total: BigInteger, val own: BigInteger, val others: List<IndividualExposure>)
class LegacyExposure(
override val total: BigInteger, override val own: BigInteger, val others: List<IndividualExposure>
): ValidatorExposure{
override val nominatorCount: Int = others.size
}

class Exposure(override val total: BigInteger, override val own: BigInteger, override val nominatorCount: Int, val pageCount: BigInteger): ValidatorExposure
data class ExposurePage(val pageTotal: BigInteger, val others: List<IndividualExposure>)

class IndividualExposure(val who: ByteArray, val value: BigInteger)
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,20 @@ class RootIdentity(
override val pgpFingerprint: String?,
override val image: String?,
override val twitter: String?
) : Identity
) : Identity {
companion object {
fun empty() = RootIdentity(
display = null,
legal = null,
web = null,
riot = null,
email = null,
pgpFingerprint = null,
image = null,
twitter = null
)
}
}

class ChildIdentity(
childName: String?,
Expand All @@ -37,7 +50,7 @@ class ChildIdentity(
override val display: String = "${parentIdentity.display} / ${childName.orEmpty()}"
}

class SuperOf(
data class SuperOf(
val parentIdHex: String,
val childName: String?
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import jp.co.soramitsu.shared_utils.runtime.RuntimeSnapshot
import java.math.BigInteger

@UseCaseBinding
fun bindStaked(
fun bindTotal(
scale: String,
runtime: RuntimeSnapshot
): BigInteger {
val returnType = runtime.metadata.storageReturnType("ParachainStaking", "Staked")
val returnType = runtime.metadata.storageReturnType("ParachainStaking", "Total")

return bindNumber(returnType.fromHexOrIncompatible(scale, runtime))
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ import java.math.BigInteger
*/
@UseCaseBinding
fun bindActiveEra(
scale: String,
scale: String?,
runtime: RuntimeSnapshot
): BigInteger {
scale ?: return BigInteger.ZERO
val returnType = runtime.metadata.storageReturnType("Staking", "ActiveEra")
val decoded = returnType.fromHexOrNull(runtime, scale) as? Struct.Instance ?: incompatible()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
package jp.co.soramitsu.staking.impl.data.network.blockhain.bindings

import java.math.BigInteger
import jp.co.soramitsu.common.data.network.runtime.binding.HelperBinding
import jp.co.soramitsu.common.data.network.runtime.binding.UseCaseBinding
import jp.co.soramitsu.common.data.network.runtime.binding.incompatible
import jp.co.soramitsu.common.data.network.runtime.binding.requireType
import jp.co.soramitsu.common.utils.staking
import jp.co.soramitsu.core.runtime.storage.returnType
import jp.co.soramitsu.shared_utils.runtime.RuntimeSnapshot
import jp.co.soramitsu.shared_utils.runtime.definitions.types.Type
import jp.co.soramitsu.shared_utils.runtime.definitions.types.composite.Struct
import jp.co.soramitsu.shared_utils.runtime.definitions.types.fromHexOrNull
import jp.co.soramitsu.shared_utils.runtime.metadata.storage
import jp.co.soramitsu.staking.api.domain.model.Exposure
import jp.co.soramitsu.staking.api.domain.model.ExposurePage
import jp.co.soramitsu.staking.api.domain.model.IndividualExposure
import java.math.BigInteger
import jp.co.soramitsu.staking.api.domain.model.LegacyExposure

/*
IndividualExposure: {
who: AccountId; // account id of the nominator
value: Compact<Balance>; // nominator’s stake
}
*/
@HelperBinding
fun bindIndividualExposure(dynamicInstance: Any?, runtime: RuntimeSnapshot): IndividualExposure {
fun bindIndividualExposure(dynamicInstance: Any?): IndividualExposure {
requireType<Struct.Instance>(dynamicInstance)

val who = dynamicInstance.get<ByteArray>("who") ?: incompatible()
Expand All @@ -28,21 +27,41 @@ fun bindIndividualExposure(dynamicInstance: Any?, runtime: RuntimeSnapshot): Ind
return IndividualExposure(who, value)
}

/*
Exposure: {
total: Compact<Balance>; // total stake of the validator
own: Compact<Balance>; // own stake of the validator
others: Vec<IndividualExposure>; // nominators stakes
}
*/
@UseCaseBinding
fun bindExposure(scale: String, runtime: RuntimeSnapshot, type: Type<*>): Exposure? {
fun bindLegacyExposure(scale: String, runtime: RuntimeSnapshot, type: Type<*>): LegacyExposure? {
val decoded = type.fromHexOrNull(runtime, scale) as? Struct.Instance ?: return null

val total = decoded.get<BigInteger>("total") ?: return null
val own = decoded.get<BigInteger>("own") ?: return null

val others = decoded.get<List<*>>("others")?.map { bindIndividualExposure(it, runtime) } ?: return null
val others = decoded.get<List<*>>("others")?.map { bindIndividualExposure(it) } ?: return null

return Exposure(total, own, others)
return LegacyExposure(total, own, others)
}

@UseCaseBinding
fun bindExposure(scale: String, runtime: RuntimeSnapshot): Exposure? {
val storageType = runtime.metadata.staking().storage("ErasStakersOverview").returnType()

val decoded = storageType.fromHexOrNull(runtime, scale) as? Struct.Instance ?: return null

val total = decoded.get<BigInteger>("total") ?: return null
val own = decoded.get<BigInteger>("own") ?: return null

val nominatorCount = decoded.get<BigInteger>("nominatorCount") ?: return null
val pageCount = decoded.get<BigInteger>("pageCount") ?: return null

return Exposure(total, own, nominatorCount.toInt(), pageCount)
}

@UseCaseBinding
fun bindExposurePage(scale: String, runtime: RuntimeSnapshot): ExposurePage? {
return runCatching {
val storageType = runtime.metadata.staking().storage("ErasStakersPaged").returnType()
val decoded = storageType.fromHexOrNull(runtime, scale) as? Struct.Instance ?: return null
val pageTotal = decoded.get<BigInteger>("pageTotal") ?: return null
val others =
decoded.get<List<*>>("others")?.map { bindIndividualExposure(it) } ?: return null
ExposurePage(pageTotal, others)
}.getOrNull()
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ fun bindIdentity(
runtime: RuntimeSnapshot,
type: Type<*>
): Identity {
val decoded = type.fromHexOrNull(runtime, scale) as? Struct.Instance ?: incompatible()
val decoded = type.fromHexOrNull(runtime, scale)// as? Struct.Instance ?: incompatible()
val struct = when (decoded) {
is Struct.Instance -> decoded.cast<Struct.Instance>()
is ArrayList<*> -> decoded.cast<ArrayList<*>>().first() as Struct.Instance
else -> return RootIdentity.empty()
}

val identityInfo = decoded.get<Struct.Instance>("info") ?: incompatible()
val identityInfo = struct.get<Struct.Instance>("info") ?: incompatible()

val pgpFingerprint = identityInfo.get<ByteArray?>("pgpFingerprint")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ fun bindDelegationScheduledRequests(
}
}

private fun bindNumber(scale: String, runtimeSnapshot: RuntimeSnapshot, type: Type<*>): BigInteger {
fun bindNumber(scale: String, runtimeSnapshot: RuntimeSnapshot, type: Type<*>): BigInteger {
return bindNumber(type.fromHexOrNull(runtimeSnapshot, scale) ?: return scale.fromHex().fromUnsignedBytes())
}

private fun bindNumberOrNull(scale: String, runtimeSnapshot: RuntimeSnapshot, type: Type<*>): BigInteger? {
fun bindNumberOrNull(scale: String, runtimeSnapshot: RuntimeSnapshot, type: Type<*>): BigInteger? {
return bindNumber(type.fromHexOrNull(runtimeSnapshot, scale) ?: return null)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package jp.co.soramitsu.staking.impl.data.network.blockhain.updaters

import jp.co.soramitsu.common.utils.staking
import jp.co.soramitsu.core.storage.StorageCache
import jp.co.soramitsu.core.updater.GlobalScope
import jp.co.soramitsu.core.updater.GlobalUpdaterScope
import jp.co.soramitsu.runtime.multiNetwork.ChainRegistry
import jp.co.soramitsu.runtime.network.updaters.SingleStorageKeyUpdater
import jp.co.soramitsu.shared_utils.runtime.RuntimeSnapshot
Expand All @@ -15,7 +15,7 @@ class ActiveEraUpdater(
stakingSharedState: StakingSharedState,
chainRegistry: ChainRegistry,
storageCache: StorageCache
) : SingleStorageKeyUpdater<GlobalScope>(GlobalScope, stakingSharedState, chainRegistry, storageCache), StakingUpdater {
) : SingleStorageKeyUpdater<GlobalUpdaterScope>(GlobalUpdaterScope, stakingSharedState, chainRegistry, storageCache), StakingUpdater {

override suspend fun storageKey(runtime: RuntimeSnapshot): String {
return runtime.metadata.staking().storage("ActiveEra").storageKey()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package jp.co.soramitsu.staking.impl.data.network.blockhain.updaters

import jp.co.soramitsu.common.utils.Modules
import jp.co.soramitsu.core.storage.StorageCache
import jp.co.soramitsu.core.updater.GlobalScope
import jp.co.soramitsu.core.updater.GlobalUpdaterScope
import jp.co.soramitsu.runtime.multiNetwork.ChainRegistry
import jp.co.soramitsu.runtime.network.updaters.SingleStorageKeyUpdater
import jp.co.soramitsu.shared_utils.runtime.RuntimeSnapshot
Expand All @@ -16,7 +16,7 @@ class CounterForNominatorsUpdater(
stakingSharedState: StakingSharedState,
chainRegistry: ChainRegistry,
storageCache: StorageCache
) : SingleStorageKeyUpdater<GlobalScope>(GlobalScope, stakingSharedState, chainRegistry, storageCache), StakingUpdater {
) : SingleStorageKeyUpdater<GlobalUpdaterScope>(GlobalUpdaterScope, stakingSharedState, chainRegistry, storageCache), StakingUpdater {

override suspend fun storageKey(runtime: RuntimeSnapshot): String? {
return runtime.metadata.moduleOrNull(Modules.STAKING)?.storageOrNull("CounterForNominators")?.storageKey()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package jp.co.soramitsu.staking.impl.data.network.blockhain.updaters

import jp.co.soramitsu.common.utils.staking
import jp.co.soramitsu.core.storage.StorageCache
import jp.co.soramitsu.core.updater.GlobalScope
import jp.co.soramitsu.core.updater.GlobalUpdaterScope
import jp.co.soramitsu.runtime.multiNetwork.ChainRegistry
import jp.co.soramitsu.runtime.network.updaters.SingleStorageKeyUpdater
import jp.co.soramitsu.shared_utils.runtime.RuntimeSnapshot
Expand All @@ -15,7 +15,7 @@ class CurrentEraUpdater(
stakingSharedState: StakingSharedState,
chainRegistry: ChainRegistry,
storageCache: StorageCache
) : SingleStorageKeyUpdater<GlobalScope>(GlobalScope, stakingSharedState, chainRegistry, storageCache), StakingUpdater {
) : SingleStorageKeyUpdater<GlobalUpdaterScope>(GlobalUpdaterScope, stakingSharedState, chainRegistry, storageCache), StakingUpdater {

override suspend fun storageKey(runtime: RuntimeSnapshot): String {
return runtime.metadata.staking().storage("CurrentEra").storageKey()
Expand Down
Loading

0 comments on commit 89559ac

Please sign in to comment.