diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-01-23 04:53:32 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-01-30 23:01:36 +0800 |
commit | 387363283ca03ac1d6c9be5b7be2107790bbf79d (patch) | |
tree | 7f9ce518e2f4931321901dfeb2675d70854e996d /packages/0x.js/src | |
parent | 709026bf1a49d468850b4ebed845c8598fa4fd75 (diff) | |
download | dexon-sol-tools-387363283ca03ac1d6c9be5b7be2107790bbf79d.tar dexon-sol-tools-387363283ca03ac1d6c9be5b7be2107790bbf79d.tar.gz dexon-sol-tools-387363283ca03ac1d6c9be5b7be2107790bbf79d.tar.bz2 dexon-sol-tools-387363283ca03ac1d6c9be5b7be2107790bbf79d.tar.lz dexon-sol-tools-387363283ca03ac1d6c9be5b7be2107790bbf79d.tar.xz dexon-sol-tools-387363283ca03ac1d6c9be5b7be2107790bbf79d.tar.zst dexon-sol-tools-387363283ca03ac1d6c9be5b7be2107790bbf79d.zip |
Remove truffle from tests
Diffstat (limited to 'packages/0x.js/src')
-rw-r--r-- | packages/0x.js/src/0x.ts | 26 | ||||
-rw-r--r-- | packages/0x.js/src/contract_wrappers/contract_wrapper.ts | 6 | ||||
-rw-r--r-- | packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts | 5 | ||||
-rw-r--r-- | packages/0x.js/src/contract_wrappers/exchange_wrapper.ts | 6 | ||||
-rw-r--r-- | packages/0x.js/src/contract_wrappers/token_wrapper.ts | 5 | ||||
-rw-r--r-- | packages/0x.js/src/globals.d.ts | 16 | ||||
-rw-r--r-- | packages/0x.js/src/index.ts | 5 | ||||
-rw-r--r-- | packages/0x.js/src/order_watcher/order_state_watcher.ts | 5 | ||||
-rw-r--r-- | packages/0x.js/src/types.ts | 29 | ||||
-rw-r--r-- | packages/0x.js/src/utils/abi_decoder.ts | 72 | ||||
-rw-r--r-- | packages/0x.js/src/utils/utils.ts | 3 |
11 files changed, 24 insertions, 154 deletions
diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts index f8a484c5d..8eb8cdd9a 100644 --- a/packages/0x.js/src/0x.ts +++ b/packages/0x.js/src/0x.ts @@ -1,5 +1,6 @@ import { schemas, SchemaValidator } from '@0xproject/json-schemas'; -import { BigNumber, intervalUtils } from '@0xproject/utils'; +import { TransactionReceiptWithDecodedLogs } from '@0xproject/types'; +import { AbiDecoder, BigNumber, intervalUtils } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as ethUtil from 'ethereumjs-util'; import * as _ from 'lodash'; @@ -12,16 +13,7 @@ import { TokenTransferProxyWrapper } from './contract_wrappers/token_transfer_pr import { TokenWrapper } from './contract_wrappers/token_wrapper'; import { OrderStateWatcher } from './order_watcher/order_state_watcher'; import { zeroExConfigSchema } from './schemas/zero_ex_config_schema'; -import { - ECSignature, - Order, - SignedOrder, - TransactionReceiptWithDecodedLogs, - Web3Provider, - ZeroExConfig, - ZeroExError, -} from './types'; -import { AbiDecoder } from './utils/abi_decoder'; +import { ECSignature, Order, SignedOrder, Web3Provider, ZeroExConfig, ZeroExError } from './types'; import { assert } from './utils/assert'; import { constants } from './utils/constants'; import { decorators } from './utils/decorators'; @@ -293,18 +285,18 @@ export class ZeroEx { * @param timeoutMs How long (in ms) to poll for transaction mined until aborting. * @return Transaction receipt with decoded log args. */ - public async awaitTransactionMinedAsync( + public async awaitTransactionMinedAsync<ArgsType>( txHash: string, pollingIntervalMs = 1000, timeoutMs?: number, - ): Promise<TransactionReceiptWithDecodedLogs> { + ): Promise<TransactionReceiptWithDecodedLogs<ArgsType>> { let timeoutExceeded = false; if (timeoutMs) { setTimeout(() => (timeoutExceeded = true), timeoutMs); } const txReceiptPromise = new Promise( - (resolve: (receipt: TransactionReceiptWithDecodedLogs) => void, reject) => { + (resolve: (receipt: TransactionReceiptWithDecodedLogs<ArgsType>) => void, reject) => { const intervalId = intervalUtils.setAsyncExcludingInterval( async () => { if (timeoutExceeded) { @@ -319,7 +311,7 @@ export class ZeroEx { transactionReceipt.logs, this._abiDecoder.tryToDecodeLogOrNoop.bind(this._abiDecoder), ); - const transactionReceiptWithDecodedLogArgs: TransactionReceiptWithDecodedLogs = { + const transactionReceiptWithDecodedLogArgs: TransactionReceiptWithDecodedLogs<ArgsType> = { ...transactionReceipt, logs: logsWithDecodedArgs, }; @@ -334,8 +326,8 @@ export class ZeroEx { ); }, ); - - return txReceiptPromise; + const txReceipt = await txReceiptPromise; + return txReceipt; } /* * HACK: `TokenWrapper` needs a token transfer proxy address. `TokenTransferProxy` address is fetched from diff --git a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts index 27551c01d..5f11d810a 100644 --- a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts @@ -1,4 +1,5 @@ -import { intervalUtils } from '@0xproject/utils'; +import { LogWithDecodedArgs, RawLog } from '@0xproject/types'; +import { AbiDecoder, intervalUtils } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { Block, BlockAndLogStreamer } from 'ethereumjs-blockstream'; import * as _ from 'lodash'; @@ -13,11 +14,8 @@ import { EventCallback, IndexedFilterValues, InternalZeroExError, - LogWithDecodedArgs, - RawLog, ZeroExError, } from '../types'; -import { AbiDecoder } from '../utils/abi_decoder'; import { constants } from '../utils/constants'; import { filterUtils } from '../utils/filter_utils'; diff --git a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts index b03571636..8fa7aa78b 100644 --- a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts @@ -1,5 +1,6 @@ import { schemas } from '@0xproject/json-schemas'; -import { BigNumber } from '@0xproject/utils'; +import { LogWithDecodedArgs } from '@0xproject/types'; +import { AbiDecoder, BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as _ from 'lodash'; @@ -10,11 +11,9 @@ import { EtherTokenEvents, EventCallback, IndexedFilterValues, - LogWithDecodedArgs, TransactionOpts, ZeroExError, } from '../types'; -import { AbiDecoder } from '../utils/abi_decoder'; import { assert } from '../utils/assert'; import { ContractWrapper } from './contract_wrapper'; diff --git a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts index 2b6117729..5672f0360 100644 --- a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts @@ -1,5 +1,6 @@ import { schemas } from '@0xproject/json-schemas'; -import { BigNumber } from '@0xproject/utils'; +import { DecodedLogArgs, LogWithDecodedArgs } from '@0xproject/types'; +import { AbiDecoder, BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as _ from 'lodash'; import * as Web3 from 'web3'; @@ -8,7 +9,6 @@ import { artifacts } from '../artifacts'; import { BlockParamLiteral, BlockRange, - DecodedLogArgs, ECSignature, EventCallback, ExchangeContractErrCodes, @@ -17,7 +17,6 @@ import { ExchangeEvents, IndexedFilterValues, LogErrorContractEventArgs, - LogWithDecodedArgs, MethodOpts, Order, OrderAddresses, @@ -28,7 +27,6 @@ import { SignedOrder, ValidateOrderFillableOpts, } from '../types'; -import { AbiDecoder } from '../utils/abi_decoder'; import { assert } from '../utils/assert'; import { decorators } from '../utils/decorators'; import { ExchangeTransferSimulator } from '../utils/exchange_transfer_simulator'; diff --git a/packages/0x.js/src/contract_wrappers/token_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_wrapper.ts index 7943f4a60..a3a8074a8 100644 --- a/packages/0x.js/src/contract_wrappers/token_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/token_wrapper.ts @@ -1,5 +1,6 @@ import { schemas } from '@0xproject/json-schemas'; -import { BigNumber } from '@0xproject/utils'; +import { AbiDecoder, BigNumber } from '@0xproject/utils'; +import { LogWithDecodedArgs } from '@0xproject/types'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as _ from 'lodash'; @@ -8,14 +9,12 @@ import { BlockRange, EventCallback, IndexedFilterValues, - LogWithDecodedArgs, MethodOpts, TokenContractEventArgs, TokenEvents, TransactionOpts, ZeroExError, } from '../types'; -import { AbiDecoder } from '../utils/abi_decoder'; import { assert } from '../utils/assert'; import { constants } from '../utils/constants'; diff --git a/packages/0x.js/src/globals.d.ts b/packages/0x.js/src/globals.d.ts index 4f4932b6e..0e103d057 100644 --- a/packages/0x.js/src/globals.d.ts +++ b/packages/0x.js/src/globals.d.ts @@ -41,19 +41,3 @@ declare module 'truffle-hdwallet-provider' { } export = HDWalletProvider; } - -// abi-decoder declarations -interface DecodedLogArg {} -interface DecodedLog { - name: string; - events: DecodedLogArg[]; -} -declare module 'abi-decoder' { - import * as Web3 from 'web3'; - const addABI: (abi: Web3.AbiDefinition) => void; - const decodeLogs: (logs: Web3.LogEntry[]) => DecodedLog[]; -} - -declare module 'web3/lib/solidity/coder' { - const decodeParams: (types: string[], data: string) => any[]; -} diff --git a/packages/0x.js/src/index.ts b/packages/0x.js/src/index.ts index 599c3a2b0..41e67e177 100644 --- a/packages/0x.js/src/index.ts +++ b/packages/0x.js/src/index.ts @@ -28,12 +28,9 @@ export { WithdrawalContractEventArgs, DepositContractEventArgs, ContractEventArgs, - ContractEventArg, Web3Provider, ZeroExConfig, EtherTokenEvents, - TransactionReceiptWithDecodedLogs, - LogWithDecodedArgs, MethodOpts, OrderTransactionOpts, TransactionOpts, @@ -47,4 +44,6 @@ export { OrderState, } from './types'; +export { ContractEventArg, LogWithDecodedArgs, TransactionReceiptWithDecodedLogs } from '@0xproject/types'; + export { TransactionReceipt } from '@0xproject/types'; diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts index 12ac60960..446fab676 100644 --- a/packages/0x.js/src/order_watcher/order_state_watcher.ts +++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts @@ -1,5 +1,6 @@ import { schemas } from '@0xproject/json-schemas'; -import { intervalUtils } from '@0xproject/utils'; +import { LogWithDecodedArgs } from '@0xproject/types'; +import { AbiDecoder, intervalUtils } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as _ from 'lodash'; @@ -19,7 +20,6 @@ import { LogCancelContractEventArgs, LogEvent, LogFillContractEventArgs, - LogWithDecodedArgs, OnOrderStateChangeCallback, OrderState, OrderStateWatcherConfig, @@ -29,7 +29,6 @@ import { WithdrawalContractEventArgs, ZeroExError, } from '../types'; -import { AbiDecoder } from '../utils/abi_decoder'; import { assert } from '../utils/assert'; import { OrderStateUtils } from '../utils/order_state_utils'; import { utils } from '../utils/utils'; diff --git a/packages/0x.js/src/types.ts b/packages/0x.js/src/types.ts index 55f7bb7d3..fcbb9e5f3 100644 --- a/packages/0x.js/src/types.ts +++ b/packages/0x.js/src/types.ts @@ -1,4 +1,4 @@ -import { TransactionReceipt } from '@0xproject/types'; +import { ContractEventArg, DecodedLogArgs, LogWithDecodedArgs, TransactionReceipt } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import * as Web3 from 'web3'; @@ -53,13 +53,6 @@ export interface DecodedLogEvent<ArgsType> { export type EventCallback<ArgsType> = (err: null | Error, log?: DecodedLogEvent<ArgsType>) => void; export type EventWatcherCallback = (err: null | Error, log?: LogEvent) => void; -export enum SolidityTypes { - Address = 'address', - Uint256 = 'uint256', - Uint8 = 'uint8', - Uint = 'uint', -} - export enum ExchangeContractErrCodes { ERROR_FILL_EXPIRED, // Order has already expired ERROR_FILL_NO_VALUE, // Order has already been fully filled or cancelled @@ -94,8 +87,6 @@ export enum ExchangeContractErrs { BatchOrdersMustHaveAtLeastOneItem = 'BATCH_ORDERS_MUST_HAVE_AT_LEAST_ONE_ITEM', } -export type RawLog = Web3.LogEntry; - export interface ContractEvent { logIndex: number; transactionIndex: number; @@ -163,7 +154,6 @@ export type EtherTokenContractEventArgs = | DepositContractEventArgs | WithdrawalContractEventArgs; export type ContractEventArgs = ExchangeContractEventArgs | TokenContractEventArgs | EtherTokenContractEventArgs; -export type ContractEventArg = string | BigNumber; export interface Order { maker: string; @@ -300,23 +290,6 @@ export interface ZeroExConfig { orderWatcherConfig?: OrderStateWatcherConfig; } -export enum AbiType { - Function = 'function', - Constructor = 'constructor', - Event = 'event', - Fallback = 'fallback', -} - -export interface DecodedLogArgs { - [argName: string]: ContractEventArg; -} - -export interface LogWithDecodedArgs<ArgsType> extends Web3.DecodedLogEntry<ArgsType> {} - -export interface TransactionReceiptWithDecodedLogs extends TransactionReceipt { - logs: Array<LogWithDecodedArgs<DecodedLogArgs> | Web3.LogEntry>; -} - export type ArtifactContractName = 'ZRX' | 'TokenTransferProxy' | 'TokenRegistry' | 'Token' | 'Exchange' | 'EtherToken'; export interface Artifact { diff --git a/packages/0x.js/src/utils/abi_decoder.ts b/packages/0x.js/src/utils/abi_decoder.ts deleted file mode 100644 index bbd2a0b1d..000000000 --- a/packages/0x.js/src/utils/abi_decoder.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { BigNumber } from '@0xproject/utils'; -import * as _ from 'lodash'; -import * as Web3 from 'web3'; -import * as SolidityCoder from 'web3/lib/solidity/coder'; - -import { AbiType, ContractEventArgs, DecodedLogArgs, LogWithDecodedArgs, RawLog, SolidityTypes } from '../types'; - -export class AbiDecoder { - private _savedABIs: Web3.AbiDefinition[] = []; - private _methodIds: { [signatureHash: string]: Web3.EventAbi } = {}; - private static _padZeros(address: string) { - let formatted = address; - if (_.startsWith(formatted, '0x')) { - formatted = formatted.slice(2); - } - - formatted = _.padStart(formatted, 40, '0'); - return `0x${formatted}`; - } - constructor(abiArrays: Web3.AbiDefinition[][]) { - _.map(abiArrays, this._addABI.bind(this)); - } - // This method can only decode logs from the 0x & ERC20 smart contracts - public tryToDecodeLogOrNoop<ArgsType extends ContractEventArgs>( - log: Web3.LogEntry, - ): LogWithDecodedArgs<ArgsType> | RawLog { - const methodId = log.topics[0]; - const event = this._methodIds[methodId]; - if (_.isUndefined(event)) { - return log; - } - const logData = log.data; - const decodedParams: DecodedLogArgs = {}; - let dataIndex = 0; - let topicsIndex = 1; - - const nonIndexedInputs = _.filter(event.inputs, input => !input.indexed); - const dataTypes = _.map(nonIndexedInputs, input => input.type); - const decodedData = SolidityCoder.decodeParams(dataTypes, logData.slice('0x'.length)); - - _.map(event.inputs, (param: Web3.EventParameter) => { - // Indexed parameters are stored in topics. Non-indexed ones in decodedData - let value = param.indexed ? log.topics[topicsIndex++] : decodedData[dataIndex++]; - if (param.type === SolidityTypes.Address) { - value = AbiDecoder._padZeros(new BigNumber(value).toString(16)); - } else if ( - param.type === SolidityTypes.Uint256 || - param.type === SolidityTypes.Uint8 || - param.type === SolidityTypes.Uint - ) { - value = new BigNumber(value); - } - decodedParams[param.name] = value; - }); - - return { - ...log, - event: event.name, - args: decodedParams, - }; - } - private _addABI(abiArray: Web3.AbiDefinition[]): void { - _.map(abiArray, (abi: Web3.AbiDefinition) => { - if (abi.type === AbiType.Event) { - const signature = `${abi.name}(${_.map(abi.inputs, input => input.type).join(',')})`; - const signatureHash = new Web3().sha3(signature); - this._methodIds[signatureHash] = abi; - } - }); - this._savedABIs = this._savedABIs.concat(abiArray); - } -} diff --git a/packages/0x.js/src/utils/utils.ts b/packages/0x.js/src/utils/utils.ts index 42cf5d956..74f2c5995 100644 --- a/packages/0x.js/src/utils/utils.ts +++ b/packages/0x.js/src/utils/utils.ts @@ -1,10 +1,11 @@ +import { SolidityTypes } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import BN = require('bn.js'); import * as ethABI from 'ethereumjs-abi'; import * as ethUtil from 'ethereumjs-util'; import * as _ from 'lodash'; -import { Order, SignedOrder, SolidityTypes } from '../types'; +import { Order, SignedOrder } from '../types'; export const utils = { /** |