aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-watcher/src
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-07-18 21:37:34 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-07-18 21:38:10 +0800
commitc71781d9abf7f2654a51dbef95bd18200ea2bde1 (patch)
treebcaf7b858ba1d22d6f8c1afe0ff21aec28467598 /packages/order-watcher/src
parentdad557164ea4ccc012243d43df013078a7c37eb6 (diff)
downloaddexon-0x-contracts-c71781d9abf7f2654a51dbef95bd18200ea2bde1.tar.gz
dexon-0x-contracts-c71781d9abf7f2654a51dbef95bd18200ea2bde1.tar.zst
dexon-0x-contracts-c71781d9abf7f2654a51dbef95bd18200ea2bde1.zip
Merge
Diffstat (limited to 'packages/order-watcher/src')
-rw-r--r--packages/order-watcher/src/fetchers/asset_balance_and_proxy_allowance_fetcher.ts4
-rw-r--r--packages/order-watcher/src/order_watcher/dependent_order_hashes_tracker.ts6
-rw-r--r--packages/order-watcher/src/order_watcher/order_watcher.ts16
3 files changed, 18 insertions, 8 deletions
diff --git a/packages/order-watcher/src/fetchers/asset_balance_and_proxy_allowance_fetcher.ts b/packages/order-watcher/src/fetchers/asset_balance_and_proxy_allowance_fetcher.ts
index b1c013928..bfa33c8b9 100644
--- a/packages/order-watcher/src/fetchers/asset_balance_and_proxy_allowance_fetcher.ts
+++ b/packages/order-watcher/src/fetchers/asset_balance_and_proxy_allowance_fetcher.ts
@@ -14,7 +14,7 @@ export class AssetBalanceAndProxyAllowanceFetcher implements AbstractBalanceAndP
this._stateLayer = stateLayer;
}
public async getBalanceAsync(assetData: string, userAddress: string): Promise<BigNumber> {
- const decodedAssetData = assetProxyUtils.decodeAssetData(assetData);
+ const decodedAssetData = assetProxyUtils.decodeAssetDataOrThrow(assetData);
if (decodedAssetData.assetProxyId === AssetProxyId.ERC20) {
const decodedERC20AssetData = decodedAssetData as ERC20AssetData;
const balance = await this._erc20Token.getBalanceAsync(decodedERC20AssetData.tokenAddress, userAddress, {
@@ -35,7 +35,7 @@ export class AssetBalanceAndProxyAllowanceFetcher implements AbstractBalanceAndP
}
}
public async getProxyAllowanceAsync(assetData: string, userAddress: string): Promise<BigNumber> {
- const decodedAssetData = assetProxyUtils.decodeAssetData(assetData);
+ const decodedAssetData = assetProxyUtils.decodeAssetDataOrThrow(assetData);
if (decodedAssetData.assetProxyId === AssetProxyId.ERC20) {
const decodedERC20AssetData = decodedAssetData as ERC20AssetData;
const proxyAllowance = await this._erc20Token.getProxyAllowanceAsync(
diff --git a/packages/order-watcher/src/order_watcher/dependent_order_hashes_tracker.ts b/packages/order-watcher/src/order_watcher/dependent_order_hashes_tracker.ts
index ae7d5078c..d639242ac 100644
--- a/packages/order-watcher/src/order_watcher/dependent_order_hashes_tracker.ts
+++ b/packages/order-watcher/src/order_watcher/dependent_order_hashes_tracker.ts
@@ -54,7 +54,7 @@ export class DependentOrderHashesTracker {
return dependentOrderHashes;
}
public getDependentOrderHashesByAssetDataByMaker(makerAddress: string, assetData: string): string[] {
- const decodedAssetData = assetProxyUtils.decodeAssetData(assetData);
+ const decodedAssetData = assetProxyUtils.decodeAssetDataOrThrow(assetData);
const dependentOrderHashes =
decodedAssetData.assetProxyId === AssetProxyId.ERC20
? this._getDependentOrderHashesByERC20AssetData(makerAddress, assetData)
@@ -62,7 +62,7 @@ export class DependentOrderHashesTracker {
return dependentOrderHashes;
}
public addToDependentOrderHashes(signedOrder: SignedOrder): void {
- const decodedMakerAssetData = assetProxyUtils.decodeAssetData(signedOrder.makerAssetData);
+ const decodedMakerAssetData = assetProxyUtils.decodeAssetDataOrThrow(signedOrder.makerAssetData);
if (decodedMakerAssetData.assetProxyId === AssetProxyId.ERC20) {
this._addToERC20DependentOrderHashes(signedOrder, (decodedMakerAssetData as ERC20AssetData).tokenAddress);
} else {
@@ -76,7 +76,7 @@ export class DependentOrderHashesTracker {
this._addToMakerDependentOrderHashes(signedOrder);
}
public removeFromDependentOrderHashes(signedOrder: SignedOrder): void {
- const decodedMakerAssetData = assetProxyUtils.decodeAssetData(signedOrder.makerAssetData);
+ const decodedMakerAssetData = assetProxyUtils.decodeAssetDataOrThrow(signedOrder.makerAssetData);
if (decodedMakerAssetData.assetProxyId === AssetProxyId.ERC20) {
this._removeFromERC20DependentOrderhashes(
signedOrder,
diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts
index 0ad3267d8..afc854445 100644
--- a/packages/order-watcher/src/order_watcher/order_watcher.ts
+++ b/packages/order-watcher/src/order_watcher/order_watcher.ts
@@ -28,7 +28,7 @@ import {
orderHashUtils,
OrderStateUtils,
} from '@0xproject/order-utils';
-import { ExchangeContractErrs, OrderState, SignedOrder } from '@0xproject/types';
+import { AssetProxyId, ExchangeContractErrs, OrderState, SignedOrder } from '@0xproject/types';
import { errorUtils, intervalUtils } from '@0xproject/utils';
import { BlockParamLiteral, LogEntryEvent, LogWithDecodedArgs, Provider } from 'ethereum-types';
import * as _ from 'lodash';
@@ -134,16 +134,26 @@ export class OrderWatcher {
* signature is verified.
* @param signedOrder The order you wish to start watching.
*/
- public addOrder(signedOrder: SignedOrder): void {
+ public async addOrderAsync(signedOrder: SignedOrder): Promise<void> {
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
const orderHash = orderHashUtils.getOrderHashHex(signedOrder);
- assert.isValidSignatureAsync(this._provider, orderHash, signedOrder.signature, signedOrder.makerAddress);
+ await assert.isValidSignatureAsync(this._provider, orderHash, signedOrder.signature, signedOrder.makerAddress);
const expirationUnixTimestampMs = signedOrder.expirationTimeSeconds.times(MILLISECONDS_IN_A_SECOND);
this._expirationWatcher.addOrder(orderHash, expirationUnixTimestampMs);
this._orderByOrderHash[orderHash] = signedOrder;
this._dependentOrderHashesTracker.addToDependentOrderHashes(signedOrder);
+
+ const orderAssetDatas = [signedOrder.makerAssetData, signedOrder.takerAssetData];
+ _.each(orderAssetDatas, assetData => {
+ const decodedAssetData = assetProxyUtils.decodeAssetDataOrThrow(assetData);
+ if (decodedAssetData.assetProxyId === AssetProxyId.ERC20) {
+ this._collisionResistantAbiDecoder.addERC20Token(decodedAssetData.tokenAddress);
+ } else if (decodedAssetData.assetProxyId === AssetProxyId.ERC721) {
+ this._collisionResistantAbiDecoder.addERC721Token(decodedAssetData.tokenAddress);
+ }
+ });
}
/**
* Removes an order from the orderWatcher