-
Notifications
You must be signed in to change notification settings - Fork 355
/
Base.ts
42 lines (32 loc) · 1.66 KB
/
Base.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2017-2023 @polkadot/api authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ApiTypes, DecorateMethod } from '@polkadot/api/types';
import type { WeightV2 } from '@polkadot/types/interfaces';
import type { Registry } from '@polkadot/types/types';
import { ApiBase } from '@polkadot/api/base';
import { isFunction } from '@polkadot/util';
import { Abi } from '../Abi';
export abstract class Base<ApiType extends ApiTypes> {
public readonly abi: Abi;
public readonly api: ApiBase<ApiType>;
protected readonly _decorateMethod: DecorateMethod<ApiType>;
protected readonly _isWeightV1: boolean;
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, decorateMethod: DecorateMethod<ApiType>) {
if (!api || !api.isConnected || !api.tx) {
throw new Error('Your API has not been initialized correctly and is not connected to a chain');
} else if (!api.tx.contracts || !isFunction(api.tx.contracts.instantiateWithCode) || api.tx.contracts.instantiateWithCode.meta.args.length !== 6) {
throw new Error('The runtime does not expose api.tx.contracts.instantiateWithCode with storageDepositLimit');
} else if (!api.call.contractsApi || !isFunction(api.call.contractsApi.call)) {
throw new Error('Your runtime does not expose the api.call.contractsApi.call runtime interfaces');
}
this.abi = abi instanceof Abi
? abi
: new Abi(abi, api.registry.getChainProperties());
this.api = api;
this._decorateMethod = decorateMethod;
this._isWeightV1 = !api.registry.createType<WeightV2>('Weight').proofSize;
}
public get registry (): Registry {
return this.api.registry;
}
}