Call return is CallBase (w/ method, section) (#2996)

* Call return is CallBase (w/ method, section)

* Remove {section, method}Name

* mthod/section

* compare via .is
This commit is contained in:
Jaco Greeff
2020-12-28 15:02:27 +01:00
committed by GitHub
parent a806e4a2ee
commit b5e37c020d
4 changed files with 15 additions and 33 deletions
@@ -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) {
+3 -3
View File
@@ -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<A extends AnyTuple> extends Base<ExtrinsicVx | Extr
/**
* @description The [[Call]] this extrinsic wraps
*/
public get method (): IMethod<A> {
return (this._raw as ExtrinsicVx).method as unknown as IMethod<A>;
public get method (): CallBase<A> {
return (this._raw as ExtrinsicVx).method as unknown as CallBase<A>;
}
/**
+4 -18
View File
@@ -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<A extends AnyTuple = AnyTuple> extends Struct implements IMethod<A> {
export class GenericCall<A extends AnyTuple = AnyTuple> extends Struct implements CallBase<A> {
protected _meta: FunctionMetadataLatest;
constructor (registry: Registry, value: unknown, meta?: FunctionMetadataLatest) {
@@ -192,32 +192,18 @@ export class GenericCall<A extends AnyTuple = AnyTuple> 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;
}
/**
+1 -5
View File
@@ -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<A extends AnyTuple> {
readonly callIndex: Uint8Array;
readonly meta: FunctionMetadataLatest;
export interface CallBase<A extends AnyTuple> extends IMethod<A> {
readonly method: string;
readonly section: string;
is: (tx: IMethod<AnyTuple>) => tx is IMethod<A>;
toJSON: () => any;
}