From b5e37c020de2b7a921749fa8fde622961ff82ac6 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Mon, 28 Dec 2020 15:02:27 +0100 Subject: [PATCH] Call return is CallBase (w/ method, section) (#2996) * Call return is CallBase (w/ method, section) * Remove {section, method}Name * mthod/section * compare via .is --- packages/api-derive/src/treasury/proposals.ts | 14 ++++++------ packages/types/src/extrinsic/Extrinsic.ts | 6 ++--- packages/types/src/generic/Call.ts | 22 ++++--------------- packages/types/src/types/calls.ts | 6 +---- 4 files changed, 15 insertions(+), 33 deletions(-) diff --git a/packages/api-derive/src/treasury/proposals.ts b/packages/api-derive/src/treasury/proposals.ts index ed83266b7f..ef3979c05c 100644 --- a/packages/api-derive/src/treasury/proposals.ts +++ b/packages/api-derive/src/treasury/proposals.ts @@ -20,20 +20,20 @@ interface Result { proposalCount: ProposalIndex; } -function parseResult (_api: ApiInterfaceRx, { allIds, allProposals, approvalIds, councilProposals, proposalCount }: Result): DeriveTreasuryProposals { +function parseResult (api: ApiInterfaceRx, { allIds, allProposals, approvalIds, councilProposals, proposalCount }: Result): DeriveTreasuryProposals { const approvals: DeriveTreasuryProposal[] = []; const proposals: DeriveTreasuryProposal[] = []; - const councilTreasury = councilProposals.filter(({ proposal: { methodName, sectionName } }): boolean => - sectionName === 'treasury' && - ['approveProposal', 'rejectProposal'].includes(methodName) + const councilTreasury = councilProposals.filter(({ proposal }) => + api.tx.treasury.approveProposal.is(proposal) || + api.tx.treasury.rejectProposal.is(proposal) ); allIds.forEach((id, index): void => { if (allProposals[index].isSome) { const council = councilTreasury - .filter(({ proposal }): boolean => id.eq(proposal.args[0])) - .sort((a, b): number => a.proposal.methodName.localeCompare(b.proposal.methodName)); - const isApproval = approvalIds.some((approvalId): boolean => approvalId.eq(id)); + .filter(({ proposal }) => id.eq(proposal.args[0])) + .sort((a, b) => a.proposal.method.localeCompare(b.proposal.method)); + const isApproval = approvalIds.some((approvalId) => approvalId.eq(id)); const derived = { council, id, proposal: allProposals[index].unwrap() }; if (isApproval) { diff --git a/packages/types/src/extrinsic/Extrinsic.ts b/packages/types/src/extrinsic/Extrinsic.ts index 3f9c63c537..9b7ea11b62 100644 --- a/packages/types/src/extrinsic/Extrinsic.ts +++ b/packages/types/src/extrinsic/Extrinsic.ts @@ -4,7 +4,7 @@ import type { EcdsaSignature, Ed25519Signature, ExtrinsicUnknown, ExtrinsicV4, Sr25519Signature } from '../interfaces/extrinsics'; import type { FunctionMetadataLatest } from '../interfaces/metadata/types'; import type { Address, Balance, Call, Index } from '../interfaces/runtime'; -import type { AnyJson, AnyTuple, AnyU8a, ArgsDef, ExtrinsicPayloadValue, IExtrinsic, IKeyringPair, IMethod, InterfaceTypes, Registry, SignatureOptions } from '../types'; +import type { AnyJson, AnyTuple, AnyU8a, ArgsDef, CallBase, ExtrinsicPayloadValue, IExtrinsic, IKeyringPair, IMethod, InterfaceTypes, Registry, SignatureOptions } from '../types'; import type { GenericExtrinsicEra } from './ExtrinsicEra'; import type { ExtrinsicValueV4 } from './v4/Extrinsic'; @@ -101,8 +101,8 @@ abstract class ExtrinsicBase extends Base { - return (this._raw as ExtrinsicVx).method as unknown as IMethod; + public get method (): CallBase { + return (this._raw as ExtrinsicVx).method as unknown as CallBase; } /** diff --git a/packages/types/src/generic/Call.ts b/packages/types/src/generic/Call.ts index ce687e4fa3..b0e9326f8f 100644 --- a/packages/types/src/generic/Call.ts +++ b/packages/types/src/generic/Call.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import type { FunctionArgumentMetadataLatest, FunctionMetadataLatest } from '../interfaces/metadata'; -import type { AnyJson, AnyTuple, AnyU8a, ArgsDef, CallFunction, IMethod, Registry } from '../types'; +import type { AnyJson, AnyTuple, AnyU8a, ArgsDef, CallBase, CallFunction, IMethod, Registry } from '../types'; import { isHex, isObject, isU8a, u8aToU8a } from '@polkadot/util'; @@ -117,7 +117,7 @@ export class GenericCallIndex extends U8aFixed { * @description * Extrinsic function descriptor */ -export class GenericCall extends Struct implements IMethod { +export class GenericCall extends Struct implements CallBase { protected _meta: FunctionMetadataLatest; constructor (registry: Registry, value: unknown, meta?: FunctionMetadataLatest) { @@ -192,32 +192,18 @@ export class GenericCall extends Struct implement return this._meta; } - /** - * @description Returns the name of the method - */ - public get methodName (): string { - return this.registry.findMetaCall(this.callIndex).method; - } - /** * @description Returns the name of the method */ public get method (): string { - return this.methodName; - } - - /** - * @description Returns the module containing the method - */ - public get sectionName (): string { - return this.registry.findMetaCall(this.callIndex).section; + return this.registry.findMetaCall(this.callIndex).method; } /** * @description Returns the module containing the method */ public get section (): string { - return this.sectionName; + return this.registry.findMetaCall(this.callIndex).section; } /** diff --git a/packages/types/src/types/calls.ts b/packages/types/src/types/calls.ts index e1dc1cbb57..62946981d9 100644 --- a/packages/types/src/types/calls.ts +++ b/packages/types/src/types/calls.ts @@ -1,18 +1,14 @@ // Copyright 2017-2020 @polkadot/types authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { FunctionMetadataLatest } from '../interfaces/metadata'; import type { Call } from '../interfaces/runtime'; import type { AnyTuple } from './codec'; import type { IMethod } from './interfaces'; -export interface CallBase { - readonly callIndex: Uint8Array; - readonly meta: FunctionMetadataLatest; +export interface CallBase extends IMethod { readonly method: string; readonly section: string; - is: (tx: IMethod) => tx is IMethod; toJSON: () => any; }