Bump static metadata (#5717)
* Bump static metadata * Adjust society candidate retrieval * Fix society member retrieval * Rebuild * Build runtime * Adjust types * Extract re-used types
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { Option, u32, WrapperOpaque } from '@polkadot/types';
|
||||
import type { Option, u32 } from '@polkadot/types';
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
import type { PalletImOnlineBoundedOpaqueNetworkState } from '@polkadot/types/lookup';
|
||||
import type { Codec } from '@polkadot/types/types';
|
||||
import type { DeriveApi, DeriveHeartbeats } from '../types.js';
|
||||
|
||||
import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
@@ -13,9 +13,9 @@ import { BN_ZERO } from '@polkadot/util';
|
||||
|
||||
import { memo } from '../util/index.js';
|
||||
|
||||
type HeartbeatsOpt = Option<WrapperOpaque<PalletImOnlineBoundedOpaqueNetworkState>>;
|
||||
type Result = [DeriveHeartbeats, AccountId[], Option<Codec>[], u32[]];
|
||||
|
||||
function mapResult ([result, validators, heartbeats, numBlocks]: [DeriveHeartbeats, AccountId[], HeartbeatsOpt[], u32[]]): DeriveHeartbeats {
|
||||
function mapResult ([result, validators, heartbeats, numBlocks]: Result): DeriveHeartbeats {
|
||||
validators.forEach((validator, index): void => {
|
||||
const validatorId = validator.toString();
|
||||
const blockCount = numBlocks[index];
|
||||
@@ -41,7 +41,7 @@ export function receivedHeartbeats (instanceId: string, api: DeriveApi): () => O
|
||||
return memo(instanceId, (): Observable<DeriveHeartbeats> =>
|
||||
api.query.imOnline?.receivedHeartbeats
|
||||
? api.derive.staking.overview().pipe(
|
||||
switchMap(({ currentIndex, validators }): Observable<[DeriveHeartbeats, AccountId[], HeartbeatsOpt[], u32[]]> =>
|
||||
switchMap(({ currentIndex, validators }): Observable<Result> =>
|
||||
combineLatest([
|
||||
of({}),
|
||||
of(validators),
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { BalanceOf } from '@polkadot/types/interfaces';
|
||||
import type { PalletSocietyBid, PalletSocietyBidKind } from '@polkadot/types/lookup';
|
||||
import type { AccountId32, BalanceOf } from '@polkadot/types/interfaces';
|
||||
import type { PalletSocietyBid, PalletSocietyBidKind, PalletSocietyCandidacy } from '@polkadot/types/lookup';
|
||||
import type { ITuple } from '@polkadot/types/types';
|
||||
import type { Option } from '@polkadot/types-codec';
|
||||
import type { Option, Vec } from '@polkadot/types-codec';
|
||||
import type { DeriveApi, DeriveSocietyCandidate } from '../types.js';
|
||||
|
||||
import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
@@ -15,28 +15,51 @@ import { memo } from '../util/index.js';
|
||||
type ResultSuspend = Option<ITuple<[BalanceOf, PalletSocietyBidKind]>>;
|
||||
type Result = [PalletSocietyBid[], ResultSuspend[]]
|
||||
|
||||
function getPrev (api: DeriveApi): Observable<DeriveSocietyCandidate[]> {
|
||||
return api.query.society.candidates<Vec<PalletSocietyBid>>().pipe(
|
||||
switchMap((candidates): Observable<Result> =>
|
||||
combineLatest([
|
||||
of(candidates),
|
||||
api.query.society['suspendedCandidates'].multi<Option<ITuple<[BalanceOf, PalletSocietyBidKind]>>>(
|
||||
candidates.map(({ who }) => who)
|
||||
)
|
||||
])
|
||||
),
|
||||
map(([candidates, suspended]: Result): DeriveSocietyCandidate[] =>
|
||||
candidates.map(({ kind, value, who }, index) => ({
|
||||
accountId: who,
|
||||
isSuspended: suspended[index].isSome,
|
||||
kind,
|
||||
value
|
||||
}))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function getCurr (api: DeriveApi) {
|
||||
return api.query.society.candidates.entries().pipe(
|
||||
map((entries) =>
|
||||
entries
|
||||
.filter(([, opt]) => opt.isSome)
|
||||
.map(([{ args: [accountId] }, opt]): [AccountId32, PalletSocietyCandidacy] => [accountId, opt.unwrap()])
|
||||
// FIXME We are missing the new fields from the candidate record
|
||||
.map(([accountId, { bid, kind }]) => ({
|
||||
accountId,
|
||||
isSuspended: false,
|
||||
kind,
|
||||
value: bid
|
||||
}))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get the candidate info for a society
|
||||
*/
|
||||
export function candidates (instanceId: string, api: DeriveApi): () => Observable<DeriveSocietyCandidate[]> {
|
||||
return memo(instanceId, (): Observable<DeriveSocietyCandidate[]> =>
|
||||
api.query.society.candidates().pipe(
|
||||
switchMap((candidates): Observable<Result> =>
|
||||
combineLatest([
|
||||
of(candidates),
|
||||
api.query.society.suspendedCandidates.multi(
|
||||
candidates.map(({ who }) => who)
|
||||
)
|
||||
])
|
||||
),
|
||||
map(([candidates, suspended]: Result): DeriveSocietyCandidate[] =>
|
||||
candidates.map(({ kind, value, who }, index) => ({
|
||||
accountId: who,
|
||||
isSuspended: suspended[index].isSome,
|
||||
kind,
|
||||
value
|
||||
}))
|
||||
)
|
||||
)
|
||||
api.query.society['suspendedCandidates'] && api.query.society.candidates.creator.meta.type.isPlain
|
||||
? getPrev(api)
|
||||
: getCurr(api)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,30 +7,34 @@ import type { AccountId, BalanceOf } from '@polkadot/types/interfaces';
|
||||
import type { PalletSocietyBid } from '@polkadot/types/lookup';
|
||||
import type { DeriveApi, DeriveSociety } from '../types.js';
|
||||
|
||||
import { map } from 'rxjs';
|
||||
import { combineLatest, map, of } from 'rxjs';
|
||||
|
||||
import { memo } from '../util/index.js';
|
||||
|
||||
type Result = [Vec<PalletSocietyBid>, Option<AccountId>, Option<AccountId>, Option<AccountId>, u32, BalanceOf]
|
||||
type Result = [Vec<PalletSocietyBid>, Option<AccountId> | undefined, Option<AccountId>, Option<AccountId>, u32 | undefined, BalanceOf]
|
||||
|
||||
/**
|
||||
* @description Get the overall info for a society
|
||||
*/
|
||||
export function info (instanceId: string, api: DeriveApi): () => Observable<DeriveSociety> {
|
||||
return memo(instanceId, (): Observable<DeriveSociety> =>
|
||||
api.queryMulti<Result>([
|
||||
api.query.society.bids,
|
||||
api.query.society.defender,
|
||||
api.query.society.founder,
|
||||
api.query.society.head,
|
||||
api.query.society.maxMembers,
|
||||
api.query.society.pot
|
||||
combineLatest<Result>([
|
||||
api.query.society.bids(),
|
||||
api.query.society['defender']
|
||||
? api.query.society['defender']<Option<AccountId>>()
|
||||
: of(undefined),
|
||||
api.query.society.founder(),
|
||||
api.query.society.head(),
|
||||
api.query.society['maxMembers']
|
||||
? api.query.society['maxMembers']<u32>()
|
||||
: of(undefined),
|
||||
api.query.society.pot()
|
||||
]).pipe(
|
||||
map(([bids, defender, founder, head, maxMembers, pot]: Result): DeriveSociety => ({
|
||||
bids,
|
||||
defender: defender.unwrapOr(undefined),
|
||||
defender: defender?.unwrapOr(undefined),
|
||||
founder: founder.unwrapOr(undefined),
|
||||
hasDefender: (defender.isSome && head.isSome && !head.eq(defender)) || false,
|
||||
hasDefender: (defender?.isSome && head.isSome && !head.eq(defender)) || false,
|
||||
head: head.unwrapOr(undefined),
|
||||
maxMembers,
|
||||
pot
|
||||
|
||||
@@ -3,34 +3,79 @@
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
import type { PalletSocietyVote, PalletSocietyVouchingStatus } from '@polkadot/types/lookup';
|
||||
import type { ITuple } from '@polkadot/types/types';
|
||||
import type { bool, Option, u32, u128, Vec } from '@polkadot/types-codec';
|
||||
import type { DeriveApi, DeriveSocietyMember } from '../types.js';
|
||||
|
||||
import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
import { memo } from '../util/index.js';
|
||||
|
||||
function _membersPrev (api: DeriveApi, accountIds: AccountId[]): Observable<DeriveSocietyMember[]> {
|
||||
return combineLatest([
|
||||
of(accountIds),
|
||||
api.query.society.payouts.multi<Vec<ITuple<[u32, u128]>>>(accountIds),
|
||||
api.query.society['strikes'].multi<u32>(accountIds),
|
||||
api.query.society.defenderVotes.multi<Option<PalletSocietyVote>>(accountIds),
|
||||
api.query.society.suspendedMembers.multi<bool>(accountIds),
|
||||
api.query.society['vouching'].multi<Option<PalletSocietyVouchingStatus>>(accountIds)
|
||||
]).pipe(
|
||||
map(([accountIds, payouts, strikes, defenderVotes, suspended, vouching]) =>
|
||||
accountIds.map((accountId, index) => ({
|
||||
accountId,
|
||||
isDefenderVoter: defenderVotes[index].isSome,
|
||||
isSuspended: suspended[index].isTrue,
|
||||
payouts: payouts[index],
|
||||
strikes: strikes[index],
|
||||
vote: defenderVotes[index].unwrapOr(undefined),
|
||||
vouching: vouching[index].unwrapOr(undefined)
|
||||
}))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function _membersCurr (api: DeriveApi, accountIds: AccountId[]): Observable<DeriveSocietyMember[]> {
|
||||
return combineLatest([
|
||||
of(accountIds),
|
||||
api.query.society.members.multi(accountIds),
|
||||
api.query.society.payouts.multi(accountIds),
|
||||
api.query.society.defenderVotes.multi(accountIds),
|
||||
api.query.society.suspendedMembers.multi(accountIds)
|
||||
]).pipe(
|
||||
map(([accountIds, members, payouts, defenderVotes, suspendedMembers]) =>
|
||||
accountIds
|
||||
.map((accountId, index) =>
|
||||
members[index].isSome
|
||||
? {
|
||||
accountId,
|
||||
isDefenderVoter: defenderVotes[index].isSome
|
||||
? defenderVotes[index].unwrap().approve.isTrue
|
||||
: false,
|
||||
isSuspended: suspendedMembers[index].isSome,
|
||||
member: members[index].unwrap(),
|
||||
payouts: payouts[index].payouts
|
||||
}
|
||||
: null
|
||||
)
|
||||
.filter((m): m is NonNullable<typeof m> => !!m)
|
||||
.map(({ accountId, isDefenderVoter, isSuspended, member, payouts }) => ({
|
||||
accountId,
|
||||
isDefenderVoter,
|
||||
isSuspended,
|
||||
payouts,
|
||||
strikes: member.strikes,
|
||||
vouching: member.vouching.unwrapOr(undefined)
|
||||
}))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export function _members (instanceId: string, api: DeriveApi): (accountIds: AccountId[]) => Observable<DeriveSocietyMember[]> {
|
||||
return memo(instanceId, (accountIds: AccountId[]): Observable<DeriveSocietyMember[]> =>
|
||||
combineLatest([
|
||||
of(accountIds),
|
||||
api.query.society.payouts.multi(accountIds),
|
||||
api.query.society.strikes.multi(accountIds),
|
||||
api.query.society.defenderVotes.multi(accountIds),
|
||||
api.query.society.suspendedMembers.multi(accountIds),
|
||||
api.query.society.vouching.multi(accountIds)
|
||||
]).pipe(
|
||||
map(([accountIds, payouts, strikes, defenderVotes, suspended, vouching]) =>
|
||||
accountIds.map((accountId, index) => ({
|
||||
accountId,
|
||||
isDefenderVoter: defenderVotes[index].isSome,
|
||||
isSuspended: suspended[index].isTrue,
|
||||
payouts: payouts[index],
|
||||
strikes: strikes[index],
|
||||
vote: defenderVotes[index].unwrapOr(undefined),
|
||||
vouching: vouching[index].unwrapOr(undefined)
|
||||
}))
|
||||
)
|
||||
)
|
||||
api.query.society.members.creator.meta.type.isMap
|
||||
? _membersCurr(api, accountIds)
|
||||
: _membersPrev(api, accountIds)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -39,8 +84,16 @@ export function _members (instanceId: string, api: DeriveApi): (accountIds: Acco
|
||||
*/
|
||||
export function members (instanceId: string, api: DeriveApi): () => Observable<DeriveSocietyMember[]> {
|
||||
return memo(instanceId, (): Observable<DeriveSocietyMember[]> =>
|
||||
api.query.society.members().pipe(
|
||||
switchMap((members) => api.derive.society._members(members))
|
||||
)
|
||||
api.query.society.members.creator.meta.type.isMap
|
||||
? api.query.society.members.keys().pipe(
|
||||
switchMap((keys) =>
|
||||
api.derive.society._members(
|
||||
keys.map(({ args: [accountId] }) => accountId)
|
||||
)
|
||||
)
|
||||
)
|
||||
: api.query.society.members<Vec<AccountId>>().pipe(
|
||||
switchMap((members) => api.derive.society._members(members))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ export interface DeriveSociety {
|
||||
hasDefender: boolean;
|
||||
head?: AccountId | undefined;
|
||||
founder?: AccountId | undefined;
|
||||
maxMembers: u32;
|
||||
maxMembers?: u32 | undefined;
|
||||
pot: BalanceOf;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user