aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/src
diff options
context:
space:
mode:
authorLeonid <logvinov.leon@gmail.com>2018-02-05 19:33:40 +0800
committerGitHub <noreply@github.com>2018-02-05 19:33:40 +0800
commit7b4f2b47de393b7ed6d5c264c8e80864d196180c (patch)
tree8e86af8000e0aedd7241a00c2189d8f7ca0fc2ad /packages/0x.js/src
parent400a97e7a8f76d894d47368425bbe1e33fa5b255 (diff)
parentc7ad6ebad6ab65a4b1e4a2084e744c6ca2bc09b8 (diff)
downloaddexon-sol-tools-7b4f2b47de393b7ed6d5c264c8e80864d196180c.tar.gz
dexon-sol-tools-7b4f2b47de393b7ed6d5c264c8e80864d196180c.tar.zst
dexon-sol-tools-7b4f2b47de393b7ed6d5c264c8e80864d196180c.zip
Merge branch 'development' into fix/ether_token_address
Diffstat (limited to 'packages/0x.js/src')
-rw-r--r--packages/0x.js/src/0x.ts18
-rw-r--r--packages/0x.js/src/contract_wrappers/contract_wrapper.ts16
-rw-r--r--packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts11
-rw-r--r--packages/0x.js/src/contract_wrappers/exchange_wrapper.ts16
-rw-r--r--packages/0x.js/src/contract_wrappers/generated/base_contract.ts12
-rw-r--r--packages/0x.js/src/contract_wrappers/token_wrapper.ts11
-rw-r--r--packages/0x.js/src/globals.d.ts16
-rw-r--r--packages/0x.js/src/index.ts5
-rw-r--r--packages/0x.js/src/order_watcher/order_state_watcher.ts17
-rw-r--r--packages/0x.js/src/types.ts34
-rw-r--r--packages/0x.js/src/utils/abi_decoder.ts72
-rw-r--r--packages/0x.js/src/utils/utils.ts3
12 files changed, 50 insertions, 181 deletions
diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts
index f8a484c5d..6cfa65cc2 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';
@@ -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 09de77452..d913e8d9b 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';
@@ -36,8 +34,8 @@ export class ContractWrapper {
protected _web3Wrapper: Web3Wrapper;
protected _networkId: number;
private _abiDecoder?: AbiDecoder;
- private _blockAndLogStreamerIfExists: BlockAndLogStreamer | undefined;
- private _blockAndLogStreamInterval: NodeJS.Timer;
+ private _blockAndLogStreamerIfExists?: BlockAndLogStreamer;
+ private _blockAndLogStreamIntervalIfExists?: NodeJS.Timer;
private _filters: { [filterToken: string]: Web3.FilterObject };
private _filterCallbacks: {
[filterToken: string]: EventCallback<ContractEventArgs>;
@@ -54,7 +52,7 @@ export class ContractWrapper {
this._onLogAddedSubscriptionToken = undefined;
this._onLogRemovedSubscriptionToken = undefined;
}
- protected unsubscribeAll(): void {
+ protected _unsubscribeAll(): void {
const filterTokens = _.keys(this._filterCallbacks);
_.each(filterTokens, filterToken => {
this._unsubscribe(filterToken);
@@ -164,7 +162,7 @@ export class ContractWrapper {
);
const catchAllLogFilter = {};
this._blockAndLogStreamerIfExists.addLogFilter(catchAllLogFilter);
- this._blockAndLogStreamInterval = intervalUtils.setAsyncExcludingInterval(
+ this._blockAndLogStreamIntervalIfExists = intervalUtils.setAsyncExcludingInterval(
this._reconcileBlockAsync.bind(this),
constants.DEFAULT_BLOCK_POLLING_INTERVAL,
this._onReconcileBlockError.bind(this),
@@ -193,7 +191,7 @@ export class ContractWrapper {
}
this._blockAndLogStreamerIfExists.unsubscribeFromOnLogAdded(this._onLogAddedSubscriptionToken as string);
this._blockAndLogStreamerIfExists.unsubscribeFromOnLogRemoved(this._onLogRemovedSubscriptionToken as string);
- intervalUtils.clearAsyncExcludingInterval(this._blockAndLogStreamInterval);
+ intervalUtils.clearAsyncExcludingInterval(this._blockAndLogStreamIntervalIfExists as NodeJS.Timer);
delete this._blockAndLogStreamerIfExists;
}
private async _reconcileBlockAsync(): Promise<void> {
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 ead6fe9d1..32c9ae6a9 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';
@@ -160,8 +159,8 @@ export class EtherTokenWrapper extends ContractWrapper {
/**
* Cancels all existing subscriptions
*/
- public unsubscribeAll(): void {
- super.unsubscribeAll();
+ public _unsubscribeAll(): void {
+ super._unsubscribeAll();
}
/**
* Retrieves the Ethereum address of the EtherToken contract deployed on the network
@@ -177,7 +176,7 @@ export class EtherTokenWrapper extends ContractWrapper {
return contractAddressIfExists;
}
private _invalidateContractInstance(): void {
- this.unsubscribeAll();
+ this._unsubscribeAll();
this._etherTokenContractsByAddress = {};
}
private async _getEtherTokenContractAsync(etherTokenAddress: string): Promise<EtherTokenContract> {
diff --git a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
index 2b6117729..63c0d073a 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';
@@ -680,8 +678,8 @@ export class ExchangeWrapper extends ContractWrapper {
/**
* Cancels all existing subscriptions
*/
- public unsubscribeAll(): void {
- super.unsubscribeAll();
+ public _unsubscribeAll(): void {
+ super._unsubscribeAll();
}
/**
* Gets historical logs without creating a subscription
@@ -846,9 +844,9 @@ export class ExchangeWrapper extends ContractWrapper {
public throwLogErrorsAsErrors(logs: Array<LogWithDecodedArgs<DecodedLogArgs> | Web3.LogEntry>): void {
const errLog = _.find(logs, {
event: ExchangeEvents.LogError,
- }) as LogWithDecodedArgs<LogErrorContractEventArgs> | undefined;
+ });
if (!_.isUndefined(errLog)) {
- const logArgs = errLog.args;
+ const logArgs = (errLog as LogWithDecodedArgs<LogErrorContractEventArgs>).args;
const errCode = logArgs.errorId.toNumber();
const errMessage = this._exchangeContractErrCodesToMsg[errCode];
throw new Error(errMessage);
@@ -863,7 +861,7 @@ export class ExchangeWrapper extends ContractWrapper {
return contractAddress;
}
private _invalidateContractInstances(): void {
- this.unsubscribeAll();
+ this._unsubscribeAll();
delete this._exchangeContractIfExists;
}
private async _isValidSignatureUsingContractCallAsync(
diff --git a/packages/0x.js/src/contract_wrappers/generated/base_contract.ts b/packages/0x.js/src/contract_wrappers/generated/base_contract.ts
index 28a7e2f52..d8fac7eea 100644
--- a/packages/0x.js/src/contract_wrappers/generated/base_contract.ts
+++ b/packages/0x.js/src/contract_wrappers/generated/base_contract.ts
@@ -3,9 +3,9 @@ import * as _ from 'lodash';
import * as Web3 from 'web3';
export class BaseContract {
- protected web3ContractInstance: Web3.ContractInstance;
- protected defaults: Partial<TxData>;
- protected async applyDefaultsToTxDataAsync<T extends TxData|TxDataPayable>(
+ protected _web3ContractInstance: Web3.ContractInstance;
+ protected _defaults: Partial<TxData>;
+ protected async _applyDefaultsToTxDataAsync<T extends TxData|TxDataPayable>(
txData: T,
estimateGasAsync?: (txData: T) => Promise<number>,
): Promise<TxData> {
@@ -15,7 +15,7 @@ export class BaseContract {
// 3. Gas estimate calculation + safety margin
const removeUndefinedProperties = _.pickBy;
const txDataWithDefaults = {
- ...removeUndefinedProperties(this.defaults),
+ ...removeUndefinedProperties(this._defaults),
...removeUndefinedProperties(txData as any),
// HACK: TS can't prove that T is spreadable.
// Awaiting https://github.com/Microsoft/TypeScript/pull/13288 to be merged
@@ -27,7 +27,7 @@ export class BaseContract {
return txDataWithDefaults;
}
constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<TxData>) {
- this.web3ContractInstance = web3ContractInstance;
- this.defaults = defaults;
+ this._web3ContractInstance = web3ContractInstance;
+ this._defaults = defaults;
}
}
diff --git a/packages/0x.js/src/contract_wrappers/token_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_wrapper.ts
index 7943f4a60..98c24d059 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 { LogWithDecodedArgs } from '@0xproject/types';
+import { AbiDecoder, BigNumber } from '@0xproject/utils';
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';
@@ -343,8 +342,8 @@ export class TokenWrapper extends ContractWrapper {
/**
* Cancels all existing subscriptions
*/
- public unsubscribeAll(): void {
- super.unsubscribeAll();
+ public _unsubscribeAll(): void {
+ super._unsubscribeAll();
}
/**
* Gets historical logs without creating a subscription
@@ -375,7 +374,7 @@ export class TokenWrapper extends ContractWrapper {
return logs;
}
private _invalidateContractInstances(): void {
- this.unsubscribeAll();
+ this._unsubscribeAll();
this._tokenContractsByAddress = {};
}
private async _getTokenContractAsync(tokenAddress: string): Promise<TokenContract> {
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..1ad1a90b1 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';
@@ -134,8 +133,12 @@ export class OrderStateWatcher {
delete this._orderStateByOrderHashCache[orderHash];
const exchange = (this._orderFilledCancelledLazyStore as any)._exchange as ExchangeWrapper;
const zrxTokenAddress = exchange.getZRXTokenAddress();
+
this._removeFromDependentOrderHashes(signedOrder.maker, zrxTokenAddress, orderHash);
- this._removeFromDependentOrderHashes(signedOrder.maker, signedOrder.makerTokenAddress, orderHash);
+ if (zrxTokenAddress !== signedOrder.makerTokenAddress) {
+ this._removeFromDependentOrderHashes(signedOrder.maker, signedOrder.makerTokenAddress, orderHash);
+ }
+
this._expirationWatcher.removeOrder(orderHash);
}
/**
@@ -224,12 +227,12 @@ export class OrderStateWatcher {
return;
}
const log = logIfExists as LogEvent; // At this moment we are sure that no error occured and log is defined.
- const maybeDecodedLog = this._abiDecoder.tryToDecodeLogOrNoop(log);
- const isLogDecoded = !_.isUndefined((maybeDecodedLog as LogWithDecodedArgs<any>).event);
+ const maybeDecodedLog = this._abiDecoder.tryToDecodeLogOrNoop<ContractEventArgs>(log);
+ const isLogDecoded = !_.isUndefined(((maybeDecodedLog as any) as LogWithDecodedArgs<ContractEventArgs>).event);
if (!isLogDecoded) {
return; // noop
}
- const decodedLog = maybeDecodedLog as LogWithDecodedArgs<ContractEventArgs>;
+ const decodedLog = (maybeDecodedLog as any) as LogWithDecodedArgs<ContractEventArgs>;
let makerToken: string;
let makerAddress: string;
switch (decodedLog.event) {
diff --git a/packages/0x.js/src/types.ts b/packages/0x.js/src/types.ts
index 3c93910e9..a0deb91c9 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, LogWithDecodedArgs } 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;
@@ -267,11 +257,6 @@ export type SyncMethod = (...args: any[]) => any;
*/
export type Web3Provider = Web3.Provider;
-export interface JSONRPCPayload {
- params: any[];
- method: string;
-}
-
/*
* orderExpirationCheckingIntervalMs: How often to check for expired orders. Default: 50
* eventPollingIntervalMs: How often to poll the Ethereum node for new events. Defaults: 200
@@ -305,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 = {
/**