Bump to latest Substrate metadata (#5807)
* Bump to latest substrate metadata * Bump to latest Substrate metadata * Update type-support docs for metadata * Update docs again * fix compat issues * adjust types
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { Data } from '@polkadot/types';
|
||||
import type { Bytes, Data } from '@polkadot/types';
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
import type { PalletIdentityIdentityInfo, PalletIdentityRegistration } from '@polkadot/types/lookup';
|
||||
import type { Option } from '@polkadot/types-codec';
|
||||
@@ -40,12 +40,21 @@ function extractOther (additional: IdentityInfoAdditional[]): Record<string, str
|
||||
}, {});
|
||||
}
|
||||
|
||||
function extractIdentity (identityOfOpt?: Option<PalletIdentityRegistration>, superOf?: [AccountId, Data]): DeriveAccountRegistration {
|
||||
// handle compatibility between generations of structures
|
||||
function identityCompat (identityOfOpt: Option<ITuple<[PalletIdentityRegistration, Option<Bytes>]>> | Option<PalletIdentityRegistration>): PalletIdentityRegistration {
|
||||
const identity = identityOfOpt.unwrap();
|
||||
|
||||
return Array.isArray(identity)
|
||||
? identity[0]
|
||||
: identity;
|
||||
}
|
||||
|
||||
function extractIdentity (identityOfOpt?: Option<ITuple<[PalletIdentityRegistration, Option<Bytes>]>> | Option<PalletIdentityRegistration>, superOf?: [AccountId, Data]): DeriveAccountRegistration {
|
||||
if (!identityOfOpt?.isSome) {
|
||||
return { judgements: [] };
|
||||
}
|
||||
|
||||
const { info, judgements } = identityOfOpt.unwrap();
|
||||
const { info, judgements } = identityCompat(identityOfOpt);
|
||||
const topDisplay = dataAsString(info.display);
|
||||
|
||||
return {
|
||||
@@ -64,7 +73,7 @@ function extractIdentity (identityOfOpt?: Option<PalletIdentityRegistration>, su
|
||||
};
|
||||
}
|
||||
|
||||
function getParent (api: DeriveApi, identityOfOpt: Option<PalletIdentityRegistration> | undefined, superOfOpt: Option<ITuple<[AccountId, Data]>> | undefined): Observable<[Option<PalletIdentityRegistration> | undefined, [AccountId, Data] | undefined]> {
|
||||
function getParent (api: DeriveApi, identityOfOpt: Option<ITuple<[PalletIdentityRegistration, Option<Bytes>]>> | Option<PalletIdentityRegistration> | undefined, superOfOpt: Option<ITuple<[AccountId, Data]>> | undefined): Observable<[Option<ITuple<[PalletIdentityRegistration, Option<Bytes>]>> | Option<PalletIdentityRegistration> | undefined, [AccountId, Data] | undefined]> {
|
||||
if (identityOfOpt?.isSome) {
|
||||
// this identity has something set
|
||||
return of([identityOfOpt, undefined]);
|
||||
@@ -83,8 +92,8 @@ function getParent (api: DeriveApi, identityOfOpt: Option<PalletIdentityRegistra
|
||||
return of([undefined, undefined]);
|
||||
}
|
||||
|
||||
export function _identity (instanceId: string, api: DeriveApi): (accountId?: AccountId | Uint8Array | string) => Observable<[Option<PalletIdentityRegistration> | undefined, Option<ITuple<[AccountId, Data]>> | undefined]> {
|
||||
return memo(instanceId, (accountId?: AccountId | Uint8Array | string): Observable<[Option<PalletIdentityRegistration> | undefined, Option<ITuple<[AccountId, Data]>> | undefined]> =>
|
||||
export function _identity (instanceId: string, api: DeriveApi): (accountId?: AccountId | Uint8Array | string) => Observable<[Option<ITuple<[PalletIdentityRegistration, Option<Bytes>]>> | Option<PalletIdentityRegistration> | undefined, Option<ITuple<[AccountId, Data]>> | undefined]> {
|
||||
return memo(instanceId, (accountId?: AccountId | Uint8Array | string): Observable<[Option<ITuple<[PalletIdentityRegistration, Option<Bytes>]>> | Option<PalletIdentityRegistration> | undefined, Option<ITuple<[AccountId, Data]>> | undefined]> =>
|
||||
accountId && api.query.identity?.identityOf
|
||||
? combineLatest([
|
||||
api.query.identity.identityOf(accountId),
|
||||
@@ -132,7 +141,7 @@ export function hasIdentityMulti (instanceId: string, api: DeriveApi): (accountI
|
||||
let display: string | undefined;
|
||||
|
||||
if (identityOfOpt && identityOfOpt.isSome) {
|
||||
const value = dataAsString(identityOfOpt.unwrap().info.display);
|
||||
const value = dataAsString(identityCompat(identityOfOpt).info.display);
|
||||
|
||||
if (value && !isHex(value)) {
|
||||
display = value;
|
||||
|
||||
@@ -11,7 +11,15 @@ import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
import { firstMemo, memo } from '../util/index.js';
|
||||
|
||||
function parseDetails (stashId: AccountId, controllerIdOpt: Option<AccountId> | null, nominatorsOpt: Option<PalletStakingNominations>, rewardDestination: PalletStakingRewardDestination, validatorPrefs: PalletStakingValidatorPrefs, exposure: PalletStakingExposure, stakingLedgerOpt: Option<PalletStakingStakingLedger>): DeriveStakingQuery {
|
||||
// handle compatibility between generations of structures
|
||||
function rewardDestinationCompat (rewardDestination: PalletStakingRewardDestination | Option<PalletStakingRewardDestination>): PalletStakingRewardDestination | null {
|
||||
// We ensure the type is an Option by checking if isSome is a boolean. When isSome doesn't exist it will always return undefined.
|
||||
return typeof (rewardDestination as Option<PalletStakingRewardDestination>).isSome === 'boolean'
|
||||
? (rewardDestination as Option<PalletStakingRewardDestination>).unwrapOr(null)
|
||||
: (rewardDestination as PalletStakingRewardDestination);
|
||||
}
|
||||
|
||||
function parseDetails (stashId: AccountId, controllerIdOpt: Option<AccountId> | null, nominatorsOpt: Option<PalletStakingNominations>, rewardDestinationOpts: Option<PalletStakingRewardDestination> | PalletStakingRewardDestination, validatorPrefs: PalletStakingValidatorPrefs, exposure: PalletStakingExposure, stakingLedgerOpt: Option<PalletStakingStakingLedger>): DeriveStakingQuery {
|
||||
return {
|
||||
accountId: stashId,
|
||||
controllerId: controllerIdOpt?.unwrapOr(null) || null,
|
||||
@@ -19,7 +27,7 @@ function parseDetails (stashId: AccountId, controllerIdOpt: Option<AccountId> |
|
||||
nominators: nominatorsOpt.isSome
|
||||
? nominatorsOpt.unwrap().targets
|
||||
: [],
|
||||
rewardDestination,
|
||||
rewardDestination: rewardDestinationCompat(rewardDestinationOpts),
|
||||
stakingLedger: stakingLedgerOpt.unwrapOrDefault(),
|
||||
stashId,
|
||||
validatorPrefs
|
||||
@@ -49,9 +57,9 @@ function getLedgers (api: DeriveApi, optIds: (Option<AccountId> | null)[], { wit
|
||||
);
|
||||
}
|
||||
|
||||
function getStashInfo (api: DeriveApi, stashIds: AccountId[], activeEra: EraIndex, { withController, withDestination, withExposure, withLedger, withNominations, withPrefs }: StakingQueryFlags): Observable<[(Option<AccountId> | null)[], Option<PalletStakingNominations>[], PalletStakingRewardDestination[], PalletStakingValidatorPrefs[], PalletStakingExposure[]]> {
|
||||
function getStashInfo (api: DeriveApi, stashIds: AccountId[], activeEra: EraIndex, { withController, withDestination, withExposure, withLedger, withNominations, withPrefs }: StakingQueryFlags): Observable<[(Option<AccountId> | null)[], Option<PalletStakingNominations>[], Option<PalletStakingRewardDestination>[], PalletStakingValidatorPrefs[], PalletStakingExposure[]]> {
|
||||
const emptyNoms = api.registry.createType<Option<PalletStakingNominations>>('Option<Nominations>');
|
||||
const emptyRewa = api.registry.createType<PalletStakingRewardDestination>('RewardDestination');
|
||||
const emptyRewa = api.registry.createType<Option<PalletStakingRewardDestination>>('RewardDestination');
|
||||
const emptyExpo = api.registry.createType<PalletStakingExposure>('Exposure');
|
||||
const emptyPrefs = api.registry.createType<PalletStakingValidatorPrefs>('ValidatorPrefs');
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ export interface DeriveStakingStash {
|
||||
controllerId: AccountId | null;
|
||||
exposure: PalletStakingExposure;
|
||||
nominators: AccountId[];
|
||||
rewardDestination: PalletStakingRewardDestination;
|
||||
rewardDestination: PalletStakingRewardDestination | null;
|
||||
stashId: AccountId;
|
||||
validatorPrefs: PalletStakingValidatorPrefs;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user