From 07d1fc0dba4c4c2e2a52b349e6d84b046ebbd205 Mon Sep 17 00:00:00 2001 From: Jaco Date: Thu, 1 Sep 2022 12:19:30 +0300 Subject: [PATCH 01/10] Support for ink! v4 metadata --- CHANGELOG.md | 1 + packages/api-contract/src/Abi/Abi.spec.ts | 5 ++++- packages/api-contract/src/Abi/index.ts | 17 ++++++++++++++--- packages/api-contract/src/Abi/toLatest.ts | 11 +++++++---- packages/api-contract/src/Abi/toV4.ts | 9 +++++++++ .../compare/ink_v4_flipperContract.test.json | 9 +++++++++ .../compare/ink_v4_flipperMetadata.test.json | 9 +++++++++ .../src/test/contracts/ink/index.ts | 4 ++-- .../types-augment/src/registry/interfaces.ts | 4 +++- .../src/interfaces/contractsAbi/definitions.ts | 9 +++++++-- .../types/src/interfaces/contractsAbi/types.ts | 15 +++++++++++++-- 11 files changed, 78 insertions(+), 15 deletions(-) create mode 100644 packages/api-contract/src/Abi/toV4.ts create mode 100644 packages/api-contract/src/test/compare/ink_v4_flipperContract.test.json create mode 100644 packages/api-contract/src/test/compare/ink_v4_flipperMetadata.test.json diff --git a/CHANGELOG.md b/CHANGELOG.md index d7c4275c21c1..c1b18842fe72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Changes: +- Support for ink! v4 metadata - Adjust `pendingRewards` for pools runtime calls - Update to latest Substrate, Polkadot & Kusama metadata diff --git a/packages/api-contract/src/Abi/Abi.spec.ts b/packages/api-contract/src/Abi/Abi.spec.ts index 2c9c6c8d7af1..b048df987677 100644 --- a/packages/api-contract/src/Abi/Abi.spec.ts +++ b/packages/api-contract/src/Abi/Abi.spec.ts @@ -35,6 +35,9 @@ interface JSONAbi { }, V3: { spec: SpecDef; + }, + V4: { + spec: SpecDef; } } @@ -59,7 +62,7 @@ describe('Abi', (): void => { it(`initializes from a contract ABI (${abiName})`, (): void => { try { - const messageIds = (abi.V3 || abi.V2 || abi.V1 || abi).spec.messages.map(({ label, name }) => + const messageIds = (abi.V4 || abi.V3 || abi.V2 || abi.V1 || abi).spec.messages.map(({ label, name }) => label || ( Array.isArray(name) ? name.join('::') diff --git a/packages/api-contract/src/Abi/index.ts b/packages/api-contract/src/Abi/index.ts index fd4bd29bd1f5..ed013b8918a8 100644 --- a/packages/api-contract/src/Abi/index.ts +++ b/packages/api-contract/src/Abi/index.ts @@ -27,12 +27,23 @@ function findMessage (list: T[], messageOrId: T | string } function getLatestMeta (registry: Registry, json: Record): ContractMetadataLatest { + // this is for V1, V2, V3 const vx = enumVersions.find((v) => isObject(json[v])); - const metadata = registry.createType('ContractMetadata', + + // this was added in V4 + const jsonVersion = json.version as string; + + if (!vx && jsonVersion && !enumVersions.find((v) => v === `V${jsonVersion}`)) { + throw new Error(`Unable to handle version ${jsonVersion}`); + } + + const metadata = registry.createType('ContractMetadata', vx ? { [vx]: json[vx] } - : { V0: json } - ) as unknown as ContractMetadata; + : jsonVersion + ? { [`V${jsonVersion}`]: json } + : { V0: json } + ); const converter = convertVersions.find(([v]) => metadata[`is${v}`]); if (!converter) { diff --git a/packages/api-contract/src/Abi/toLatest.ts b/packages/api-contract/src/Abi/toLatest.ts index 46a4c23dfdee..0159e7b65f69 100644 --- a/packages/api-contract/src/Abi/toLatest.ts +++ b/packages/api-contract/src/Abi/toLatest.ts @@ -1,16 +1,17 @@ // Copyright 2017-2022 @polkadot/api-contract authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { ContractMetadataLatest, ContractMetadataV3 } from '@polkadot/types/interfaces'; +import type { ContractMetadataLatest, ContractMetadataV4 } from '@polkadot/types/interfaces'; import type { Registry } from '@polkadot/types/types'; import { v0ToV1 } from './toV1'; import { v1ToV2 } from './toV2'; import { v2ToV3 } from './toV3'; +import { v3ToV4 } from './toV4'; // The versions where an enum is used, aka V0 is missing // (Order from newest, i.e. we expect more on newest vs oldest) -export const enumVersions = ['V3', 'V2', 'V1']; +export const enumVersions = ['V4', 'V3', 'V2', 'V1']; type Versions = typeof enumVersions[number] | 'V0'; @@ -22,15 +23,17 @@ function createConverter (next: (registry: Registry, input: O) => Contrac next(registry, step(registry, input)); } -export function v3ToLatest (registry: Registry, v3: ContractMetadataV3): ContractMetadataLatest { - return v3; +function v4ToLatest (registry: Registry, v4: ContractMetadataV4): ContractMetadataLatest { + return v4; } +export const v3ToLatest = createConverter(v4ToLatest, v3ToV4); export const v2ToLatest = createConverter(v3ToLatest, v2ToV3); export const v1ToLatest = createConverter(v2ToLatest, v1ToV2); export const v0ToLatest = createConverter(v1ToLatest, v0ToV1); export const convertVersions: [Versions, Converter][] = [ + ['V4', v4ToLatest], ['V3', v3ToLatest], ['V2', v2ToLatest], ['V1', v1ToLatest], diff --git a/packages/api-contract/src/Abi/toV4.ts b/packages/api-contract/src/Abi/toV4.ts new file mode 100644 index 000000000000..12db921d4db5 --- /dev/null +++ b/packages/api-contract/src/Abi/toV4.ts @@ -0,0 +1,9 @@ +// Copyright 2017-2022 @polkadot/api-contract authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { ContractMetadataV3, ContractMetadataV4 } from '@polkadot/types/interfaces'; +import type { Registry } from '@polkadot/types/types'; + +export function v3ToV4 (registry: Registry, v3: ContractMetadataV3): ContractMetadataV4 { + return v3; +} diff --git a/packages/api-contract/src/test/compare/ink_v4_flipperContract.test.json b/packages/api-contract/src/test/compare/ink_v4_flipperContract.test.json new file mode 100644 index 000000000000..e7e9211fa21f --- /dev/null +++ b/packages/api-contract/src/test/compare/ink_v4_flipperContract.test.json @@ -0,0 +1,9 @@ +[ + { + "info": "Plain", + "lookupIndex": 0, + "type": "bool", + "docs": [], + "namespace": "" + } +] \ No newline at end of file diff --git a/packages/api-contract/src/test/compare/ink_v4_flipperMetadata.test.json b/packages/api-contract/src/test/compare/ink_v4_flipperMetadata.test.json new file mode 100644 index 000000000000..e7e9211fa21f --- /dev/null +++ b/packages/api-contract/src/test/compare/ink_v4_flipperMetadata.test.json @@ -0,0 +1,9 @@ +[ + { + "info": "Plain", + "lookupIndex": 0, + "type": "bool", + "docs": [], + "namespace": "" + } +] \ No newline at end of file diff --git a/packages/api-contract/src/test/contracts/ink/index.ts b/packages/api-contract/src/test/contracts/ink/index.ts index ce076a2181e5..9514b8b579fd 100644 --- a/packages/api-contract/src/test/contracts/ink/index.ts +++ b/packages/api-contract/src/test/contracts/ink/index.ts @@ -6,6 +6,6 @@ import * as v0 from './v0'; import * as v1 from './v1'; import * as v2 from './v2'; import * as v3 from './v3'; -// import * as v4 from './v4'; +import * as v4 from './v4'; -export default createVersionedExport({ v0, v1, v2, v3 }); +export default createVersionedExport({ v0, v1, v2, v3, v4 }); diff --git a/packages/types-augment/src/registry/interfaces.ts b/packages/types-augment/src/registry/interfaces.ts index 530ac825b2e2..8c6446da438b 100644 --- a/packages/types-augment/src/registry/interfaces.ts +++ b/packages/types-augment/src/registry/interfaces.ts @@ -24,7 +24,7 @@ import type { StatementKind } from '@polkadot/types/interfaces/claims'; import type { CollectiveOrigin, MemberCount, ProposalIndex, Votes, VotesTo230 } from '@polkadot/types/interfaces/collective'; import type { AuthorityId, RawVRFOutput } from '@polkadot/types/interfaces/consensus'; import type { AliveContractInfo, CodeHash, CodeSource, CodeUploadRequest, CodeUploadResult, CodeUploadResultValue, ContractCallFlags, ContractCallRequest, ContractExecResult, ContractExecResultOk, ContractExecResultResult, ContractExecResultSuccessTo255, ContractExecResultSuccessTo260, ContractExecResultTo255, ContractExecResultTo260, ContractExecResultTo267, ContractInfo, ContractInstantiateResult, ContractInstantiateResultTo267, ContractInstantiateResultTo299, ContractReturnFlags, ContractStorageKey, DeletedContract, ExecReturnValue, Gas, HostFnWeights, HostFnWeightsTo264, InstantiateRequest, InstantiateRequestV1, InstantiateRequestV2, InstantiateReturnValue, InstantiateReturnValueOk, InstantiateReturnValueTo267, InstructionWeights, Limits, LimitsTo264, PrefabWasmModule, RentProjection, Schedule, ScheduleTo212, ScheduleTo258, ScheduleTo264, SeedOf, StorageDeposit, TombstoneContractInfo, TrieId } from '@polkadot/types/interfaces/contracts'; -import type { ContractConstructorSpecLatest, ContractConstructorSpecV0, ContractConstructorSpecV1, ContractConstructorSpecV2, ContractConstructorSpecV3, ContractContractSpecV0, ContractContractSpecV1, ContractContractSpecV2, ContractContractSpecV3, ContractCryptoHasher, ContractDiscriminant, ContractDisplayName, ContractEventParamSpecLatest, ContractEventParamSpecV0, ContractEventParamSpecV2, ContractEventSpecLatest, ContractEventSpecV0, ContractEventSpecV1, ContractEventSpecV2, ContractLayoutArray, ContractLayoutCell, ContractLayoutEnum, ContractLayoutHash, ContractLayoutHashingStrategy, ContractLayoutKey, ContractLayoutStruct, ContractLayoutStructField, ContractMessageParamSpecLatest, ContractMessageParamSpecV0, ContractMessageParamSpecV2, ContractMessageSpecLatest, ContractMessageSpecV0, ContractMessageSpecV1, ContractMessageSpecV2, ContractMetadata, ContractMetadataLatest, ContractMetadataV0, ContractMetadataV1, ContractMetadataV2, ContractMetadataV3, ContractProject, ContractProjectContract, ContractProjectInfo, ContractProjectSource, ContractProjectV0, ContractSelector, ContractStorageLayout, ContractTypeSpec } from '@polkadot/types/interfaces/contractsAbi'; +import type { ContractConstructorSpecLatest, ContractConstructorSpecV0, ContractConstructorSpecV1, ContractConstructorSpecV2, ContractConstructorSpecV3, ContractContractSpecV0, ContractContractSpecV1, ContractContractSpecV2, ContractContractSpecV3, ContractContractSpecV4, ContractCryptoHasher, ContractDiscriminant, ContractDisplayName, ContractEventParamSpecLatest, ContractEventParamSpecV0, ContractEventParamSpecV2, ContractEventSpecLatest, ContractEventSpecV0, ContractEventSpecV1, ContractEventSpecV2, ContractLayoutArray, ContractLayoutCell, ContractLayoutEnum, ContractLayoutHash, ContractLayoutHashingStrategy, ContractLayoutKey, ContractLayoutStruct, ContractLayoutStructField, ContractMessageParamSpecLatest, ContractMessageParamSpecV0, ContractMessageParamSpecV2, ContractMessageSpecLatest, ContractMessageSpecV0, ContractMessageSpecV1, ContractMessageSpecV2, ContractMetadata, ContractMetadataLatest, ContractMetadataV0, ContractMetadataV1, ContractMetadataV2, ContractMetadataV3, ContractMetadataV4, ContractProject, ContractProjectContract, ContractProjectInfo, ContractProjectSource, ContractProjectV0, ContractSelector, ContractStorageLayout, ContractTypeSpec } from '@polkadot/types/interfaces/contractsAbi'; import type { FundIndex, FundInfo, LastContribution, TrieIndex } from '@polkadot/types/interfaces/crowdloan'; import type { CollationInfo, CollationInfoV1, ConfigData, MessageId, OverweightIndex, PageCounter, PageIndexData } from '@polkadot/types/interfaces/cumulus'; import type { AccountVote, AccountVoteSplit, AccountVoteStandard, Conviction, Delegations, PreimageStatus, PreimageStatusAvailable, PriorLock, PropIndex, Proposal, ProxyState, ReferendumIndex, ReferendumInfo, ReferendumInfoFinished, ReferendumInfoTo239, ReferendumStatus, Tally, Voting, VotingDelegating, VotingDirect, VotingDirectVote } from '@polkadot/types/interfaces/democracy'; @@ -252,6 +252,7 @@ declare module '@polkadot/types/types/registry' { ContractContractSpecV1: ContractContractSpecV1; ContractContractSpecV2: ContractContractSpecV2; ContractContractSpecV3: ContractContractSpecV3; + ContractContractSpecV4: ContractContractSpecV4; ContractCryptoHasher: ContractCryptoHasher; ContractDiscriminant: ContractDiscriminant; ContractDisplayName: ContractDisplayName; @@ -295,6 +296,7 @@ declare module '@polkadot/types/types/registry' { ContractMetadataV1: ContractMetadataV1; ContractMetadataV2: ContractMetadataV2; ContractMetadataV3: ContractMetadataV3; + ContractMetadataV4: ContractMetadataV4; ContractProject: ContractProject; ContractProjectContract: ContractProjectContract; ContractProjectInfo: ContractProjectInfo; diff --git a/packages/types/src/interfaces/contractsAbi/definitions.ts b/packages/types/src/interfaces/contractsAbi/definitions.ts index 20d2430aa5a0..904bd1130cd6 100644 --- a/packages/types/src/interfaces/contractsAbi/definitions.ts +++ b/packages/types/src/interfaces/contractsAbi/definitions.ts @@ -106,6 +106,7 @@ const spec = { events: 'Vec', docs: 'Vec' }, + ContractContractSpecV4: 'ContractContractSpecV3', ContractDisplayName: 'SiPath', ContractEventParamSpecV0: { name: 'Text', @@ -197,6 +198,8 @@ const ContractMetadataV3 = { spec: 'ContractContractSpecV3' }; +const ContractMetadataV4 = ContractMetadataV3; + const ContractProjectInfo = { source: 'ContractProjectSource', contract: 'ContractProjectContract' @@ -208,7 +211,7 @@ const latest = { ContractEventParamSpecLatest: 'ContractEventParamSpecV2', ContractMessageParamSpecLatest: 'ContractMessageParamSpecV2', ContractMessageSpecLatest: 'ContractMessageSpecV2', - ContractMetadataLatest: 'ContractMetadataV3' + ContractMetadataLatest: 'ContractMetadataV4' }; export default { @@ -219,12 +222,14 @@ export default { ContractMetadataV1, ContractMetadataV2, ContractMetadataV3, + ContractMetadataV4, ContractMetadata: { _enum: { V0: 'ContractMetadataV0', V1: 'ContractMetadataV1', V2: 'ContractMetadataV2', - V3: 'ContractMetadataV3' + V3: 'ContractMetadataV3', + V4: 'ContractMetadataV4' } }, ContractProjectV0: objectSpread({ metadataVersion: 'Text' }, ContractProjectInfo, ContractMetadataV0), diff --git a/packages/types/src/interfaces/contractsAbi/types.ts b/packages/types/src/interfaces/contractsAbi/types.ts index 39e411a42f9d..f58598897b02 100644 --- a/packages/types/src/interfaces/contractsAbi/types.ts +++ b/packages/types/src/interfaces/contractsAbi/types.ts @@ -74,6 +74,9 @@ export interface ContractContractSpecV3 extends Struct { readonly docs: Vec; } +/** @name ContractContractSpecV4 */ +export interface ContractContractSpecV4 extends ContractContractSpecV3 {} + /** @name ContractCryptoHasher */ export interface ContractCryptoHasher extends Enum { readonly isBlake2x256: boolean; @@ -240,11 +243,13 @@ export interface ContractMetadata extends Enum { readonly asV2: ContractMetadataV2; readonly isV3: boolean; readonly asV3: ContractMetadataV3; - readonly type: 'V0' | 'V1' | 'V2' | 'V3'; + readonly isV4: boolean; + readonly asV4: ContractMetadataV4; + readonly type: 'V0' | 'V1' | 'V2' | 'V3' | 'V4'; } /** @name ContractMetadataLatest */ -export interface ContractMetadataLatest extends ContractMetadataV3 {} +export interface ContractMetadataLatest extends ContractMetadataV4 {} /** @name ContractMetadataV0 */ export interface ContractMetadataV0 extends Struct { @@ -271,6 +276,12 @@ export interface ContractMetadataV3 extends Struct { readonly spec: ContractContractSpecV3; } +/** @name ContractMetadataV4 */ +export interface ContractMetadataV4 extends Struct { + readonly types: Vec; + readonly spec: ContractContractSpecV3; +} + /** @name ContractProject */ export interface ContractProject extends ITuple<[ContractProjectInfo, ContractMetadata]> {} From 862e20c3a88de40c6c639b1f51034c296d7f9d16 Mon Sep 17 00:00:00 2001 From: Jaco Date: Thu, 1 Sep 2022 13:20:35 +0300 Subject: [PATCH 02/10] Adjust --- packages/api-contract/src/Abi/toLatest.spec.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/api-contract/src/Abi/toLatest.spec.ts b/packages/api-contract/src/Abi/toLatest.spec.ts index cd311879becd..d8d14db5dbe2 100644 --- a/packages/api-contract/src/Abi/toLatest.spec.ts +++ b/packages/api-contract/src/Abi/toLatest.spec.ts @@ -1,7 +1,7 @@ // Copyright 2017-2022 @polkadot/api-contract authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { v0ToLatest, v1ToLatest, v2ToLatest, v3ToLatest } from '@polkadot/api-contract/Abi/toLatest'; +import { v0ToLatest, v1ToLatest, v2ToLatest, v3ToLatest, v4ToLatest } from '@polkadot/api-contract/Abi/toLatest'; import { TypeRegistry } from '@polkadot/types'; import abis from '../test/contracts'; @@ -120,3 +120,18 @@ describe('v3ToLatest', (): void => { ]); }); }); + +describe('v4ToLatest', (): void => { + const registry = new TypeRegistry(); + const contract = registry.createType('ContractMetadata', { V4: abis.ink_v4_flipperContract.V4 }); + const latest = v4ToLatest(registry, contract.asV4); + + it('has the correct constructor flags', (): void => { + expect( + latest.spec.constructors[0].payable.isTrue + ).toEqual(false); + expect( + latest.spec.constructors[1].payable.isTrue + ).toEqual(true); + }); +}); From 7daa1f6c5da880a75782d514e1f9b22be5b6d256 Mon Sep 17 00:00:00 2001 From: Jaco Date: Thu, 1 Sep 2022 16:32:08 +0300 Subject: [PATCH 03/10] Support for AccountId33 --- CHANGELOG.md | 1 + packages/types/src/generic/AccountId.spec.ts | 7 +++- packages/types/src/generic/AccountId.ts | 35 +++++++++++++------ packages/types/src/generic/index.ts | 2 +- .../src/interfaces/runtime/definitions.ts | 3 +- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1b18842fe72..5b44f5fc3d77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Changes: - Support for ink! v4 metadata - Adjust `pendingRewards` for pools runtime calls +- Support for `AccountId33` (raw/compressed 33-byte ecdsa) - Update to latest Substrate, Polkadot & Kusama metadata diff --git a/packages/types/src/generic/AccountId.spec.ts b/packages/types/src/generic/AccountId.spec.ts index 21f4bb4d6170..2f9c7f34a037 100644 --- a/packages/types/src/generic/AccountId.spec.ts +++ b/packages/types/src/generic/AccountId.spec.ts @@ -7,7 +7,7 @@ import { Raw } from '@polkadot/types-codec'; import jsonVec from '@polkadot/types-support/json/AccountIdVec.001.json' assert { type: 'json' }; import { TypeRegistry } from '../create'; -import { GenericAccountId as AccountId } from '.'; +import { GenericAccountId32 as AccountId } from '.'; describe('AccountId', (): void => { const registry = new TypeRegistry(); @@ -57,6 +57,11 @@ describe('AccountId', (): void => { registry.createType('AccountId', '0x0102030405060708010203040506070801020304050607080102030405060708'), '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF' ); + testDecode( + 'AccountId33', + registry.createType('AccountId', '0x0102030405060708010203040506070801020304050607080102030405060708'), + '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF' + ); testDecode('hex', '0x0102030405060708010203040506070801020304050607080102030405060708', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'); testDecode('string', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'); testDecode( diff --git a/packages/types/src/generic/AccountId.ts b/packages/types/src/generic/AccountId.ts index 57ff045d2986..44aebece0a7b 100644 --- a/packages/types/src/generic/AccountId.ts +++ b/packages/types/src/generic/AccountId.ts @@ -22,20 +22,14 @@ function decodeAccountId (value?: AnyU8a | AnyString): Uint8Array { throw new Error(`Unknown type passed to AccountId constructor, found typeof ${typeof value}`); } -/** - * @name GenericAccountId - * @description - * A wrapper around an AccountId/PublicKey representation. Since we are dealing with - * underlying PublicKeys (32 bytes in length), we extend from U8aFixed which is - * just a Uint8Array wrapper with a fixed length. - */ -export class GenericAccountId extends U8aFixed { - constructor (registry: Registry, value?: AnyU8a) { +class BaseAccountId extends U8aFixed { + constructor (registry: Registry, allowedBits = 256 | 264, value?: AnyU8a) { const decoded = decodeAccountId(value); + const decodedBits = decoded.length * 8; // Part of stream containing >= 32 bytes or a all empty (defaults) - if (decoded.length < 32 && decoded.some((b) => b)) { - throw new Error(`Invalid AccountId provided, expected 32 bytes, found ${decoded.length}`); + if (decodedBits !== allowedBits && decoded.some((b) => b)) { + throw new Error(`Invalid AccountId provided, expected ${allowedBits >> 3} bytes, found ${decoded.length}`); } super(registry, decoded, 256); @@ -83,3 +77,22 @@ export class GenericAccountId extends U8aFixed { return 'AccountId'; } } + +/** + * @name GenericAccountId + * @description + * A wrapper around an AccountId/PublicKey representation. Since we are dealing with + * underlying PublicKeys (32 bytes in length), we extend from U8aFixed which is + * just a Uint8Array wrapper with a fixed length. + */ +export class GenericAccountId32 extends BaseAccountId { + constructor (registry: Registry, value?: AnyU8a) { + super(registry, 256, value); + } +} + +export class GenericAccountId33 extends BaseAccountId { + constructor (registry: Registry, value?: AnyU8a) { + super(registry, 264, value); + } +} diff --git a/packages/types/src/generic/index.ts b/packages/types/src/generic/index.ts index 4d05e32afa4d..80d89d105451 100644 --- a/packages/types/src/generic/index.ts +++ b/packages/types/src/generic/index.ts @@ -3,7 +3,7 @@ export * from '../ethereum'; -export { GenericAccountId } from './AccountId'; +export { GenericAccountId32 as GenericAccountId, GenericAccountId32, GenericAccountId33 } from './AccountId'; export { GenericAccountIndex } from './AccountIndex'; export { GenericBlock } from './Block'; export { GenericCall } from './Call'; diff --git a/packages/types/src/interfaces/runtime/definitions.ts b/packages/types/src/interfaces/runtime/definitions.ts index fba5e68a57e2..fed46ec39e16 100644 --- a/packages/types/src/interfaces/runtime/definitions.ts +++ b/packages/types/src/interfaces/runtime/definitions.ts @@ -53,7 +53,8 @@ export default { types: objectSpread({}, numberTypes, { AccountId: 'AccountId32', AccountId20: 'GenericEthereumAccountId', - AccountId32: 'GenericAccountId', + AccountId32: 'GenericAccountId32', + AccountId33: 'GenericAccountId33', AccountIdOf: 'AccountId', AccountIndex: 'GenericAccountIndex', Address: 'MultiAddress', From de4ce448ec4def075a1a0265746c5c70bdc0a680 Mon Sep 17 00:00:00 2001 From: Jaco Date: Thu, 1 Sep 2022 16:32:46 +0300 Subject: [PATCH 04/10] Revert "Adjust" This reverts commit 862e20c3a88de40c6c639b1f51034c296d7f9d16. --- packages/api-contract/src/Abi/toLatest.spec.ts | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/packages/api-contract/src/Abi/toLatest.spec.ts b/packages/api-contract/src/Abi/toLatest.spec.ts index d8d14db5dbe2..cd311879becd 100644 --- a/packages/api-contract/src/Abi/toLatest.spec.ts +++ b/packages/api-contract/src/Abi/toLatest.spec.ts @@ -1,7 +1,7 @@ // Copyright 2017-2022 @polkadot/api-contract authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { v0ToLatest, v1ToLatest, v2ToLatest, v3ToLatest, v4ToLatest } from '@polkadot/api-contract/Abi/toLatest'; +import { v0ToLatest, v1ToLatest, v2ToLatest, v3ToLatest } from '@polkadot/api-contract/Abi/toLatest'; import { TypeRegistry } from '@polkadot/types'; import abis from '../test/contracts'; @@ -120,18 +120,3 @@ describe('v3ToLatest', (): void => { ]); }); }); - -describe('v4ToLatest', (): void => { - const registry = new TypeRegistry(); - const contract = registry.createType('ContractMetadata', { V4: abis.ink_v4_flipperContract.V4 }); - const latest = v4ToLatest(registry, contract.asV4); - - it('has the correct constructor flags', (): void => { - expect( - latest.spec.constructors[0].payable.isTrue - ).toEqual(false); - expect( - latest.spec.constructors[1].payable.isTrue - ).toEqual(true); - }); -}); From c40bf56e9216a512206fa95c3fceb37c68698312 Mon Sep 17 00:00:00 2001 From: Jaco Date: Thu, 1 Sep 2022 16:32:53 +0300 Subject: [PATCH 05/10] Revert "Support for ink! v4 metadata" This reverts commit 07d1fc0dba4c4c2e2a52b349e6d84b046ebbd205. --- CHANGELOG.md | 1 - packages/api-contract/src/Abi/Abi.spec.ts | 5 +---- packages/api-contract/src/Abi/index.ts | 17 +++-------------- packages/api-contract/src/Abi/toLatest.ts | 11 ++++------- packages/api-contract/src/Abi/toV4.ts | 9 --------- .../compare/ink_v4_flipperContract.test.json | 9 --------- .../compare/ink_v4_flipperMetadata.test.json | 9 --------- .../src/test/contracts/ink/index.ts | 4 ++-- .../types-augment/src/registry/interfaces.ts | 4 +--- .../src/interfaces/contractsAbi/definitions.ts | 9 ++------- .../types/src/interfaces/contractsAbi/types.ts | 15 ++------------- 11 files changed, 15 insertions(+), 78 deletions(-) delete mode 100644 packages/api-contract/src/Abi/toV4.ts delete mode 100644 packages/api-contract/src/test/compare/ink_v4_flipperContract.test.json delete mode 100644 packages/api-contract/src/test/compare/ink_v4_flipperMetadata.test.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b44f5fc3d77..ca2ed2de3651 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,6 @@ Changes: -- Support for ink! v4 metadata - Adjust `pendingRewards` for pools runtime calls - Support for `AccountId33` (raw/compressed 33-byte ecdsa) - Update to latest Substrate, Polkadot & Kusama metadata diff --git a/packages/api-contract/src/Abi/Abi.spec.ts b/packages/api-contract/src/Abi/Abi.spec.ts index b048df987677..2c9c6c8d7af1 100644 --- a/packages/api-contract/src/Abi/Abi.spec.ts +++ b/packages/api-contract/src/Abi/Abi.spec.ts @@ -35,9 +35,6 @@ interface JSONAbi { }, V3: { spec: SpecDef; - }, - V4: { - spec: SpecDef; } } @@ -62,7 +59,7 @@ describe('Abi', (): void => { it(`initializes from a contract ABI (${abiName})`, (): void => { try { - const messageIds = (abi.V4 || abi.V3 || abi.V2 || abi.V1 || abi).spec.messages.map(({ label, name }) => + const messageIds = (abi.V3 || abi.V2 || abi.V1 || abi).spec.messages.map(({ label, name }) => label || ( Array.isArray(name) ? name.join('::') diff --git a/packages/api-contract/src/Abi/index.ts b/packages/api-contract/src/Abi/index.ts index ed013b8918a8..fd4bd29bd1f5 100644 --- a/packages/api-contract/src/Abi/index.ts +++ b/packages/api-contract/src/Abi/index.ts @@ -27,23 +27,12 @@ function findMessage (list: T[], messageOrId: T | string } function getLatestMeta (registry: Registry, json: Record): ContractMetadataLatest { - // this is for V1, V2, V3 const vx = enumVersions.find((v) => isObject(json[v])); - - // this was added in V4 - const jsonVersion = json.version as string; - - if (!vx && jsonVersion && !enumVersions.find((v) => v === `V${jsonVersion}`)) { - throw new Error(`Unable to handle version ${jsonVersion}`); - } - - const metadata = registry.createType('ContractMetadata', + const metadata = registry.createType('ContractMetadata', vx ? { [vx]: json[vx] } - : jsonVersion - ? { [`V${jsonVersion}`]: json } - : { V0: json } - ); + : { V0: json } + ) as unknown as ContractMetadata; const converter = convertVersions.find(([v]) => metadata[`is${v}`]); if (!converter) { diff --git a/packages/api-contract/src/Abi/toLatest.ts b/packages/api-contract/src/Abi/toLatest.ts index 0159e7b65f69..46a4c23dfdee 100644 --- a/packages/api-contract/src/Abi/toLatest.ts +++ b/packages/api-contract/src/Abi/toLatest.ts @@ -1,17 +1,16 @@ // Copyright 2017-2022 @polkadot/api-contract authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { ContractMetadataLatest, ContractMetadataV4 } from '@polkadot/types/interfaces'; +import type { ContractMetadataLatest, ContractMetadataV3 } from '@polkadot/types/interfaces'; import type { Registry } from '@polkadot/types/types'; import { v0ToV1 } from './toV1'; import { v1ToV2 } from './toV2'; import { v2ToV3 } from './toV3'; -import { v3ToV4 } from './toV4'; // The versions where an enum is used, aka V0 is missing // (Order from newest, i.e. we expect more on newest vs oldest) -export const enumVersions = ['V4', 'V3', 'V2', 'V1']; +export const enumVersions = ['V3', 'V2', 'V1']; type Versions = typeof enumVersions[number] | 'V0'; @@ -23,17 +22,15 @@ function createConverter (next: (registry: Registry, input: O) => Contrac next(registry, step(registry, input)); } -function v4ToLatest (registry: Registry, v4: ContractMetadataV4): ContractMetadataLatest { - return v4; +export function v3ToLatest (registry: Registry, v3: ContractMetadataV3): ContractMetadataLatest { + return v3; } -export const v3ToLatest = createConverter(v4ToLatest, v3ToV4); export const v2ToLatest = createConverter(v3ToLatest, v2ToV3); export const v1ToLatest = createConverter(v2ToLatest, v1ToV2); export const v0ToLatest = createConverter(v1ToLatest, v0ToV1); export const convertVersions: [Versions, Converter][] = [ - ['V4', v4ToLatest], ['V3', v3ToLatest], ['V2', v2ToLatest], ['V1', v1ToLatest], diff --git a/packages/api-contract/src/Abi/toV4.ts b/packages/api-contract/src/Abi/toV4.ts deleted file mode 100644 index 12db921d4db5..000000000000 --- a/packages/api-contract/src/Abi/toV4.ts +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2017-2022 @polkadot/api-contract authors & contributors -// SPDX-License-Identifier: Apache-2.0 - -import type { ContractMetadataV3, ContractMetadataV4 } from '@polkadot/types/interfaces'; -import type { Registry } from '@polkadot/types/types'; - -export function v3ToV4 (registry: Registry, v3: ContractMetadataV3): ContractMetadataV4 { - return v3; -} diff --git a/packages/api-contract/src/test/compare/ink_v4_flipperContract.test.json b/packages/api-contract/src/test/compare/ink_v4_flipperContract.test.json deleted file mode 100644 index e7e9211fa21f..000000000000 --- a/packages/api-contract/src/test/compare/ink_v4_flipperContract.test.json +++ /dev/null @@ -1,9 +0,0 @@ -[ - { - "info": "Plain", - "lookupIndex": 0, - "type": "bool", - "docs": [], - "namespace": "" - } -] \ No newline at end of file diff --git a/packages/api-contract/src/test/compare/ink_v4_flipperMetadata.test.json b/packages/api-contract/src/test/compare/ink_v4_flipperMetadata.test.json deleted file mode 100644 index e7e9211fa21f..000000000000 --- a/packages/api-contract/src/test/compare/ink_v4_flipperMetadata.test.json +++ /dev/null @@ -1,9 +0,0 @@ -[ - { - "info": "Plain", - "lookupIndex": 0, - "type": "bool", - "docs": [], - "namespace": "" - } -] \ No newline at end of file diff --git a/packages/api-contract/src/test/contracts/ink/index.ts b/packages/api-contract/src/test/contracts/ink/index.ts index 9514b8b579fd..ce076a2181e5 100644 --- a/packages/api-contract/src/test/contracts/ink/index.ts +++ b/packages/api-contract/src/test/contracts/ink/index.ts @@ -6,6 +6,6 @@ import * as v0 from './v0'; import * as v1 from './v1'; import * as v2 from './v2'; import * as v3 from './v3'; -import * as v4 from './v4'; +// import * as v4 from './v4'; -export default createVersionedExport({ v0, v1, v2, v3, v4 }); +export default createVersionedExport({ v0, v1, v2, v3 }); diff --git a/packages/types-augment/src/registry/interfaces.ts b/packages/types-augment/src/registry/interfaces.ts index 8c6446da438b..530ac825b2e2 100644 --- a/packages/types-augment/src/registry/interfaces.ts +++ b/packages/types-augment/src/registry/interfaces.ts @@ -24,7 +24,7 @@ import type { StatementKind } from '@polkadot/types/interfaces/claims'; import type { CollectiveOrigin, MemberCount, ProposalIndex, Votes, VotesTo230 } from '@polkadot/types/interfaces/collective'; import type { AuthorityId, RawVRFOutput } from '@polkadot/types/interfaces/consensus'; import type { AliveContractInfo, CodeHash, CodeSource, CodeUploadRequest, CodeUploadResult, CodeUploadResultValue, ContractCallFlags, ContractCallRequest, ContractExecResult, ContractExecResultOk, ContractExecResultResult, ContractExecResultSuccessTo255, ContractExecResultSuccessTo260, ContractExecResultTo255, ContractExecResultTo260, ContractExecResultTo267, ContractInfo, ContractInstantiateResult, ContractInstantiateResultTo267, ContractInstantiateResultTo299, ContractReturnFlags, ContractStorageKey, DeletedContract, ExecReturnValue, Gas, HostFnWeights, HostFnWeightsTo264, InstantiateRequest, InstantiateRequestV1, InstantiateRequestV2, InstantiateReturnValue, InstantiateReturnValueOk, InstantiateReturnValueTo267, InstructionWeights, Limits, LimitsTo264, PrefabWasmModule, RentProjection, Schedule, ScheduleTo212, ScheduleTo258, ScheduleTo264, SeedOf, StorageDeposit, TombstoneContractInfo, TrieId } from '@polkadot/types/interfaces/contracts'; -import type { ContractConstructorSpecLatest, ContractConstructorSpecV0, ContractConstructorSpecV1, ContractConstructorSpecV2, ContractConstructorSpecV3, ContractContractSpecV0, ContractContractSpecV1, ContractContractSpecV2, ContractContractSpecV3, ContractContractSpecV4, ContractCryptoHasher, ContractDiscriminant, ContractDisplayName, ContractEventParamSpecLatest, ContractEventParamSpecV0, ContractEventParamSpecV2, ContractEventSpecLatest, ContractEventSpecV0, ContractEventSpecV1, ContractEventSpecV2, ContractLayoutArray, ContractLayoutCell, ContractLayoutEnum, ContractLayoutHash, ContractLayoutHashingStrategy, ContractLayoutKey, ContractLayoutStruct, ContractLayoutStructField, ContractMessageParamSpecLatest, ContractMessageParamSpecV0, ContractMessageParamSpecV2, ContractMessageSpecLatest, ContractMessageSpecV0, ContractMessageSpecV1, ContractMessageSpecV2, ContractMetadata, ContractMetadataLatest, ContractMetadataV0, ContractMetadataV1, ContractMetadataV2, ContractMetadataV3, ContractMetadataV4, ContractProject, ContractProjectContract, ContractProjectInfo, ContractProjectSource, ContractProjectV0, ContractSelector, ContractStorageLayout, ContractTypeSpec } from '@polkadot/types/interfaces/contractsAbi'; +import type { ContractConstructorSpecLatest, ContractConstructorSpecV0, ContractConstructorSpecV1, ContractConstructorSpecV2, ContractConstructorSpecV3, ContractContractSpecV0, ContractContractSpecV1, ContractContractSpecV2, ContractContractSpecV3, ContractCryptoHasher, ContractDiscriminant, ContractDisplayName, ContractEventParamSpecLatest, ContractEventParamSpecV0, ContractEventParamSpecV2, ContractEventSpecLatest, ContractEventSpecV0, ContractEventSpecV1, ContractEventSpecV2, ContractLayoutArray, ContractLayoutCell, ContractLayoutEnum, ContractLayoutHash, ContractLayoutHashingStrategy, ContractLayoutKey, ContractLayoutStruct, ContractLayoutStructField, ContractMessageParamSpecLatest, ContractMessageParamSpecV0, ContractMessageParamSpecV2, ContractMessageSpecLatest, ContractMessageSpecV0, ContractMessageSpecV1, ContractMessageSpecV2, ContractMetadata, ContractMetadataLatest, ContractMetadataV0, ContractMetadataV1, ContractMetadataV2, ContractMetadataV3, ContractProject, ContractProjectContract, ContractProjectInfo, ContractProjectSource, ContractProjectV0, ContractSelector, ContractStorageLayout, ContractTypeSpec } from '@polkadot/types/interfaces/contractsAbi'; import type { FundIndex, FundInfo, LastContribution, TrieIndex } from '@polkadot/types/interfaces/crowdloan'; import type { CollationInfo, CollationInfoV1, ConfigData, MessageId, OverweightIndex, PageCounter, PageIndexData } from '@polkadot/types/interfaces/cumulus'; import type { AccountVote, AccountVoteSplit, AccountVoteStandard, Conviction, Delegations, PreimageStatus, PreimageStatusAvailable, PriorLock, PropIndex, Proposal, ProxyState, ReferendumIndex, ReferendumInfo, ReferendumInfoFinished, ReferendumInfoTo239, ReferendumStatus, Tally, Voting, VotingDelegating, VotingDirect, VotingDirectVote } from '@polkadot/types/interfaces/democracy'; @@ -252,7 +252,6 @@ declare module '@polkadot/types/types/registry' { ContractContractSpecV1: ContractContractSpecV1; ContractContractSpecV2: ContractContractSpecV2; ContractContractSpecV3: ContractContractSpecV3; - ContractContractSpecV4: ContractContractSpecV4; ContractCryptoHasher: ContractCryptoHasher; ContractDiscriminant: ContractDiscriminant; ContractDisplayName: ContractDisplayName; @@ -296,7 +295,6 @@ declare module '@polkadot/types/types/registry' { ContractMetadataV1: ContractMetadataV1; ContractMetadataV2: ContractMetadataV2; ContractMetadataV3: ContractMetadataV3; - ContractMetadataV4: ContractMetadataV4; ContractProject: ContractProject; ContractProjectContract: ContractProjectContract; ContractProjectInfo: ContractProjectInfo; diff --git a/packages/types/src/interfaces/contractsAbi/definitions.ts b/packages/types/src/interfaces/contractsAbi/definitions.ts index 904bd1130cd6..20d2430aa5a0 100644 --- a/packages/types/src/interfaces/contractsAbi/definitions.ts +++ b/packages/types/src/interfaces/contractsAbi/definitions.ts @@ -106,7 +106,6 @@ const spec = { events: 'Vec', docs: 'Vec' }, - ContractContractSpecV4: 'ContractContractSpecV3', ContractDisplayName: 'SiPath', ContractEventParamSpecV0: { name: 'Text', @@ -198,8 +197,6 @@ const ContractMetadataV3 = { spec: 'ContractContractSpecV3' }; -const ContractMetadataV4 = ContractMetadataV3; - const ContractProjectInfo = { source: 'ContractProjectSource', contract: 'ContractProjectContract' @@ -211,7 +208,7 @@ const latest = { ContractEventParamSpecLatest: 'ContractEventParamSpecV2', ContractMessageParamSpecLatest: 'ContractMessageParamSpecV2', ContractMessageSpecLatest: 'ContractMessageSpecV2', - ContractMetadataLatest: 'ContractMetadataV4' + ContractMetadataLatest: 'ContractMetadataV3' }; export default { @@ -222,14 +219,12 @@ export default { ContractMetadataV1, ContractMetadataV2, ContractMetadataV3, - ContractMetadataV4, ContractMetadata: { _enum: { V0: 'ContractMetadataV0', V1: 'ContractMetadataV1', V2: 'ContractMetadataV2', - V3: 'ContractMetadataV3', - V4: 'ContractMetadataV4' + V3: 'ContractMetadataV3' } }, ContractProjectV0: objectSpread({ metadataVersion: 'Text' }, ContractProjectInfo, ContractMetadataV0), diff --git a/packages/types/src/interfaces/contractsAbi/types.ts b/packages/types/src/interfaces/contractsAbi/types.ts index f58598897b02..39e411a42f9d 100644 --- a/packages/types/src/interfaces/contractsAbi/types.ts +++ b/packages/types/src/interfaces/contractsAbi/types.ts @@ -74,9 +74,6 @@ export interface ContractContractSpecV3 extends Struct { readonly docs: Vec; } -/** @name ContractContractSpecV4 */ -export interface ContractContractSpecV4 extends ContractContractSpecV3 {} - /** @name ContractCryptoHasher */ export interface ContractCryptoHasher extends Enum { readonly isBlake2x256: boolean; @@ -243,13 +240,11 @@ export interface ContractMetadata extends Enum { readonly asV2: ContractMetadataV2; readonly isV3: boolean; readonly asV3: ContractMetadataV3; - readonly isV4: boolean; - readonly asV4: ContractMetadataV4; - readonly type: 'V0' | 'V1' | 'V2' | 'V3' | 'V4'; + readonly type: 'V0' | 'V1' | 'V2' | 'V3'; } /** @name ContractMetadataLatest */ -export interface ContractMetadataLatest extends ContractMetadataV4 {} +export interface ContractMetadataLatest extends ContractMetadataV3 {} /** @name ContractMetadataV0 */ export interface ContractMetadataV0 extends Struct { @@ -276,12 +271,6 @@ export interface ContractMetadataV3 extends Struct { readonly spec: ContractContractSpecV3; } -/** @name ContractMetadataV4 */ -export interface ContractMetadataV4 extends Struct { - readonly types: Vec; - readonly spec: ContractContractSpecV3; -} - /** @name ContractProject */ export interface ContractProject extends ITuple<[ContractProjectInfo, ContractMetadata]> {} From 0fb87e4fc58488f3e983f170b67b93ddf31c65e2 Mon Sep 17 00:00:00 2001 From: Jaco Date: Thu, 1 Sep 2022 16:38:27 +0300 Subject: [PATCH 06/10] Adjust --- packages/types-augment/src/registry/interfaces.ts | 3 ++- packages/types/src/generic/MultiAddress.ts | 4 ++-- packages/types/src/interfaces/runtime/types.ts | 7 +++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/types-augment/src/registry/interfaces.ts b/packages/types-augment/src/registry/interfaces.ts index 530ac825b2e2..be57e64572b8 100644 --- a/packages/types-augment/src/registry/interfaces.ts +++ b/packages/types-augment/src/registry/interfaces.ts @@ -52,7 +52,7 @@ import type { ProxyAnnouncement, ProxyDefinition, ProxyType } from '@polkadot/ty import type { AccountStatus, AccountValidity } from '@polkadot/types/interfaces/purchase'; import type { ActiveRecovery, RecoveryConfig } from '@polkadot/types/interfaces/recovery'; import type { RpcMethods } from '@polkadot/types/interfaces/rpc'; -import type { AccountId, AccountId20, AccountId32, AccountIdOf, AccountIndex, Address, AssetId, Balance, BalanceOf, Block, BlockNumber, BlockNumberFor, BlockNumberOf, Call, CallHash, CallHashOf, ChangesTrieConfiguration, ChangesTrieSignal, CodecHash, Consensus, ConsensusEngineId, CrateVersion, Digest, DigestItem, EncodedJustification, ExtrinsicsWeight, Fixed128, Fixed64, FixedI128, FixedI64, FixedU128, FixedU64, H1024, H128, H160, H2048, H256, H32, H512, H64, Hash, Header, HeaderPartial, I32F32, Index, IndicesLookupSource, Justification, Justifications, KeyTypeId, KeyValue, LockIdentifier, LookupSource, LookupTarget, ModuleId, Moment, MultiAddress, MultiSigner, OpaqueCall, Origin, OriginCaller, PalletId, PalletVersion, PalletsOrigin, Pays, PerU16, Perbill, Percent, Permill, Perquintill, Phantom, PhantomData, PreRuntime, Releases, RuntimeDbWeight, Seal, SealV0, SignedBlock, SignedBlockWithJustification, SignedBlockWithJustifications, Slot, SlotDuration, StorageData, StorageInfo, StorageProof, TransactionInfo, TransactionLongevity, TransactionPriority, TransactionStorageProof, TransactionTag, U32F32, ValidatorId, ValidatorIdOf, Weight, WeightMultiplier } from '@polkadot/types/interfaces/runtime'; +import type { AccountId, AccountId20, AccountId32, AccountId33, AccountIdOf, AccountIndex, Address, AssetId, Balance, BalanceOf, Block, BlockNumber, BlockNumberFor, BlockNumberOf, Call, CallHash, CallHashOf, ChangesTrieConfiguration, ChangesTrieSignal, CodecHash, Consensus, ConsensusEngineId, CrateVersion, Digest, DigestItem, EncodedJustification, ExtrinsicsWeight, Fixed128, Fixed64, FixedI128, FixedI64, FixedU128, FixedU64, H1024, H128, H160, H2048, H256, H32, H512, H64, Hash, Header, HeaderPartial, I32F32, Index, IndicesLookupSource, Justification, Justifications, KeyTypeId, KeyValue, LockIdentifier, LookupSource, LookupTarget, ModuleId, Moment, MultiAddress, MultiSigner, OpaqueCall, Origin, OriginCaller, PalletId, PalletVersion, PalletsOrigin, Pays, PerU16, Perbill, Percent, Permill, Perquintill, Phantom, PhantomData, PreRuntime, Releases, RuntimeDbWeight, Seal, SealV0, SignedBlock, SignedBlockWithJustification, SignedBlockWithJustifications, Slot, SlotDuration, StorageData, StorageInfo, StorageProof, TransactionInfo, TransactionLongevity, TransactionPriority, TransactionStorageProof, TransactionTag, U32F32, ValidatorId, ValidatorIdOf, Weight, WeightMultiplier } from '@polkadot/types/interfaces/runtime'; import type { Si0Field, Si0LookupTypeId, Si0Path, Si0Type, Si0TypeDef, Si0TypeDefArray, Si0TypeDefBitSequence, Si0TypeDefCompact, Si0TypeDefComposite, Si0TypeDefPhantom, Si0TypeDefPrimitive, Si0TypeDefSequence, Si0TypeDefTuple, Si0TypeDefVariant, Si0TypeParameter, Si0Variant, Si1Field, Si1LookupTypeId, Si1Path, Si1Type, Si1TypeDef, Si1TypeDefArray, Si1TypeDefBitSequence, Si1TypeDefCompact, Si1TypeDefComposite, Si1TypeDefPrimitive, Si1TypeDefSequence, Si1TypeDefTuple, Si1TypeDefVariant, Si1TypeParameter, Si1Variant, SiField, SiLookupTypeId, SiPath, SiType, SiTypeDef, SiTypeDefArray, SiTypeDefBitSequence, SiTypeDefCompact, SiTypeDefComposite, SiTypeDefPrimitive, SiTypeDefSequence, SiTypeDefTuple, SiTypeDefVariant, SiTypeParameter, SiVariant } from '@polkadot/types/interfaces/scaleInfo'; import type { Period, Priority, SchedulePeriod, SchedulePriority, Scheduled, ScheduledTo254, TaskAddress } from '@polkadot/types/interfaces/scheduler'; import type { BeefyKey, FullIdentification, IdentificationTuple, Keys, MembershipProof, SessionIndex, SessionKeys1, SessionKeys10, SessionKeys10B, SessionKeys2, SessionKeys3, SessionKeys4, SessionKeys5, SessionKeys6, SessionKeys6B, SessionKeys7, SessionKeys7B, SessionKeys8, SessionKeys8B, SessionKeys9, SessionKeys9B, ValidatorCount } from '@polkadot/types/interfaces/session'; @@ -78,6 +78,7 @@ declare module '@polkadot/types/types/registry' { AccountId: AccountId; AccountId20: AccountId20; AccountId32: AccountId32; + AccountId33: AccountId33; AccountIdOf: AccountIdOf; AccountIndex: AccountIndex; AccountInfo: AccountInfo; diff --git a/packages/types/src/generic/MultiAddress.ts b/packages/types/src/generic/MultiAddress.ts index 66f5aa95c720..a799a48391cf 100644 --- a/packages/types/src/generic/MultiAddress.ts +++ b/packages/types/src/generic/MultiAddress.ts @@ -7,7 +7,7 @@ import { Enum } from '@polkadot/types-codec'; import { isBn, isNumber, isString, isU8a } from '@polkadot/util'; import { decodeAddress } from '@polkadot/util-crypto'; -import { GenericAccountId } from './AccountId'; +import { GenericAccountId32 } from './AccountId'; import { GenericAccountIndex } from './AccountIndex'; function decodeU8a (registry: Registry, u8a: Uint8Array): unknown { @@ -23,7 +23,7 @@ function decodeU8a (registry: Registry, u8a: Uint8Array): unknown { } function decodeMultiAny (registry: Registry, value?: unknown): unknown { - if (value instanceof GenericAccountId) { + if (value instanceof GenericAccountId32) { return { Id: value }; } else if (isU8a(value)) { // NOTE This is after the AccountId check (which is U8a) diff --git a/packages/types/src/interfaces/runtime/types.ts b/packages/types/src/interfaces/runtime/types.ts index 6996860f018b..68632ae53856 100644 --- a/packages/types/src/interfaces/runtime/types.ts +++ b/packages/types/src/interfaces/runtime/types.ts @@ -1,7 +1,7 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit /* eslint-disable */ -import type { GenericAccountId, GenericAccountIndex, GenericBlock, GenericCall, GenericConsensusEngineId, GenericEthereumAccountId, GenericLookupSource, GenericMultiAddress, StorageKey } from '@polkadot/types'; +import type { GenericAccountId32, GenericAccountId33, GenericAccountIndex, GenericBlock, GenericCall, GenericConsensusEngineId, GenericEthereumAccountId, GenericLookupSource, GenericMultiAddress, StorageKey } from '@polkadot/types'; import type { Bytes, Compact, DoNotConstruct, Enum, Int, Null, Option, Struct, U8aFixed, UInt, Vec, u16, u32, u64, u8 } from '@polkadot/types-codec'; import type { ITuple } from '@polkadot/types-codec/types'; import type { AuthorityId } from '@polkadot/types/interfaces/consensus'; @@ -15,7 +15,10 @@ export interface AccountId extends AccountId32 {} export interface AccountId20 extends GenericEthereumAccountId {} /** @name AccountId32 */ -export interface AccountId32 extends GenericAccountId {} +export interface AccountId32 extends GenericAccountId32 {} + +/** @name AccountId33 */ +export interface AccountId33 extends GenericAccountId33 {} /** @name AccountIdOf */ export interface AccountIdOf extends AccountId {} From f49923aff20c5b67e8f09c702e0706b74cd2cd15 Mon Sep 17 00:00:00 2001 From: Jaco Date: Thu, 1 Sep 2022 16:45:15 +0300 Subject: [PATCH 07/10] Adjust, keep exports --- packages/types/src/generic/AccountId.ts | 2 +- packages/types/src/generic/MultiAddress.ts | 4 ++-- packages/types/src/generic/index.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/types/src/generic/AccountId.ts b/packages/types/src/generic/AccountId.ts index 44aebece0a7b..58971e0de568 100644 --- a/packages/types/src/generic/AccountId.ts +++ b/packages/types/src/generic/AccountId.ts @@ -85,7 +85,7 @@ class BaseAccountId extends U8aFixed { * underlying PublicKeys (32 bytes in length), we extend from U8aFixed which is * just a Uint8Array wrapper with a fixed length. */ -export class GenericAccountId32 extends BaseAccountId { +export class GenericAccountId extends BaseAccountId { constructor (registry: Registry, value?: AnyU8a) { super(registry, 256, value); } diff --git a/packages/types/src/generic/MultiAddress.ts b/packages/types/src/generic/MultiAddress.ts index a799a48391cf..66f5aa95c720 100644 --- a/packages/types/src/generic/MultiAddress.ts +++ b/packages/types/src/generic/MultiAddress.ts @@ -7,7 +7,7 @@ import { Enum } from '@polkadot/types-codec'; import { isBn, isNumber, isString, isU8a } from '@polkadot/util'; import { decodeAddress } from '@polkadot/util-crypto'; -import { GenericAccountId32 } from './AccountId'; +import { GenericAccountId } from './AccountId'; import { GenericAccountIndex } from './AccountIndex'; function decodeU8a (registry: Registry, u8a: Uint8Array): unknown { @@ -23,7 +23,7 @@ function decodeU8a (registry: Registry, u8a: Uint8Array): unknown { } function decodeMultiAny (registry: Registry, value?: unknown): unknown { - if (value instanceof GenericAccountId32) { + if (value instanceof GenericAccountId) { return { Id: value }; } else if (isU8a(value)) { // NOTE This is after the AccountId check (which is U8a) diff --git a/packages/types/src/generic/index.ts b/packages/types/src/generic/index.ts index 80d89d105451..5d10f9bcea91 100644 --- a/packages/types/src/generic/index.ts +++ b/packages/types/src/generic/index.ts @@ -3,7 +3,7 @@ export * from '../ethereum'; -export { GenericAccountId32 as GenericAccountId, GenericAccountId32, GenericAccountId33 } from './AccountId'; +export { GenericAccountId, GenericAccountId as GenericAccountId32, GenericAccountId33 } from './AccountId'; export { GenericAccountIndex } from './AccountIndex'; export { GenericBlock } from './Block'; export { GenericCall } from './Call'; From 3258e5395cde2a70dbb99ead5706df474ba01b88 Mon Sep 17 00:00:00 2001 From: Jaco Date: Thu, 1 Sep 2022 16:48:31 +0300 Subject: [PATCH 08/10] Adjust test --- packages/types/src/generic/AccountId.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/types/src/generic/AccountId.spec.ts b/packages/types/src/generic/AccountId.spec.ts index 2f9c7f34a037..e7c1d94d6bb4 100644 --- a/packages/types/src/generic/AccountId.spec.ts +++ b/packages/types/src/generic/AccountId.spec.ts @@ -59,8 +59,8 @@ describe('AccountId', (): void => { ); testDecode( 'AccountId33', - registry.createType('AccountId', '0x0102030405060708010203040506070801020304050607080102030405060708'), - '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF' + registry.createType('AccountId33', '0x098765430987654309876543098765430987654309876543098765430987654309'), + '4o8ZUWNkE3mjgW73xGVFHFoTve33Uyw5jLhgDFKF7PTEVo2k' ); testDecode('hex', '0x0102030405060708010203040506070801020304050607080102030405060708', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'); testDecode('string', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'); From 66c861dfd94b94f37f184cfd66e023f384d6db6a Mon Sep 17 00:00:00 2001 From: Jaco Date: Thu, 1 Sep 2022 16:49:07 +0300 Subject: [PATCH 09/10] Adjust --- packages/types/src/generic/AccountId.spec.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/types/src/generic/AccountId.spec.ts b/packages/types/src/generic/AccountId.spec.ts index e7c1d94d6bb4..fbe4c55178b2 100644 --- a/packages/types/src/generic/AccountId.spec.ts +++ b/packages/types/src/generic/AccountId.spec.ts @@ -7,7 +7,6 @@ import { Raw } from '@polkadot/types-codec'; import jsonVec from '@polkadot/types-support/json/AccountIdVec.001.json' assert { type: 'json' }; import { TypeRegistry } from '../create'; -import { GenericAccountId32 as AccountId } from '.'; describe('AccountId', (): void => { const registry = new TypeRegistry(); @@ -37,7 +36,7 @@ describe('AccountId', (): void => { }); describe('decoding', (): void => { - const testDecode = (type: string, input: Uint8Array | string | AccountId, expected: string): void => + const testDecode = (type: string, input: Uint8Array | string, expected: string): void => it(`can decode from ${type}`, (): void => { expect( registry From 53e6a3a2bee4a617e8e102a8a5ad353d9557e000 Mon Sep 17 00:00:00 2001 From: Jaco Date: Thu, 1 Sep 2022 16:58:28 +0300 Subject: [PATCH 10/10] Sizing --- packages/types/src/generic/AccountId.spec.ts | 2 +- packages/types/src/generic/AccountId.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/types/src/generic/AccountId.spec.ts b/packages/types/src/generic/AccountId.spec.ts index fbe4c55178b2..76c6c4105db5 100644 --- a/packages/types/src/generic/AccountId.spec.ts +++ b/packages/types/src/generic/AccountId.spec.ts @@ -59,7 +59,7 @@ describe('AccountId', (): void => { testDecode( 'AccountId33', registry.createType('AccountId33', '0x098765430987654309876543098765430987654309876543098765430987654309'), - '4o8ZUWNkE3mjgW73xGVFHFoTve33Uyw5jLhgDFKF7PTEVo2k' + '5CHCWUYMmDGeJjiuaQ1LnrsAWacDhiTAV6vCfytSxoqBdCCb' ); testDecode('hex', '0x0102030405060708010203040506070801020304050607080102030405060708', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'); testDecode('string', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'); diff --git a/packages/types/src/generic/AccountId.ts b/packages/types/src/generic/AccountId.ts index 58971e0de568..197ff47e1fc5 100644 --- a/packages/types/src/generic/AccountId.ts +++ b/packages/types/src/generic/AccountId.ts @@ -28,7 +28,7 @@ class BaseAccountId extends U8aFixed { const decodedBits = decoded.length * 8; // Part of stream containing >= 32 bytes or a all empty (defaults) - if (decodedBits !== allowedBits && decoded.some((b) => b)) { + if (decodedBits < allowedBits && decoded.some((b) => b)) { throw new Error(`Invalid AccountId provided, expected ${allowedBits >> 3} bytes, found ${decoded.length}`); }