Ensure *.d.ts files are generated in outputs (#4362)

* Ensure *.d.ts files are generated in outputs

* Adjust

* Additional dep

* Update

* Update refs
This commit is contained in:
Jaco
2021-12-20 10:00:10 +02:00
committed by GitHub
parent aa704210f8
commit 67ee8b08d9
21 changed files with 80 additions and 64 deletions
+5 -5
View File
@@ -1,8 +1,8 @@
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Bytes, PortableRegistry } from '@polkadot/types';
import type { ChainProperties, ContractConstructorSpecLatest, ContractEventSpecLatest, ContractMessageParamSpecLatest, ContractMessageSpecLatest, ContractMetadataLatest, ContractProjectInfo } from '@polkadot/types/interfaces';
import type { Bytes } from '@polkadot/types';
import type { ChainProperties, ContractConstructorSpecLatest, ContractEventSpecLatest, ContractMessageParamSpecLatest, ContractMessageSpecLatest, ContractMetadata, ContractMetadataLatest, ContractProjectInfo } from '@polkadot/types/interfaces';
import type { Codec, Registry } from '@polkadot/types/types';
import type { AbiConstructor, AbiEvent, AbiMessage, AbiParam, DecodedEvent, DecodedMessage } from '../types';
@@ -36,7 +36,7 @@ function getLatestMeta (registry: Registry, json: Record<string, unknown>): Cont
: isObject(json.V1)
? { V1: json.V1 }
: { V0: json }
);
) as unknown as ContractMetadata;
return metadata.isV2
? metadata.asV2
@@ -47,9 +47,9 @@ function getLatestMeta (registry: Registry, json: Record<string, unknown>): Cont
function parseJson (json: Record<string, unknown>, chainProperties?: ChainProperties): [Record<string, unknown>, Registry, ContractMetadataLatest, ContractProjectInfo] {
const registry = new TypeRegistry();
const info = registry.createType('ContractProjectInfo', json);
const info = registry.createType('ContractProjectInfo', json) as unknown as ContractProjectInfo;
const latest = getLatestMeta(registry, json);
const lookup = registry.createType<PortableRegistry>('PortableRegistry', { types: latest.types });
const lookup = registry.createType('PortableRegistry', { types: latest.types });
// attach the lookup to the registry - now the types are known
registry.setLookup(lookup);
+9 -3
View File
@@ -2,8 +2,8 @@
// SPDX-License-Identifier: Apache-2.0
import type { Text } from '@polkadot/types';
import type { ContractMetadataV1, ContractMetadataV2 } from '@polkadot/types/interfaces';
import type { InterfaceTypes, Registry } from '@polkadot/types/types';
import type { ContractConstructorSpecV0, ContractEventSpecV0, ContractMessageSpecV0, ContractMetadataV1, ContractMetadataV2 } from '@polkadot/types/interfaces';
import type { Registry } from '@polkadot/types/types';
import { objectSpread } from '@polkadot/util';
@@ -13,8 +13,14 @@ interface NamedEntry {
name: Text | Text[];
}
type GetArgsType<T extends WithArgs> = T extends 'ContractConstructorSpec'
? ContractConstructorSpecV0
: T extends ContractEventSpecV0
? ContractEventSpecV0
: ContractMessageSpecV0;
interface ArgsEntry <T extends WithArgs> extends NamedEntry {
args: InterfaceTypes[`${T}V0`]['args'][0][];
args: GetArgsType<T>['args'][0][];
}
const ARG_TYPES = {
+4 -3
View File
@@ -3,8 +3,9 @@
import type { SubmittableExtrinsic } from '@polkadot/api/submittable/types';
import type { ApiTypes, DecorateMethod } from '@polkadot/api/types';
import type { EventRecord } from '@polkadot/types/interfaces';
import type { AccountId, EventRecord } from '@polkadot/types/interfaces';
import type { ISubmittableResult } from '@polkadot/types/types';
import type { Codec } from '@polkadot/types-codec/types';
import type { AbiConstructor, BlueprintOptions } from '../types';
import type { MapConstructorExec } from './types';
@@ -73,9 +74,9 @@ export class Code<ApiType extends ApiTypes> extends Base<ApiType> {
new CodeSubmittableResult(result, ...(applyOnEvent(result, ['CodeStored', 'Instantiated'], (records: EventRecord[]) =>
records.reduce<[Blueprint<ApiType>?, Contract<ApiType>?]>(([blueprint, contract], { event }) =>
this.api.events.contracts.Instantiated.is(event)
? [blueprint, new Contract<ApiType>(this.api, this.abi, event.data[1], this._decorateMethod)]
? [blueprint, new Contract<ApiType>(this.api, this.abi, (event as unknown as { data: [Codec, AccountId] }).data[1], this._decorateMethod)]
: this.api.events.contracts.CodeStored.is(event)
? [new Blueprint<ApiType>(this.api, this.abi, event.data[0], this._decorateMethod), contract]
? [new Blueprint<ApiType>(this.api, this.abi, (event as unknown as { data: [AccountId] }).data[0], this._decorateMethod), contract]
: [blueprint, contract],
[])
) || []))
+1 -1
View File
@@ -100,7 +100,7 @@ export class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
? isCall
? MAX_CALL_GAS
: (this.api.consts.system.blockWeights
? this.api.consts.system.blockWeights.maxBlock
? (this.api.consts.system.blockWeights as unknown as { maxBlock: Weight }).maxBlock
: this.api.consts.system.maximumBlockWeight as Weight
).muln(64).div(BN_HUNDRED)
: gasLimit;