From 6581d779c7762bb2fb2d994755e9b7dc85f2eedf Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Mon, 10 Feb 2020 18:44:12 +0100 Subject: [PATCH] Alias Address -> AccountId for polkadot/kusama (#1825) * Swap Address -> LookupSource (correct aliasses) * Adjust overrides with explicit LookupSource * Map Lookup{Source,Target} * Adjust overrides * Comment Address -> AccountId (for now) * Fix typo in comments * Map Address -> AccountId * CHANGELOG --- CHANGELOG.md | 1 + packages/api/src/types/augment/tx.ts | 36 +++++++++++----------- packages/types/src/known/overrides.ts | 16 ++++++---- packages/types/src/scripts/util/derived.ts | 10 ++++-- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52385600a5..2beda74dde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # 1.2.0-beta.x +- Swap Kusama and Polkadot aliasses for `Address` to `AccountId` (future update) - Add `LookupSource` and `LookupTarget` types instead of mapping these directly for aliassing - Add support for `system.account` for balance & nonce queries in derives (Substrate composites) - Add `BitVec` type primitive diff --git a/packages/api/src/types/augment/tx.ts b/packages/api/src/types/augment/tx.ts index 07247da47c..0f3f9a3c96 100644 --- a/packages/api/src/types/augment/tx.ts +++ b/packages/api/src/types/augment/tx.ts @@ -4,7 +4,7 @@ import { AnyNumber, ITuple } from '@polkadot/types/types'; import { Compact, Option, Raw, Vec } from '@polkadot/types/codec'; import { Bytes, Data, IdentityFields, bool, u16, u32, u64 } from '@polkadot/types/primitive'; -import { AccountId, AccountIndex, Balance, BalanceOf, BlockNumber, Call, ChangesTrieConfiguration, Hash, Header, KeyValue, LookupSource, Moment, Signature } from '@polkadot/types/interfaces/runtime'; +import { AccountId, AccountIndex, Address, Balance, BalanceOf, BlockNumber, Call, ChangesTrieConfiguration, Hash, Header, KeyValue, LookupSource, Moment, Signature } from '@polkadot/types/interfaces/runtime'; import { MemberCount, ProposalIndex } from '@polkadot/types/interfaces/collective'; import { CodeHash, Gas, Schedule } from '@polkadot/types/interfaces/contracts'; import { Conviction, PropIndex, Proposal, ReferendumIndex } from '@polkadot/types/interfaces/democracy'; @@ -216,7 +216,7 @@ declare module '@polkadot/api/types/submittable' { * check that the transfer will not kill the origin account. * # **/ - transfer: AugmentedSubmittable<(dest: LookupSource | string | AccountId | AccountIndex | Uint8Array, value: Compact | AnyNumber | Uint8Array) => SubmittableExtrinsic>; + transfer: AugmentedSubmittable<(dest: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, value: Compact | AnyNumber | Uint8Array) => SubmittableExtrinsic>; /** * Set the balances of a given account. * This will alter `FreeBalance` and `ReservedBalance` in storage. it will @@ -229,19 +229,19 @@ declare module '@polkadot/api/types/submittable' { * - Contains a limited number of reads and writes. * # **/ - setBalance: AugmentedSubmittable<(who: LookupSource | string | AccountId | AccountIndex | Uint8Array, newFree: Compact | AnyNumber | Uint8Array, newReserved: Compact | AnyNumber | Uint8Array) => SubmittableExtrinsic>; + setBalance: AugmentedSubmittable<(who: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, newFree: Compact | AnyNumber | Uint8Array, newReserved: Compact | AnyNumber | Uint8Array) => SubmittableExtrinsic>; /** * Exactly as `transfer`, except the origin must be root and the source account may be * specified. **/ - forceTransfer: AugmentedSubmittable<(source: LookupSource | string | AccountId | AccountIndex | Uint8Array, dest: LookupSource | string | AccountId | AccountIndex | Uint8Array, value: Compact | AnyNumber | Uint8Array) => SubmittableExtrinsic>; + forceTransfer: AugmentedSubmittable<(source: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, dest: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, value: Compact | AnyNumber | Uint8Array) => SubmittableExtrinsic>; /** * Same as the [`transfer`] call, but with a check that the transfer will not kill the * origin account. * 99% of the time you want [`transfer`] instead. * [`transfer`]: struct.Module.html#method.transfer **/ - transferKeepAlive: AugmentedSubmittable<(dest: LookupSource | string | AccountId | AccountIndex | Uint8Array, value: Compact | AnyNumber | Uint8Array) => SubmittableExtrinsic>; + transferKeepAlive: AugmentedSubmittable<(dest: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, value: Compact | AnyNumber | Uint8Array) => SubmittableExtrinsic>; }; staking: { [index: string]: SubmittableExtrinsicFunction; @@ -258,7 +258,7 @@ declare module '@polkadot/api/types/submittable' { * the `origin` falls below _existential deposit_ and gets removed as dust. * # **/ - bond: AugmentedSubmittable<(controller: LookupSource | string | AccountId | AccountIndex | Uint8Array, value: Compact | AnyNumber | Uint8Array, payee: RewardDestination | ('Staked' | 'Stash' | 'Controller') | number | Uint8Array) => SubmittableExtrinsic>; + bond: AugmentedSubmittable<(controller: LookupSource | Address | AccountId | AccountIndex | string | 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. @@ -330,7 +330,7 @@ declare module '@polkadot/api/types/submittable' { * - Both the reads and writes follow a similar pattern. * # **/ - nominate: AugmentedSubmittable<(targets: Vec | (LookupSource | string | AccountId | AccountIndex | Uint8Array)[]) => SubmittableExtrinsic>; + nominate: AugmentedSubmittable<(targets: Vec | (LookupSource | Address | AccountId | AccountIndex | string | Uint8Array)[]) => SubmittableExtrinsic>; /** * Declare no desire to either validate or nominate. * Effects will be felt at the beginning of the next era. @@ -363,7 +363,7 @@ declare module '@polkadot/api/types/submittable' { * - Writes are limited to the `origin` account key. * # **/ - setController: AugmentedSubmittable<(controller: LookupSource | string | AccountId | AccountIndex | Uint8Array) => SubmittableExtrinsic>; + setController: AugmentedSubmittable<(controller: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array) => SubmittableExtrinsic>; /** * The ideal number of validators. **/ @@ -666,7 +666,7 @@ declare module '@polkadot/api/types/submittable' { * Writes: O(1) * # **/ - reportDefunctVoter: AugmentedSubmittable<(target: LookupSource | string | AccountId | AccountIndex | Uint8Array) => SubmittableExtrinsic>; + reportDefunctVoter: AugmentedSubmittable<(target: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array) => SubmittableExtrinsic>; /** * Submit oneself for candidacy. * A candidate will either: @@ -705,7 +705,7 @@ declare module '@polkadot/api/types/submittable' { * Writes: O(do_phragmen) * # **/ - removeMember: AugmentedSubmittable<(who: LookupSource | string | AccountId | AccountIndex | Uint8Array) => SubmittableExtrinsic>; + removeMember: AugmentedSubmittable<(who: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array) => SubmittableExtrinsic>; }; technicalMembership: { [index: string]: SubmittableExtrinsicFunction; @@ -763,7 +763,7 @@ declare module '@polkadot/api/types/submittable' { * - One DB change, one extra DB entry. * # **/ - proposeSpend: AugmentedSubmittable<(value: Compact | AnyNumber | Uint8Array, beneficiary: LookupSource | string | AccountId | AccountIndex | Uint8Array) => SubmittableExtrinsic>; + proposeSpend: AugmentedSubmittable<(value: Compact | AnyNumber | Uint8Array, beneficiary: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array) => SubmittableExtrinsic>; /** * Reject a proposed spend. The original deposit will be slashed. * # @@ -887,7 +887,7 @@ declare module '@polkadot/api/types/submittable' { * * If no account exists and the call value is not less than `existential_deposit`, * a regular account will be created and any value will be transferred. **/ - call: AugmentedSubmittable<(dest: LookupSource | string | AccountId | AccountIndex | Uint8Array, value: Compact | AnyNumber | Uint8Array, gasLimit: Compact | AnyNumber | Uint8Array, data: Bytes | string | Uint8Array) => SubmittableExtrinsic>; + call: AugmentedSubmittable<(dest: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, value: Compact | AnyNumber | Uint8Array, gasLimit: Compact | AnyNumber | Uint8Array, data: Bytes | string | Uint8Array) => SubmittableExtrinsic>; /** * Instantiates a new contract from the `codehash` generated by `put_code`, optionally transferring some balance. * Instantiation is executed as follows: @@ -929,7 +929,7 @@ declare module '@polkadot/api/types/submittable' { * - One DB change. * # **/ - setKey: AugmentedSubmittable<(updated: LookupSource | string | AccountId | AccountIndex | Uint8Array) => SubmittableExtrinsic>; + setKey: AugmentedSubmittable<(updated: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array) => SubmittableExtrinsic>; /** * Authenticates the sudo key and dispatches a function call with `Signed` origin from * a given account. @@ -941,7 +941,7 @@ declare module '@polkadot/api/types/submittable' { * - Unknown weight of derivative `proposal` execution. * # **/ - sudoAs: AugmentedSubmittable<(who: LookupSource | string | AccountId | AccountIndex | Uint8Array, proposal: Proposal | { callIndex?: any; args?: any } | string | Uint8Array) => SubmittableExtrinsic>; + sudoAs: AugmentedSubmittable<(who: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, proposal: Proposal | { callIndex?: any; args?: any } | string | Uint8Array) => SubmittableExtrinsic>; }; imOnline: { [index: string]: SubmittableExtrinsicFunction; @@ -1094,7 +1094,7 @@ declare module '@polkadot/api/types/submittable' { * - One event. * # **/ - provideJudgement: AugmentedSubmittable<(regIndex: Compact | AnyNumber | Uint8Array, target: LookupSource | string | AccountId | AccountIndex | Uint8Array, judgement: IdentityJudgement | { unknown: any } | { feePaid: any } | { reasonable: any } | { knownGood: any } | { outOfDate: any } | { lowQuality: any } | { erroneous: any } | string | Uint8Array) => SubmittableExtrinsic>; + provideJudgement: AugmentedSubmittable<(regIndex: Compact | AnyNumber | Uint8Array, target: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, judgement: IdentityJudgement | { unknown: any } | { feePaid: any } | { reasonable: any } | { knownGood: any } | { outOfDate: any } | { lowQuality: any } | { erroneous: any } | string | Uint8Array) => 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 @@ -1111,7 +1111,7 @@ declare module '@polkadot/api/types/submittable' { * - One event. * # **/ - killIdentity: AugmentedSubmittable<(target: LookupSource | string | AccountId | AccountIndex | Uint8Array) => SubmittableExtrinsic>; + killIdentity: AugmentedSubmittable<(target: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array) => SubmittableExtrinsic>; }; society: { [index: string]: SubmittableExtrinsicFunction; @@ -1237,7 +1237,7 @@ declare module '@polkadot/api/types/submittable' { * Total Complexity: O(M + logM + C) * # **/ - vote: AugmentedSubmittable<(candidate: LookupSource | string | AccountId | AccountIndex | Uint8Array, approve: bool | boolean | Uint8Array) => SubmittableExtrinsic>; + vote: AugmentedSubmittable<(candidate: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, approve: bool | boolean | Uint8Array) => SubmittableExtrinsic>; /** * As a member, vote on the defender. * The dispatch origin for this call must be _Signed_ and a member. @@ -1557,7 +1557,7 @@ declare module '@polkadot/api/types/submittable' { * - One event. * # **/ - vestOther: AugmentedSubmittable<(target: LookupSource | string | AccountId | AccountIndex | Uint8Array) => SubmittableExtrinsic>; + vestOther: AugmentedSubmittable<(target: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array) => SubmittableExtrinsic>; }; } } diff --git a/packages/types/src/known/overrides.ts b/packages/types/src/known/overrides.ts index ccc30830d7..e0b15f193e 100644 --- a/packages/types/src/known/overrides.ts +++ b/packages/types/src/known/overrides.ts @@ -32,6 +32,8 @@ const TYPES_POLKADOT_VERSIONED: OverrideVersionedType[] = [ { minmax: [1000, undefined], // from launch types: { + // Indices optional, not in transaction + Address: 'AccountId', Keys: 'SessionKeys5' } } @@ -41,35 +43,36 @@ const TYPES_KUSAMA_VERSIONED: OverrideVersionedType[] = [ { minmax: [1019, 1031], types: { + Address: 'GenericAddress', BalanceLock: 'BalanceLockTo212', DispatchError: 'DispatchErrorTo198', Keys: 'SessionKeys5', - LookupSource: 'Address', SlashingSpans: 'SlashingSpansTo204' } }, { minmax: [1032, 1042], types: { + Address: 'GenericAddress', BalanceLock: 'BalanceLockTo212', Keys: 'SessionKeys5', - LookupSource: 'Address', SlashingSpans: 'SlashingSpansTo204' } }, { minmax: [1043, 1045], types: { + Address: 'GenericAddress', BalanceLock: 'BalanceLockTo212', - Keys: 'SessionKeys5', - LookupSource: 'Address' + Keys: 'SessionKeys5' } }, { minmax: [1046, undefined], types: { - Keys: 'SessionKeys5', - LookupSource: 'AccountId' + // Indices optional, not in transaction + Address: 'AccountId', + Keys: 'SessionKeys5' } } ]; @@ -86,6 +89,7 @@ const TYPES_META: OverrideVersionedType[] = [ // v4 = v1.0 branch minmax: [0, 4], types: { + Address: 'GenericAddress', BlockNumber: 'u64', Index: 'u64', EventRecord: 'EventRecordTo76', diff --git a/packages/types/src/scripts/util/derived.ts b/packages/types/src/scripts/util/derived.ts index d30ff96864..81299c3ce1 100644 --- a/packages/types/src/scripts/util/derived.ts +++ b/packages/types/src/scripts/util/derived.ts @@ -14,8 +14,10 @@ import Enum from '../../codec/Enum'; import Option from '../../codec/Option'; import Struct from '../../codec/Struct'; import Vec from '../../codec/Vec'; -import Null from '../../primitive/Null'; +import GenericAccountId from '../../primitive/Generic/AccountId'; +import GenericAddress from '../../primitive/Generic/Address'; import Vote, { convictionNames as _voteConvictions } from '../../primitive/Generic/Vote'; +import Null from '../../primitive/Null'; import * as primitiveClasses from '../../primitive'; import { formatType } from './formatting'; import { setImports, TypeImports } from './imports'; @@ -105,8 +107,10 @@ export function getSimilarTypes (definitions: object, registry: Registry, type: possibleTypes.push('Uint8Array'); } else if (isChildClass(AbstractInt as unknown as Constructor, Clazz) || isChildClass(Compact, Clazz)) { possibleTypes.push('AnyNumber', 'Uint8Array'); - } else if (isChildClass(ClassOf(registry, 'Address'), Clazz)) { - possibleTypes.push('string', 'AccountId', 'AccountIndex', 'Uint8Array'); + } else if (isChildClass(GenericAddress, Clazz)) { + possibleTypes.push('Address', 'AccountId', 'AccountIndex', 'string', 'Uint8Array'); + } else if (isChildClass(GenericAccountId, Clazz)) { + possibleTypes.push('string', 'Uint8Array'); } else if (isChildClass(ClassOf(registry, 'bool'), Clazz)) { possibleTypes.push('boolean', 'Uint8Array'); } else if (isChildClass(Null, Clazz)) {