From de853d9cc04c224080a4a882729bbb973a7017ec Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 29 Jan 2020 18:26:06 +0100 Subject: [PATCH] Add EVM types (#1771) * Add EVM types * Add findError for metadata --- packages/api/src/base/Decorate.ts | 4 +++- packages/api/src/base/Init.ts | 3 --- packages/api/src/base/index.ts | 11 +++++++-- packages/types/src/interfaceRegistry.ts | 7 ++++++ packages/types/src/interfaces/definitions.ts | 1 + .../types/src/interfaces/evm/definitions.ts | 17 ++++++++++++++ packages/types/src/interfaces/evm/index.ts | 4 ++++ packages/types/src/interfaces/evm/types.ts | 23 +++++++++++++++++++ packages/types/src/interfaces/types.ts | 1 + 9 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 packages/types/src/interfaces/evm/definitions.ts create mode 100644 packages/types/src/interfaces/evm/index.ts create mode 100644 packages/types/src/interfaces/evm/types.ts diff --git a/packages/api/src/base/Decorate.ts b/packages/api/src/base/Decorate.ts index c915235cd0..4ef1fc3659 100644 --- a/packages/api/src/base/Decorate.ts +++ b/packages/api/src/base/Decorate.ts @@ -6,7 +6,7 @@ import { Constants, Storage } from '@polkadot/metadata/Decorated/types'; import { RpcInterface } from '@polkadot/rpc-core/jsonrpc.types'; import { InterfaceRegistry } from '@polkadot/types/interfaceRegistry'; import { Call, Hash, RuntimeVersion } from '@polkadot/types/interfaces'; -import { AnyFunction, CallFunction, Codec, CodecArg as Arg, ITuple, InterfaceTypes, ModulesWithCalls, Registry } from '@polkadot/types/types'; +import { AnyFunction, CallFunction, Codec, CodecArg as Arg, ITuple, InterfaceTypes, ModulesWithCalls, Registry, RegistryTypes } from '@polkadot/types/types'; import { SubmittableExtrinsic } from '../submittable/types'; import { ApiInterfaceRx, ApiOptions, ApiTypes, DecorateMethod, DecoratedRpc, DecoratedRpcSection, QueryableModuleStorage, QueryableStorage, QueryableStorageEntry, QueryableStorageMulti, QueryableStorageMultiArg, SubmittableExtrinsicFunction, SubmittableExtrinsics, SubmittableModuleExtrinsics } from '../types'; @@ -131,6 +131,8 @@ export default abstract class Decorate extends Events public abstract createType (type: K, ...params: any[]): InterfaceRegistry[K]; + public abstract registerTypes (types?: RegistryTypes): void; + /** * @returns `true` if the API operates with subscriptions */ diff --git a/packages/api/src/base/Init.ts b/packages/api/src/base/Init.ts index b833d1b698..a993b592c5 100644 --- a/packages/api/src/base/Init.ts +++ b/packages/api/src/base/Init.ts @@ -3,7 +3,6 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { SignedBlock } from '@polkadot/types/interfaces'; -import { RegistryTypes } from '@polkadot/types/types'; import { ApiBase, ApiOptions, ApiTypes, DecorateMethod } from '../types'; import DecoratedMeta from '@polkadot/metadata/Decorated'; @@ -55,8 +54,6 @@ export default abstract class Init extends Decorate { const { metadata = {} } = this._options; diff --git a/packages/api/src/base/index.ts b/packages/api/src/base/index.ts index 35ea5be140..f6ac2f8eea 100644 --- a/packages/api/src/base/index.ts +++ b/packages/api/src/base/index.ts @@ -6,7 +6,7 @@ import { Constants } from '@polkadot/metadata/Decorated/types'; import { RpcInterface } from '@polkadot/rpc-core/jsonrpc.types'; import { Hash, RuntimeVersion } from '@polkadot/types/interfaces'; import { InterfaceRegistry } from '@polkadot/types/interfaceRegistry'; -import { CallFunction, InterfaceTypes, RegistryTypes, SignerPayloadRawBase } from '@polkadot/types/types'; +import { CallFunction, InterfaceTypes, RegistryError, RegistryTypes, SignerPayloadRawBase } from '@polkadot/types/types'; import { ApiInterfaceRx, ApiOptions, ApiTypes, DecoratedRpc, DecorateMethod, QueryableStorage, QueryableStorageMulti, SubmittableExtrinsics, Signer } from '../types'; import { Metadata, createType } from '@polkadot/types'; @@ -243,12 +243,19 @@ export default abstract class ApiBase extends Init': Option; 'Vec': Vec; + Account: Account; + 'Option': Option; + 'Vec': Vec; + Log: Log; + 'Option': Option; + 'Vec': Vec; AssetOptions: AssetOptions; 'Option': Option; 'Vec': Vec; diff --git a/packages/types/src/interfaces/definitions.ts b/packages/types/src/interfaces/definitions.ts index 37d0ce8e5f..05314fbd19 100644 --- a/packages/types/src/interfaces/definitions.ts +++ b/packages/types/src/interfaces/definitions.ts @@ -16,6 +16,7 @@ export { default as contracts } from './contracts/definitions'; export { default as democracy } from './democracy/definitions'; export { default as deprecated } from './deprecated/definitions'; export { default as elections } from './elections/definitions'; +export { default as evm } from './evm/definitions'; export { default as genericAsset } from './genericAsset/definitions'; export { default as grandpa } from './grandpa/definitions'; export { default as identity } from './identity/definitions'; diff --git a/packages/types/src/interfaces/evm/definitions.ts b/packages/types/src/interfaces/evm/definitions.ts new file mode 100644 index 0000000000..7bc8a72d9c --- /dev/null +++ b/packages/types/src/interfaces/evm/definitions.ts @@ -0,0 +1,17 @@ +// Copyright 2017-2020 @polkadot/types authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +export default { + types: { + Account: { + nonce: 'U256', + balance: 'U256' + }, + Log: { + address: 'H160', + topics: 'Vec', + data: 'Bytes' + } + } +}; diff --git a/packages/types/src/interfaces/evm/index.ts b/packages/types/src/interfaces/evm/index.ts new file mode 100644 index 0000000000..25784af928 --- /dev/null +++ b/packages/types/src/interfaces/evm/index.ts @@ -0,0 +1,4 @@ +// Auto-generated via `yarn polkadot-types-from-defs`, do not edit +/* eslint-disable @typescript-eslint/no-empty-interface */ + +export * from './types'; diff --git a/packages/types/src/interfaces/evm/types.ts b/packages/types/src/interfaces/evm/types.ts new file mode 100644 index 0000000000..ea6dbf6afd --- /dev/null +++ b/packages/types/src/interfaces/evm/types.ts @@ -0,0 +1,23 @@ +// Auto-generated via `yarn polkadot-types-from-defs`, do not edit +/* eslint-disable @typescript-eslint/no-empty-interface */ + +import { Struct, Vec } from '@polkadot/types/codec'; +import { Bytes, H160, H256, U256 } from '@polkadot/types/primitive'; + +/** Struct */ +export interface Account extends Struct { + /** U256 */ + readonly nonce: U256; + /** U256 */ + readonly balance: U256; +} + +/** Struct */ +export interface Log extends Struct { + /** H160 */ + readonly address: H160; + /** Vec */ + readonly topics: Vec; + /** Bytes */ + readonly data: Bytes; +} diff --git a/packages/types/src/interfaces/types.ts b/packages/types/src/interfaces/types.ts index e31e343078..88ba55ce2b 100644 --- a/packages/types/src/interfaces/types.ts +++ b/packages/types/src/interfaces/types.ts @@ -12,6 +12,7 @@ export * from './contracts/types'; export * from './democracy/types'; export * from './deprecated/types'; export * from './elections/types'; +export * from './evm/types'; export * from './genericAsset/types'; export * from './grandpa/types'; export * from './identity/types';