diff --git a/packages/api/src/types/augment/tx.ts b/packages/api/src/types/augment/tx.ts index 5cdb5030f0..c3fee5820a 100644 --- a/packages/api/src/types/augment/tx.ts +++ b/packages/api/src/types/augment/tx.ts @@ -258,7 +258,7 @@ declare module '@polkadot/api/types/submittable' { * the `origin` falls below _existential deposit_ and gets removed as dust. * # **/ - bond: AugmentedSubmittable<(controller: Address | string | AccountId | AccountIndex | Uint8Array, value: Compact | AnyNumber | Uint8Array, payee: RewardDestination | number | any) => SubmittableExtrinsic>; + bond: AugmentedSubmittable<(controller: Address | string | AccountId | AccountIndex | Uint8Array, value: Compact | AnyNumber | Uint8Array, payee: RewardDestination | ('Staked' | 'Stash' | 'Controller') | number | Uint8Array) => SubmittableExtrinsic>; /** * Add some extra amount that have appeared in the stash `free_balance` into the balance up * for staking. @@ -352,7 +352,7 @@ declare module '@polkadot/api/types/submittable' { * - Writes are limited to the `origin` account key. * # **/ - setPayee: AugmentedSubmittable<(payee: RewardDestination | number | any) => SubmittableExtrinsic>; + setPayee: AugmentedSubmittable<(payee: RewardDestination | ('Staked' | 'Stash' | 'Controller') | number | Uint8Array) => SubmittableExtrinsic>; /** * (Re-)set the controller of a stash. * Effects will be felt at the beginning of the next era. @@ -456,7 +456,7 @@ declare module '@polkadot/api/types/submittable' { * - One DB change, one DB entry. * # **/ - vote: AugmentedSubmittable<(refIndex: Compact | AnyNumber | Uint8Array, vote: Vote | { aye: boolean; conviction?: number | ('None' | 'Locked1x' | 'Locked2x' | 'Locked3x' | 'Locked4x' | 'Locked5x' | 'Locked6x') } | boolean | string | Uint8Array) => SubmittableExtrinsic>; + vote: AugmentedSubmittable<(refIndex: Compact | AnyNumber | Uint8Array, vote: Vote | { aye: boolean; conviction?: ('None' | 'Locked1x' | 'Locked2x' | 'Locked3x' | 'Locked4x' | 'Locked5x' | 'Locked6x') | number } | boolean | string | Uint8Array) => SubmittableExtrinsic>; /** * Vote in a referendum on behalf of a stash. If `vote.is_aye()`, the vote is to enact * the proposal; otherwise it is a vote to keep the status quo. @@ -465,7 +465,7 @@ declare module '@polkadot/api/types/submittable' { * - One DB change, one DB entry. * # **/ - proxyVote: AugmentedSubmittable<(refIndex: Compact | AnyNumber | Uint8Array, vote: Vote | { aye: boolean; conviction?: number | ('None' | 'Locked1x' | 'Locked2x' | 'Locked3x' | 'Locked4x' | 'Locked5x' | 'Locked6x') } | boolean | string | Uint8Array) => SubmittableExtrinsic>; + proxyVote: AugmentedSubmittable<(refIndex: Compact | AnyNumber | Uint8Array, vote: Vote | { aye: boolean; conviction?: ('None' | 'Locked1x' | 'Locked2x' | 'Locked3x' | 'Locked4x' | 'Locked5x' | 'Locked6x') | number } | boolean | string | Uint8Array) => SubmittableExtrinsic>; /** * Schedule an emergency cancellation of a referendum. Cannot happen twice to the same * referendum. @@ -540,7 +540,7 @@ declare module '@polkadot/api/types/submittable' { * - One extra DB entry. * # **/ - delegate: AugmentedSubmittable<(to: AccountId | string | Uint8Array, conviction: Conviction | number | any) => SubmittableExtrinsic>; + delegate: AugmentedSubmittable<(to: AccountId | string | Uint8Array, conviction: Conviction | ('None' | 'Locked1x' | 'Locked2x' | 'Locked3x' | 'Locked4x' | 'Locked5x' | 'Locked6x') | number | Uint8Array) => SubmittableExtrinsic>; /** * Undelegate vote. * # @@ -991,7 +991,7 @@ declare module '@polkadot/api/types/submittable' { * one storage-exists. * # **/ - setSubs: AugmentedSubmittable<(subs: Vec> | ([AccountId | string | Uint8Array, Data | number | any])[]) => SubmittableExtrinsic>; + setSubs: AugmentedSubmittable<(subs: Vec> | ([AccountId | string | Uint8Array, Data | object | number | Uint8Array | string])[]) => SubmittableExtrinsic>; /** * Clear an account's identity info and all sub-account and return all deposits. * Payment: All reserved balances on the account are returned. @@ -1094,7 +1094,7 @@ declare module '@polkadot/api/types/submittable' { * - One event. * # **/ - provideJudgement: AugmentedSubmittable<(regIndex: Compact | AnyNumber | Uint8Array, target: Address | string | AccountId | AccountIndex | Uint8Array, judgement: IdentityJudgement | number | any) => SubmittableExtrinsic>; + provideJudgement: AugmentedSubmittable<(regIndex: Compact | AnyNumber | Uint8Array, target: Address | string | AccountId | AccountIndex | Uint8Array, judgement: IdentityJudgement | object | number | Uint8Array | string) => SubmittableExtrinsic>; /** * Remove an account's identity and sub-account information and slash the deposits. * Payment: Reserved balances from `set_subs` and `set_identity` are slashed and handled by @@ -1360,7 +1360,7 @@ declare module '@polkadot/api/types/submittable' { * Total Complexity: O(M + logM + B + X) * # **/ - judgeSuspendedCandidate: AugmentedSubmittable<(who: AccountId | string | Uint8Array, judgement: SocietyJudgement | number | any) => SubmittableExtrinsic>; + judgeSuspendedCandidate: AugmentedSubmittable<(who: AccountId | string | Uint8Array, judgement: SocietyJudgement | ('Rebid' | 'Reject' | 'Approve') | number | Uint8Array) => SubmittableExtrinsic>; /** * Allows root origin to change the maximum number of members in society. * Max membership count must be greater than 1. diff --git a/packages/rpc-core/src/jsonrpc.types.ts b/packages/rpc-core/src/jsonrpc.types.ts index 054660e2b7..273ef72e85 100644 --- a/packages/rpc-core/src/jsonrpc.types.ts +++ b/packages/rpc-core/src/jsonrpc.types.ts @@ -16,7 +16,7 @@ export interface RpcInterface { author: { insertKey(keyType: Text | string, suri: Text | string, publicKey: Bytes | string | Uint8Array): Observable; pendingExtrinsics(): Observable>; - removeExtrinsic(bytesOrHash: Vec | (ExtrinsicOrHash | number | any)[]): Observable>; + removeExtrinsic(bytesOrHash: Vec | (ExtrinsicOrHash | object | number | Uint8Array | string)[]): Observable>; rotateKeys(): Observable; submitAndWatchExtrinsic(extrinsic: IExtrinsic): Observable; submitExtrinsic(extrinsic: IExtrinsic): Observable; diff --git a/packages/types/src/codec/Enum.ts b/packages/types/src/codec/Enum.ts index c25f9abf09..dad41625b7 100644 --- a/packages/types/src/codec/Enum.ts +++ b/packages/types/src/codec/Enum.ts @@ -182,6 +182,13 @@ export default class Enum extends Base { return this._index; } + /** + * @description true if this is a basic enum (no values) + */ + public get isBasic (): boolean { + return this._isBasic; + } + /** * @description Checks if the Enum points to a [[Null]] type */ @@ -196,11 +203,18 @@ export default class Enum extends Base { return this.raw instanceof Null; } + /** + * @description The available keys for this enum + */ + public get defKeys (): string[] { + return Object.keys(this._def); + } + /** * @description The name of the type this enum value represents */ public get type (): string { - return Object.keys(this._def)[this._index]; + return this.defKeys[this._index]; } /** diff --git a/packages/types/src/scripts/util/derived.ts b/packages/types/src/scripts/util/derived.ts index 1ed711f7d3..ee46f5f1f6 100644 --- a/packages/types/src/scripts/util/derived.ts +++ b/packages/types/src/scripts/util/derived.ts @@ -18,7 +18,11 @@ import * as primitiveClasses from '../../primitive'; import { formatType } from './formatting'; import { setImports, TypeImports } from './imports'; -const voteConvictions = _voteConvictions.map((c): string => `'${c}'`).join(' | '); +function arrayToStrType (arr: string[]): string { + return `(${arr.map((c): string => `'${c}'`).join(' | ')})`; +} + +const voteConvictions = arrayToStrType(_voteConvictions); // From `T`, generate `Compact, Option, Vec` /** @internal */ @@ -70,9 +74,9 @@ export function getSimilarTypes (definitions: object, registry: Registry, type: return ['StorageKey', 'string', 'Uint8Array', 'any']; } - const clazz = ClassOfUnsafe(registry, type); + const Clazz = ClassOfUnsafe(registry, type); - if (isChildClass(Vec, clazz)) { + if (isChildClass(Vec, Clazz)) { const subDef = (getTypeDef(type).sub) as TypeDef; if (subDef.info === TypeDefInfo.Plain) { @@ -86,24 +90,31 @@ export function getSimilarTypes (definitions: object, registry: Registry, type: } else { throw new Error(`Unhandled subtype in Vec, ${JSON.stringify(subDef)}`); } - } else if (isChildClass(Enum, clazz)) { - // TODO Handle this more gracefully (expand actual options) - possibleTypes.push('number', 'any'); - } else if (isChildClass(AbstractInt as unknown as Constructor, clazz) || isChildClass(Compact, clazz)) { + } else if (isChildClass(Enum, Clazz)) { + const e = new Clazz(registry) as Enum; + + if (e.isBasic) { + possibleTypes.push(arrayToStrType(e.defKeys), 'number', 'Uint8Array'); + } else { + // TODO Handle this more gracefully (expand actual options) + possibleTypes.push('object', 'number', 'Uint8Array', 'string'); + } + } else if (isChildClass(AbstractInt as unknown as Constructor, Clazz) || isChildClass(Compact, Clazz)) { possibleTypes.push('AnyNumber', 'Uint8Array'); - } else if (isChildClass(ClassOf(registry, 'Address'), clazz)) { + } else if (isChildClass(ClassOf(registry, 'Address'), Clazz)) { possibleTypes.push('string', 'AccountId', 'AccountIndex', 'Uint8Array'); - } else if (isChildClass(ClassOf(registry, 'bool'), clazz)) { + } else if (isChildClass(ClassOf(registry, 'bool'), Clazz)) { possibleTypes.push('boolean', 'Uint8Array'); - } else if (isChildClass(Struct, clazz)) { + } else if (isChildClass(Struct, Clazz)) { possibleTypes.push('object', 'string', 'Uint8Array'); - } else if (isChildClass(Option, clazz)) { + } else if (isChildClass(Option, Clazz)) { + // TODO inspect container possibleTypes.push('null', 'object', 'string', 'Uint8Array'); - } else if (isChildClass(Vote, clazz)) { - possibleTypes.push(`{ aye: boolean; conviction?: number | (${voteConvictions}) }`, 'boolean', 'string', 'Uint8Array'); - } else if (isChildClass(Uint8Array, clazz)) { + } else if (isChildClass(Vote, Clazz)) { + possibleTypes.push(`{ aye: boolean; conviction?: ${voteConvictions} | number }`, 'boolean', 'string', 'Uint8Array'); + } else if (isChildClass(Uint8Array, Clazz)) { possibleTypes.push('string', 'Uint8Array'); - } else if (isChildClass(String, clazz)) { + } else if (isChildClass(String, Clazz)) { possibleTypes.push('string'); }