From d72b7299c66ea6d63eb14595b06456c02b2ad99b Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 27 Mar 2018 15:19:23 +0200 Subject: Move common types out of web3 types --- packages/abi-gen/package.json | 2 +- packages/abi-gen/src/index.ts | 8 ++++---- packages/abi-gen/src/types.ts | 6 +++--- packages/abi-gen/src/utils.ts | 11 +++-------- 4 files changed, 11 insertions(+), 16 deletions(-) (limited to 'packages/abi-gen') diff --git a/packages/abi-gen/package.json b/packages/abi-gen/package.json index 2fdf19320..3c20249dd 100644 --- a/packages/abi-gen/package.json +++ b/packages/abi-gen/package.json @@ -24,6 +24,7 @@ "homepage": "https://github.com/0xProject/0x-monorepo/packages/abi-gen/README.md", "dependencies": { "@0xproject/utils": "^0.4.3", + "@0xproject/types": "^0.4.1", "@0xproject/typescript-typings": "^0.0.1", "chalk": "^2.3.0", "glob": "^7.1.2", @@ -31,7 +32,6 @@ "lodash": "^4.17.4", "mkdirp": "^0.5.1", "to-snake-case": "^1.0.0", - "web3": "^0.20.0", "yargs": "^10.0.3" }, "devDependencies": { diff --git a/packages/abi-gen/src/index.ts b/packages/abi-gen/src/index.ts index 8932e4045..942bb12db 100644 --- a/packages/abi-gen/src/index.ts +++ b/packages/abi-gen/src/index.ts @@ -1,5 +1,6 @@ #!/usr/bin/env node +import { AbiDefinition, ConstructorAbi, EventAbi, MethodAbi } from '@0xproject/types'; import { logUtils } from '@0xproject/utils'; import chalk from 'chalk'; import * as fs from 'fs'; @@ -10,7 +11,6 @@ import * as mkdirp from 'mkdirp'; import * as yargs from 'yargs'; import toSnakeCase = require('to-snake-case'); -import * as Web3 from 'web3'; import { ContextData, ContractsBackend, ParamKind } from './types'; import { utils } from './utils'; @@ -120,12 +120,12 @@ for (const abiFileName of abiFileNames) { process.exit(1); } - let ctor = ABI.find((abi: Web3.AbiDefinition) => abi.type === ABI_TYPE_CONSTRUCTOR) as Web3.ConstructorAbi; + let ctor = ABI.find((abi: AbiDefinition) => abi.type === ABI_TYPE_CONSTRUCTOR) as ConstructorAbi; if (_.isUndefined(ctor)) { ctor = utils.getEmptyConstructor(); // The constructor exists, but it's implicit in JSON's ABI definition } - const methodAbis = ABI.filter((abi: Web3.AbiDefinition) => abi.type === ABI_TYPE_METHOD) as Web3.MethodAbi[]; + const methodAbis = ABI.filter((abi: AbiDefinition) => abi.type === ABI_TYPE_METHOD) as MethodAbi[]; const methodsData = _.map(methodAbis, methodAbi => { _.map(methodAbi.inputs, (input, i: number) => { if (_.isEmpty(input.name)) { @@ -142,7 +142,7 @@ for (const abiFileName of abiFileNames) { return methodData; }); - const eventAbis = ABI.filter((abi: Web3.AbiDefinition) => abi.type === ABI_TYPE_EVENT) as Web3.EventAbi[]; + const eventAbis = ABI.filter((abi: AbiDefinition) => abi.type === ABI_TYPE_EVENT) as EventAbi[]; const contextData = { contractName: namedContent.name, diff --git a/packages/abi-gen/src/types.ts b/packages/abi-gen/src/types.ts index deddb1857..df5b1feaf 100644 --- a/packages/abi-gen/src/types.ts +++ b/packages/abi-gen/src/types.ts @@ -1,4 +1,4 @@ -import * as Web3 from 'web3'; +import { EventAbi, MethodAbi } from '@0xproject/types'; export enum ParamKind { Input = 'input', @@ -17,7 +17,7 @@ export enum ContractsBackend { Ethers = 'ethers', } -export interface Method extends Web3.MethodAbi { +export interface Method extends MethodAbi { singleReturnValue: boolean; hasReturnValue: boolean; } @@ -25,5 +25,5 @@ export interface Method extends Web3.MethodAbi { export interface ContextData { contractName: string; methods: Method[]; - events: Web3.EventAbi[]; + events: EventAbi[]; } diff --git a/packages/abi-gen/src/utils.ts b/packages/abi-gen/src/utils.ts index c4520ade0..755fbc71a 100644 --- a/packages/abi-gen/src/utils.ts +++ b/packages/abi-gen/src/utils.ts @@ -1,17 +1,12 @@ +import { ConstructorAbi, DataItem } from '@0xproject/types'; import * as fs from 'fs'; import * as _ from 'lodash'; import * as path from 'path'; -import * as Web3 from 'web3'; import { AbiType, ContractsBackend, ParamKind } from './types'; export const utils = { - solTypeToTsType( - paramKind: ParamKind, - backend: ContractsBackend, - solType: string, - components?: Web3.DataItem[], - ): string { + solTypeToTsType(paramKind: ParamKind, backend: ContractsBackend, solType: string, components?: DataItem[]): string { const trailingArrayRegex = /\[\d*\]$/; if (solType.match(trailingArrayRegex)) { const arrayItemSolType = solType.replace(trailingArrayRegex, ''); @@ -89,7 +84,7 @@ export const utils = { throw new Error(`Failed to read ${filename}: ${err}`); } }, - getEmptyConstructor(): Web3.ConstructorAbi { + getEmptyConstructor(): ConstructorAbi { return { type: AbiType.Constructor, stateMutability: 'nonpayable', -- cgit v1.2.3