Remove capabilities (#4303)

This commit is contained in:
Jaco
2021-12-08 20:18:38 +02:00
committed by GitHub
parent fd6ba08f58
commit dcb7760a0e
6 changed files with 33 additions and 260 deletions
+19 -41
View File
@@ -122,54 +122,32 @@ function getModuleInstances (api: ApiInterfaceRx, specName: string, moduleName:
*/
/** @internal */
function injectFunctions (instanceId: string, api: ApiInterfaceRx, derives: DeriveCustom): ExactDerive {
const queryKeys = Object.keys(api.query);
const specName = api.runtimeVersion.specName.toString();
const filterQueryKeys = (q: string) =>
queryKeys.includes(q);
const filterInstances = (q: string) =>
getModuleInstances(api, specName, q).some(filterQueryKeys);
const filterMethods = (instances: string[]) =>
(m: string) =>
instances.some((q) =>
queryKeys.includes(q) &&
!!api.query[q][m]
);
const isIncluded = (s: string) => (
!checks[s] ||
(
(
checks[s].instances.some(filterQueryKeys) &&
(
!checks[s].methods.length ||
checks[s].methods.every(filterMethods(checks[s].instances))
)
) ||
(
checks[s].withDetect &&
checks[s].instances.some(filterInstances)
)
)
);
const getKeys = (section: string) =>
Object.keys(derives[section]);
const creator = (section: string, method: string) =>
derives[section][method](instanceId, api);
const result: Record<string, Record<string, AnyFunction>> = {};
const names = Object.keys(derives);
const keys = Object.keys(api.query);
const specName = api.runtimeVersion.specName.toString();
const filterKeys = (q: string) => keys.includes(q);
const filterInstances = (q: string) => getModuleInstances(api, specName, q).some(filterKeys);
const filterMethods = (all: string[]) => (m: string) => all.some((q) => keys.includes(q) && api.query[q][m]);
const getKeys = (s: string) => Object.keys(derives[s]);
const creator = (s: string, m: string) => derives[s][m](instanceId, api);
const isIncluded = (c: string) => (!checks[c] || (
(checks[c].instances.some(filterKeys) && (
!checks[c].methods.length ||
checks[c].methods.every(filterMethods(checks[c].instances))
)) ||
(
checks[c].withDetect &&
checks[c].instances.some(filterInstances)
)
));
for (let i = 0; i < names.length; i++) {
const name = names[i];
if (isIncluded(name)) {
isIncluded(name) &&
lazyDeriveSection(result, name, getKeys, creator);
}
}
return result as ExactDerive;
+6 -4
View File
@@ -6,6 +6,10 @@ import type { AccountId, Balance, BlockNumber, Hash, PropIndex, Proposal, Refere
import type { PalletDemocracyReferendumStatus, PalletDemocracyVoteThreshold } from '@polkadot/types/lookup';
import type { BN } from '@polkadot/util';
export interface AtBlock {
at: BlockNumber;
}
export interface DeriveDemocracyLock {
balance: Balance;
isDelegated: boolean;
@@ -16,15 +20,13 @@ export interface DeriveDemocracyLock {
vote: Vote;
}
export interface DeriveProposalImage {
at: BlockNumber;
export interface DeriveProposalImage extends AtBlock {
balance: Balance;
proposal?: Proposal;
proposer: AccountId;
}
export interface DeriveDispatch {
at: BlockNumber;
export interface DeriveDispatch extends AtBlock {
index: ReferendumIndex;
imageHash: Hash;
image?: DeriveProposalImage;