Council -> consts (#1531)
* Council -> consts * Additional info, expose Balance * Types
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { AccountId, BlockNumber, SetIndex, VoteIndex } from '@polkadot/types/interfaces';
|
||||
import { AccountId, Balance, BlockNumber, SetIndex, VoteIndex } from '@polkadot/types/interfaces';
|
||||
import { Codec } from '@polkadot/types/types';
|
||||
|
||||
import { Observable, combineLatest } from 'rxjs';
|
||||
@@ -16,16 +16,13 @@ import { drr } from '../util/drr';
|
||||
type ResultElectionsInner = [u32, u32, Vec<[AccountId, BlockNumber] & Codec>, SetIndex, BlockNumber, VoteIndex, SetIndex];
|
||||
type ResultElections = [Vec<AccountId>, ResultElectionsInner];
|
||||
|
||||
type ResultPhragmenInner = [u32, Vec<AccountId>, BlockNumber];
|
||||
type ResultPhragmen = [Vec<AccountId>, ResultPhragmenInner];
|
||||
|
||||
function deriveElections ([candidates, [candidateCount, desiredSeats, members, nextVoterSet, termDuration, voteCount, voterCount]]: ResultElections): DerivedElectionsInfo {
|
||||
return {
|
||||
candidates,
|
||||
candidateCount,
|
||||
desiredSeats,
|
||||
nextVoterSet,
|
||||
members: members.map(([accountId]): AccountId => accountId),
|
||||
members: members.map(([accountId]): [AccountId, Balance] => [accountId, createType('Balance')]),
|
||||
termDuration,
|
||||
voteCount,
|
||||
voterCount
|
||||
@@ -48,13 +45,15 @@ function queryElections (api: ApiInterfaceRx): Observable<DerivedElectionsInfo>
|
||||
]).pipe(map(deriveElections), drr());
|
||||
}
|
||||
|
||||
function derivePhragmen ([candidates, [desiredMembers, members, termDuration]]: ResultPhragmen): DerivedElectionsInfo {
|
||||
function derivePhragmen (candidates: Vec<AccountId>, members: Vec<[AccountId, Balance] & Codec>, candidacyBond: Balance, desiredSeats: u32, termDuration: BlockNumber, votingBond: Balance): DerivedElectionsInfo {
|
||||
return {
|
||||
candidates,
|
||||
candidateCount: createType('u32', candidates.length),
|
||||
desiredSeats: desiredMembers,
|
||||
candidacyBond,
|
||||
desiredSeats,
|
||||
members,
|
||||
termDuration
|
||||
termDuration,
|
||||
votingBond
|
||||
};
|
||||
}
|
||||
|
||||
@@ -62,12 +61,18 @@ function queryPhragmen (api: ApiInterfaceRx): Observable<DerivedElectionsInfo> {
|
||||
// NOTE We have an issue where candidates can return `null` for an empty array
|
||||
return combineLatest([
|
||||
api.query.electionsPhragmen.candidates<Vec<AccountId>>(),
|
||||
api.queryMulti<ResultPhragmenInner>([
|
||||
api.query.electionsPhragmen.desiredMembers,
|
||||
api.query.electionsPhragmen.members,
|
||||
api.query.electionsPhragmen.termDuration
|
||||
])
|
||||
]).pipe(map(derivePhragmen), drr());
|
||||
api.query.electionsPhragmen.members<Vec<[AccountId, Balance] & Codec>>()
|
||||
]).pipe(
|
||||
map(([candidates, members]): DerivedElectionsInfo => derivePhragmen(
|
||||
candidates,
|
||||
members,
|
||||
api.consts.electionsPhragmen.candidacyBond as Balance,
|
||||
api.consts.electionsPhragmen.desiredMembers as u32,
|
||||
api.consts.electionsPhragmen.termDuration as BlockNumber,
|
||||
api.consts.electionsPhragmen.votingBond as Balance
|
||||
)),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,12 +40,14 @@ export interface DerivedContractFees {
|
||||
export interface DerivedElectionsInfo {
|
||||
candidates: AccountId[];
|
||||
candidateCount: u32;
|
||||
candidacyBond?: Balance;
|
||||
desiredSeats: u32;
|
||||
members: AccountId[];
|
||||
members: [AccountId, Balance][];
|
||||
nextVoterSet?: SetIndex;
|
||||
termDuration: BlockNumber;
|
||||
voteCount?: VoteIndex;
|
||||
voterCount?: SetIndex;
|
||||
votingBond?: Balance;
|
||||
}
|
||||
|
||||
export interface DerivedFees {
|
||||
|
||||
Reference in New Issue
Block a user