diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-05-31 05:41:36 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-06-01 02:04:05 +0800 |
commit | a7fc9caacb7b98c7d79333e60ee9862945a67ecc (patch) | |
tree | d26d61dd0b2f19d68f34b4de460fa0cb225622d6 /packages/ethereum-types | |
parent | c284f6dcd4e10388e0dd474be08788ddef6b4f30 (diff) | |
download | dexon-sol-tools-a7fc9caacb7b98c7d79333e60ee9862945a67ecc.tar dexon-sol-tools-a7fc9caacb7b98c7d79333e60ee9862945a67ecc.tar.gz dexon-sol-tools-a7fc9caacb7b98c7d79333e60ee9862945a67ecc.tar.bz2 dexon-sol-tools-a7fc9caacb7b98c7d79333e60ee9862945a67ecc.tar.lz dexon-sol-tools-a7fc9caacb7b98c7d79333e60ee9862945a67ecc.tar.xz dexon-sol-tools-a7fc9caacb7b98c7d79333e60ee9862945a67ecc.tar.zst dexon-sol-tools-a7fc9caacb7b98c7d79333e60ee9862945a67ecc.zip |
Introduce ethereum-types package
Diffstat (limited to 'packages/ethereum-types')
-rw-r--r-- | packages/ethereum-types/.npmignore | 6 | ||||
-rw-r--r-- | packages/ethereum-types/CHANGELOG.json | 10 | ||||
-rw-r--r-- | packages/ethereum-types/README.md | 61 | ||||
-rw-r--r-- | packages/ethereum-types/package.json | 42 | ||||
-rw-r--r-- | packages/ethereum-types/src/globals.d.ts | 6 | ||||
-rw-r--r-- | packages/ethereum-types/src/index.ts | 281 | ||||
-rw-r--r-- | packages/ethereum-types/src/monorepo_scripts/postpublish.ts | 8 | ||||
-rw-r--r-- | packages/ethereum-types/tsconfig.json | 8 | ||||
-rw-r--r-- | packages/ethereum-types/tslint.json | 3 |
9 files changed, 425 insertions, 0 deletions
diff --git a/packages/ethereum-types/.npmignore b/packages/ethereum-types/.npmignore new file mode 100644 index 000000000..24e65ad5b --- /dev/null +++ b/packages/ethereum-types/.npmignore @@ -0,0 +1,6 @@ +.* +yarn-error.log +/scripts/ +/src/ +tsconfig.json +/lib/monorepo_scripts/ diff --git a/packages/ethereum-types/CHANGELOG.json b/packages/ethereum-types/CHANGELOG.json new file mode 100644 index 000000000..67eac5111 --- /dev/null +++ b/packages/ethereum-types/CHANGELOG.json @@ -0,0 +1,10 @@ +[ + { + "version": "0.0.1", + "changes": [ + { + "note": "Initial publish" + } + ] + } +] diff --git a/packages/ethereum-types/README.md b/packages/ethereum-types/README.md new file mode 100644 index 000000000..817e22d15 --- /dev/null +++ b/packages/ethereum-types/README.md @@ -0,0 +1,61 @@ +## ethereum-types + +Typescript types shared across Ethereum-related packages/libraries/tools. + +## Installation + +```bash +yarn add -D ethereum-types +``` + +## Usage + +```javascript +import { TransactionReceipt, TxData, TxDataPayable } from 'ethereum-types'; +``` + +## Contributing + +We welcome improvements and fixes from the wider community! To report bugs within this package, please create an issue in this repository. + +Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started. + +### Install dependencies + +If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them: + +```bash +yarn config set workspaces-experimental true +``` + +Then install dependencies + +```bash +yarn install +``` + +### Build + +To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory: + +```bash +PKG=ethereum-types yarn build +``` + +Or continuously rebuild on change: + +```bash +PKG=ethereum-types yarn watch +``` + +### Clean + +```bash +yarn clean +``` + +### Lint + +```bash +yarn lint +``` diff --git a/packages/ethereum-types/package.json b/packages/ethereum-types/package.json new file mode 100644 index 000000000..c7a748f70 --- /dev/null +++ b/packages/ethereum-types/package.json @@ -0,0 +1,42 @@ +{ + "name": "ethereum-types", + "version": "0.0.1", + "engines": { + "node": ">=6.12" + }, + "description": "Ethereum types", + "main": "lib/index.js", + "types": "lib/index.d.ts", + "scripts": { + "watch": "tsc -w", + "build": "tsc && copyfiles -u 2 './lib/monorepo_scripts/**/*' ./scripts", + "clean": "shx rm -rf lib scripts", + "lint": "tslint --project .", + "manual:postpublish": "yarn build; node ./scripts/postpublish.js" + }, + "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/0xProject/0x-monorepo.git" + }, + "bugs": { + "url": "https://github.com/0xProject/0x-monorepo/issues" + }, + "homepage": "https://github.com/0xProject/0x-monorepo/packages/types/README.md", + "devDependencies": { + "@0xproject/monorepo-scripts": "^0.1.20", + "@0xproject/tslint-config": "^0.4.18", + "copyfiles": "^1.2.0", + "make-promises-safe": "^1.1.0", + "shx": "^0.2.2", + "tslint": "5.8.0", + "typescript": "2.7.1" + }, + "dependencies": { + "@types/node": "^8.0.53", + "bignumber.js": "~4.1.0" + }, + "publishConfig": { + "access": "public" + } +} diff --git a/packages/ethereum-types/src/globals.d.ts b/packages/ethereum-types/src/globals.d.ts new file mode 100644 index 000000000..94e63a32d --- /dev/null +++ b/packages/ethereum-types/src/globals.d.ts @@ -0,0 +1,6 @@ +declare module '*.json' { + const json: any; + /* tslint:disable */ + export default json; + /* tslint:enable */ +} diff --git a/packages/ethereum-types/src/index.ts b/packages/ethereum-types/src/index.ts new file mode 100644 index 000000000..f00ae963a --- /dev/null +++ b/packages/ethereum-types/src/index.ts @@ -0,0 +1,281 @@ +import { BigNumber } from 'bignumber.js'; + +export type JSONRPCErrorCallback = (err: Error | null, result?: JSONRPCResponsePayload) => void; + +/** + * Do not create your own provider. Use an existing provider from a Web3 or ProviderEngine library + * Read more about Providers in the 0x wiki. + */ +export interface Provider { + sendAsync(payload: JSONRPCRequestPayload, callback: JSONRPCErrorCallback): void; +} + +export type ContractAbi = AbiDefinition[]; + +export type AbiDefinition = FunctionAbi | EventAbi; + +export type FunctionAbi = MethodAbi | ConstructorAbi | FallbackAbi; + +export type ConstructorStateMutability = 'nonpayable' | 'payable'; +export type StateMutability = 'pure' | 'view' | ConstructorStateMutability; + +export interface MethodAbi { + type: AbiType.Function; + name: string; + inputs: DataItem[]; + outputs: DataItem[]; + constant: boolean; + stateMutability: StateMutability; + payable: boolean; +} + +export interface ConstructorAbi { + type: AbiType.Constructor; + inputs: DataItem[]; + payable: boolean; + stateMutability: ConstructorStateMutability; +} + +export interface FallbackAbi { + type: AbiType.Fallback; + payable: boolean; +} + +export interface EventParameter extends DataItem { + indexed: boolean; +} + +export interface EventAbi { + type: AbiType.Event; + name: string; + inputs: EventParameter[]; + anonymous: boolean; +} + +export interface DataItem { + name: string; + type: string; + components?: DataItem[]; +} + +export enum OpCode { + DelegateCall = 'DELEGATECALL', + Revert = 'REVERT', + Create = 'CREATE', + Stop = 'STOP', + Invalid = 'INVALID', + CallCode = 'CALLCODE', + StaticCall = 'STATICCALL', + Return = 'RETURN', + Call = 'CALL', + SelfDestruct = 'SELFDESTRUCT', +} + +export interface StructLog { + depth: number; + error: string; + gas: number; + gasCost: number; + memory: string[]; + op: OpCode; + pc: number; + stack: string[]; + storage: { [location: string]: string }; +} + +export interface TransactionTrace { + gas: number; + returnValue: any; + structLogs: StructLog[]; +} + +export type Unit = + | 'kwei' + | 'ada' + | 'mwei' + | 'babbage' + | 'gwei' + | 'shannon' + | 'szabo' + | 'finney' + | 'ether' + | 'kether' + | 'grand' + | 'einstein' + | 'mether' + | 'gether' + | 'tether'; + +export interface JSONRPCRequestPayload { + params: any[]; + method: string; + id: number; + jsonrpc: string; +} + +export interface JSONRPCResponsePayload { + result: any; + id: number; + jsonrpc: string; +} + +export interface AbstractBlock { + number: number | null; + hash: string | null; + parentHash: string; + nonce: string | null; + sha3Uncles: string; + logsBloom: string | null; + transactionsRoot: string; + stateRoot: string; + miner: string; + difficulty: BigNumber; + totalDifficulty: BigNumber; + extraData: string; + size: number; + gasLimit: number; + gasUsed: number; + timestamp: number; + uncles: string[]; +} + +export interface BlockWithoutTransactionData extends AbstractBlock { + transactions: string[]; +} + +export interface BlockWithTransactionData extends AbstractBlock { + transactions: Transaction[]; +} + +export interface Transaction { + hash: string; + nonce: number; + blockHash: string | null; + blockNumber: number | null; + transactionIndex: number | null; + from: string; + to: string | null; + value: BigNumber; + gasPrice: BigNumber; + gas: number; + input: string; +} + +export interface CallTxDataBase { + to?: string; + value?: number | string | BigNumber; + gas?: number | string | BigNumber; + gasPrice?: number | string | BigNumber; + data?: string; + nonce?: number; +} + +export interface TxData extends CallTxDataBase { + from: string; +} + +export interface CallData extends CallTxDataBase { + from?: string; +} + +export interface FilterObject { + fromBlock?: number | string; + toBlock?: number | string; + address?: string; + topics?: LogTopic[]; +} + +export type LogTopic = null | string | string[]; + +export interface DecodedLogEntry<A> extends LogEntry { + event: string; + args: A; +} + +export interface DecodedLogEntryEvent<A> extends DecodedLogEntry<A> { + removed: boolean; +} + +export interface LogEntryEvent extends LogEntry { + removed: boolean; +} + +export interface LogEntry { + logIndex: number | null; + transactionIndex: number | null; + transactionHash: string; + blockHash: string | null; + blockNumber: number | null; + address: string; + data: string; + topics: string[]; +} + +export interface TxDataPayable extends TxData { + value?: BigNumber; +} + +export interface TransactionReceipt { + blockHash: string; + blockNumber: number; + transactionHash: string; + transactionIndex: number; + from: string; + to: string; + status: null | string | 0 | 1; + cumulativeGasUsed: number; + gasUsed: number; + contractAddress: string | null; + logs: LogEntry[]; +} + +export enum AbiType { + Function = 'function', + Constructor = 'constructor', + Event = 'event', + Fallback = 'fallback', +} + +export type ContractEventArg = string | BigNumber | number | boolean; + +export interface DecodedLogArgs { + [argName: string]: ContractEventArg; +} + +export interface LogWithDecodedArgs<ArgsType extends DecodedLogArgs> extends DecodedLogEntry<ArgsType> {} +export type RawLog = LogEntry; + +export enum BlockParamLiteral { + Earliest = 'earliest', + Latest = 'latest', + Pending = 'pending', +} + +export type BlockParam = BlockParamLiteral | number; + +export interface RawLogEntry { + logIndex: string | null; + transactionIndex: string | null; + transactionHash: string; + blockHash: string | null; + blockNumber: string | null; + address: string; + data: string; + topics: string[]; +} + +export enum SolidityTypes { + Address = 'address', + Uint256 = 'uint256', + Uint8 = 'uint8', + Uint = 'uint', +} + +/** + * Contains the logs returned by a TransactionReceipt. We attempt to decode the + * logs using AbiDecoder. If we have the logs corresponding ABI, we decode it, + * otherwise we don't. + */ +export interface TransactionReceiptWithDecodedLogs extends TransactionReceipt { + logs: Array<LogWithDecodedArgs<DecodedLogArgs> | LogEntry>; +} diff --git a/packages/ethereum-types/src/monorepo_scripts/postpublish.ts b/packages/ethereum-types/src/monorepo_scripts/postpublish.ts new file mode 100644 index 000000000..dcb99d0f7 --- /dev/null +++ b/packages/ethereum-types/src/monorepo_scripts/postpublish.ts @@ -0,0 +1,8 @@ +import { postpublishUtils } from '@0xproject/monorepo-scripts'; + +import * as packageJSON from '../package.json'; +import * as tsConfigJSON from '../tsconfig.json'; + +const cwd = `${__dirname}/..`; +// tslint:disable-next-line:no-floating-promises +postpublishUtils.runAsync(packageJSON, tsConfigJSON, cwd); diff --git a/packages/ethereum-types/tsconfig.json b/packages/ethereum-types/tsconfig.json new file mode 100644 index 000000000..82a45ea94 --- /dev/null +++ b/packages/ethereum-types/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig", + "compilerOptions": { + "typeRoots": ["../../node_modules/@types"], + "outDir": "lib" + }, + "include": ["src/**/*"] +} diff --git a/packages/ethereum-types/tslint.json b/packages/ethereum-types/tslint.json new file mode 100644 index 000000000..ffaefe83a --- /dev/null +++ b/packages/ethereum-types/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": ["@0xproject/tslint-config"] +} |