Skip to content

Commit

Permalink
Merge pull request #891 from novasamatech/fix/staking-max-elections
Browse files Browse the repository at this point in the history
Prioritise json for staking max electing voters 86935m0yc
  • Loading branch information
ERussel authored Nov 21, 2023
2 parents 2d2e247 + 3f2c6e0 commit 1f500df
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@ struct ChainModel: Equatable, Codable, Hashable {
var isUtilityTokenOnRelaychain: Bool {
additional?.relaychainAsNative?.boolValue ?? false
}

var stakingMaxElectingVoters: UInt32? {
guard let value = additional?.stakingMaxElectingVoters?.unsignedIntValue else {
return nil
}

return UInt32(value)
}
}

extension ChainModel: Identifiable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import SubstrateSdk

protocol RelaychainConsensusStateDepending {
func createNetworkInfoOperationFactory(
for durationFactory: StakingDurationOperationFactoryProtocol,
for chain: ChainModel,
durationFactory: StakingDurationOperationFactoryProtocol,
operationQueue: OperationQueue
) -> NetworkStakingInfoOperationFactoryProtocol

Expand All @@ -22,10 +23,12 @@ protocol RelaychainConsensusStateDepending {

final class RelaychainConsensusStateDependingFactory: RelaychainConsensusStateDepending {
func createNetworkInfoOperationFactory(
for durationFactory: StakingDurationOperationFactoryProtocol,
for chain: ChainModel,
durationFactory: StakingDurationOperationFactoryProtocol,
operationQueue: OperationQueue
) -> NetworkStakingInfoOperationFactoryProtocol {
let votersInfoOperationFactory = VotersInfoOperationFactory(
chain: chain,
operationManager: OperationManager(operationQueue: operationQueue)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ final class RelaychainStakingSharedState: RelaychainStakingSharedStateProtocol {
)

return consensusDependingFactory.createNetworkInfoOperationFactory(
for: durationFactory,
for: stakingOption.chainAsset.chain,
durationFactory: durationFactory,
operationQueue: operationQueue
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ final class RelaychainStartStakingState: RelaychainStartStakingStateProtocol {
)

return consensusDependingFactory.createNetworkInfoOperationFactory(
for: durationFactory,
for: chainAsset.chain,
durationFactory: durationFactory,
operationQueue: operationQueue
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ protocol VotersInfoOperationFactoryProtocol {

final class VotersInfoOperationFactory {
let operationManager: OperationManagerProtocol
let chain: ChainModel

init(operationManager: OperationManagerProtocol) {
init(chain: ChainModel, operationManager: OperationManagerProtocol) {
self.operationManager = operationManager
self.chain = chain
}

private func createBagsListResolutionOperation(
Expand Down Expand Up @@ -54,6 +56,10 @@ final class VotersInfoOperationFactory {
private func createMaxElectingVotersOperation(
dependingOn codingFactoryOperation: BaseOperation<RuntimeCoderFactoryProtocol>
) -> BaseOperation<UInt32> {
if let maxElectingVoter = chain.stakingMaxElectingVoters {
return BaseOperation.createWithResult(maxElectingVoter)
}

let valueOperation = PrimitiveConstantOperation<UInt32>(
path: ElectionProviderMultiPhase.maxElectingVoters,
fallbackValue: UInt32.max
Expand Down

0 comments on commit 1f500df

Please sign in to comment.