From e90c72fc8b0fbd6fb8313922c7a36987138471b2 Mon Sep 17 00:00:00 2001 From: Jaco Date: Wed, 23 Jun 2021 15:31:18 +0300 Subject: [PATCH] ABI indexes are 0-based from 0.7+ (#3688) --- packages/api-contract/src/MetaRegistry.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/api-contract/src/MetaRegistry.ts b/packages/api-contract/src/MetaRegistry.ts index 4c4a701a45..7acb04d58b 100644 --- a/packages/api-contract/src/MetaRegistry.ts +++ b/packages/api-contract/src/MetaRegistry.ts @@ -35,8 +35,10 @@ export class MetaRegistry extends TypeRegistry { constructor (metadataVersion: string, chainProperties?: ChainProperties) { super(); - // type indexes are 1-based pre-1.0 and 0-based post-1.0 - this.typeOffset = metadataVersion.split('.')[0] === '0' ? 1 : 0; + const [major, minor] = metadataVersion.split('.').map((n) => parseInt(n, 10)); + + // type indexes are 1-based pre 0.7 and 0-based post + this.typeOffset = (major === 0 && minor < 7) ? 1 : 0; if (chainProperties) { this.setChainProperties(chainProperties);