Skip to content

Commit 1643ec7

Browse files
authored
Provide chain properties for contract registry (#2714)
1 parent 76c206d commit 1643ec7

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

packages/api-contract/src/Abi.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import { AnyJson } from '@polkadot/types/types';
5-
import { InkConstructorSpec, InkMessageSpec } from '@polkadot/types/interfaces';
5+
import { ChainProperties, InkConstructorSpec, InkMessageSpec } from '@polkadot/types/interfaces';
66
import { AbiConstructor, AbiMessage, AbiMessageParam } from './types';
77

88
import { assert, isNumber, isObject, isString, stringCamelCase } from '@polkadot/util';
@@ -28,14 +28,14 @@ export default class Abi extends ContractRegistry {
2828

2929
public readonly messages: AbiMessage[];
3030

31-
constructor (abiJson: AnyJson) {
31+
constructor (abiJson: AnyJson, chainProperties?: ChainProperties) {
3232
const json = isString(abiJson)
3333
? JSON.parse(abiJson) as AnyJson
3434
: abiJson;
3535

3636
assert(isObject(json) && !Array.isArray(json) && json.metadataVersion && isObject(json.spec) && !Array.isArray(json.spec) && Array.isArray(json.spec.constructors) && Array.isArray(json.spec.messages), 'Invalid JSON ABI structure supplied, expected a recent metadata version');
3737

38-
super(json);
38+
super(json, chainProperties);
3939

4040
this.json = json;
4141
this.constructors = this.project.spec.constructors.map((spec: InkConstructorSpec, index) =>

packages/api-contract/src/ContractRegistry.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import { InkProject, MtField, MtLookupTypeId, MtType, MtTypeDefArray, MtTypeDefVariant, MtTypeDefSequence, MtTypeDefTuple, MtVariant } from '@polkadot/types/interfaces';
4+
import { ChainProperties, InkProject, MtField, MtLookupTypeId, MtType, MtTypeDefArray, MtTypeDefVariant, MtTypeDefSequence, MtTypeDefTuple, MtVariant } from '@polkadot/types/interfaces';
55
import { AnyJson, Registry, TypeDef, TypeDefInfo } from '@polkadot/types/types';
66

77
import { assert, isUndefined } from '@polkadot/util';
@@ -19,8 +19,13 @@ export default class ContractRegistry {
1919

2020
public readonly project: InkProject;
2121

22-
constructor (json: Record<string, AnyJson>) {
22+
constructor (json: Record<string, AnyJson>, chainProperties?: ChainProperties) {
2323
this.registry = new TypeRegistry();
24+
25+
if (chainProperties) {
26+
this.registry.setChainProperties(chainProperties);
27+
}
28+
2429
this.project = this.registry.createType('InkProject', json);
2530

2631
// Generate TypeDefs for each provided registry type

packages/api-contract/src/base/Base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default abstract class Base<ApiType extends ApiTypes> {
2121
constructor (api: ApiBase<ApiType>, abi: AnyJson | Abi, decorateMethod: DecorateMethod<ApiType>) {
2222
this.abi = abi instanceof Abi
2323
? abi
24-
: new Abi(abi);
24+
: new Abi(abi, api.registry.getChainProperties());
2525
this.api = api;
2626
this.registry = this.abi.registry;
2727
this._decorateMethod = decorateMethod;

0 commit comments

Comments
 (0)