aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorLeonid <logvinov.leon@gmail.com>2017-06-07 18:22:05 +0800
committerGitHub <noreply@github.com>2017-06-07 18:22:05 +0800
commit28d3528e42563f95255cee3bd7f85cc03141522e (patch)
tree9d9119c79f1ad4f1b097253ddc7ee4cac2415e58 /src/utils
parent8ec3bec5b3de726fbf2cc828e179ac2ed1029d9f (diff)
parent8ec2f685abefd77186b9bad5d67c9b23a9c03acf (diff)
downloaddexon-sol-tools-28d3528e42563f95255cee3bd7f85cc03141522e.tar
dexon-sol-tools-28d3528e42563f95255cee3bd7f85cc03141522e.tar.gz
dexon-sol-tools-28d3528e42563f95255cee3bd7f85cc03141522e.tar.bz2
dexon-sol-tools-28d3528e42563f95255cee3bd7f85cc03141522e.tar.lz
dexon-sol-tools-28d3528e42563f95255cee3bd7f85cc03141522e.tar.xz
dexon-sol-tools-28d3528e42563f95255cee3bd7f85cc03141522e.tar.zst
dexon-sol-tools-28d3528e42563f95255cee3bd7f85cc03141522e.zip
Merge pull request #40 from 0xProject/cancelAsync
Add cancelOrderAsync
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/utils.ts28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/utils/utils.ts b/src/utils/utils.ts
index 114b46f6c..5786bab07 100644
--- a/src/utils/utils.ts
+++ b/src/utils/utils.ts
@@ -1,5 +1,9 @@
import * as _ from 'lodash';
import * as BN from 'bn.js';
+import * as ethABI from 'ethereumjs-abi';
+import * as ethUtil from 'ethereumjs-util';
+import {Order, SignedOrder, SolidityTypes} from '../types';
+import * as BigNumber from 'bignumber.js';
export const utils = {
/**
@@ -25,4 +29,28 @@ export const utils = {
spawnSwitchErr(name: string, value: any) {
return new Error(`Unexpected switch value: ${value} encountered for ${name}`);
},
+ getOrderHashHex(order: Order|SignedOrder, exchangeContractAddr: string): string {
+ const orderParts = [
+ {value: exchangeContractAddr, type: SolidityTypes.address},
+ {value: order.maker, type: SolidityTypes.address},
+ {value: order.taker, type: SolidityTypes.address},
+ {value: order.makerTokenAddress, type: SolidityTypes.address},
+ {value: order.takerTokenAddress, type: SolidityTypes.address},
+ {value: order.feeRecipient, type: SolidityTypes.address},
+ {value: utils.bigNumberToBN(order.makerTokenAmount), type: SolidityTypes.uint256},
+ {value: utils.bigNumberToBN(order.takerTokenAmount), type: SolidityTypes.uint256},
+ {value: utils.bigNumberToBN(order.makerFee), type: SolidityTypes.uint256},
+ {value: utils.bigNumberToBN(order.takerFee), type: SolidityTypes.uint256},
+ {value: utils.bigNumberToBN(order.expirationUnixTimestampSec), type: SolidityTypes.uint256},
+ {value: utils.bigNumberToBN(order.salt), type: SolidityTypes.uint256},
+ ];
+ const types = _.map(orderParts, o => o.type);
+ const values = _.map(orderParts, o => o.value);
+ const hashBuff = ethABI.soliditySHA3(types, values);
+ const hashHex = ethUtil.bufferToHex(hashBuff);
+ return hashHex;
+ },
+ getCurrentUnixTimestamp(): BigNumber.BigNumber {
+ return new BigNumber(Date.now() / 1000);
+ },
};