diff options
author | Fabio Berger <me@fabioberger.com> | 2017-11-13 10:12:37 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2017-11-13 10:12:37 +0800 |
commit | e33027c6244b99a1fb181404668bd2a259d923e2 (patch) | |
tree | 24438eda01318a80b5cbc7f1939d1640764a9859 /src/0x.ts | |
parent | 5d2b6585c66fc17a36bb9841a3b3fb009e23024c (diff) | |
parent | b0be323e899ea7be42b6c695b4fd6d526070b213 (diff) | |
download | dexon-sol-tools-e33027c6244b99a1fb181404668bd2a259d923e2.tar dexon-sol-tools-e33027c6244b99a1fb181404668bd2a259d923e2.tar.gz dexon-sol-tools-e33027c6244b99a1fb181404668bd2a259d923e2.tar.bz2 dexon-sol-tools-e33027c6244b99a1fb181404668bd2a259d923e2.tar.lz dexon-sol-tools-e33027c6244b99a1fb181404668bd2a259d923e2.tar.xz dexon-sol-tools-e33027c6244b99a1fb181404668bd2a259d923e2.tar.zst dexon-sol-tools-e33027c6244b99a1fb181404668bd2a259d923e2.zip |
Merge branch 'development' into feature/receipt-status
* development: (164 commits)
Remove old tests
Remove unused code
Fix tests
Remove redundant spaces
Don't store empty objects
Fix a typo
Remove duplicate operations
Remove redundant instance variables
Fix tests
Remove blockStore and default to numConfirmations === 0
Add a comment
Store number of confirmations in a blockStore
Remove tautology check
Pass blockStore to eventWatcher
Fix last merge conflicts
Clear cache on unsubscribe
Clear store cache on events
Add more configs for order watcher
Make subscribe function async and make blockStore operational
Adjust tests to new interface
...
# Conflicts:
# package.json
# src/types.ts
# yarn.lock
Diffstat (limited to 'src/0x.ts')
-rw-r--r-- | src/0x.ts | 33 |
1 files changed, 14 insertions, 19 deletions
@@ -16,6 +16,8 @@ import {TokenRegistryWrapper} from './contract_wrappers/token_registry_wrapper'; import {EtherTokenWrapper} from './contract_wrappers/ether_token_wrapper'; import {TokenWrapper} from './contract_wrappers/token_wrapper'; import {TokenTransferProxyWrapper} from './contract_wrappers/token_transfer_proxy_wrapper'; +import {OrderStateWatcher} from './order_watcher/order_state_watcher'; +import {OrderStateUtils} from './utils/order_state_utils'; import { ECSignature, ZeroExError, @@ -23,6 +25,7 @@ import { SignedOrder, Web3Provider, ZeroExConfig, + OrderStateWatcherConfig, TransactionReceiptWithDecodedLogs, } from './types'; import {zeroExConfigSchema} from './schemas/zero_ex_config_schema'; @@ -65,6 +68,11 @@ export class ZeroEx { * tokenTransferProxy smart contract. */ public proxy: TokenTransferProxyWrapper; + /** + * An instance of the OrderStateWatcher class containing methods for watching a set of orders for relevant + * blockchain state changes. + */ + public orderStateWatcher: OrderStateWatcher; private _web3Wrapper: Web3Wrapper; private _abiDecoder: AbiDecoder; /** @@ -80,19 +88,8 @@ export class ZeroEx { assert.doesConformToSchema('signature', signature, schemas.ecSignatureSchema); assert.isETHAddressHex('signerAddress', signerAddress); - const dataBuff = ethUtil.toBuffer(data); - const msgHashBuff = ethUtil.hashPersonalMessage(dataBuff); - try { - const pubKey = ethUtil.ecrecover( - msgHashBuff, - signature.v, - ethUtil.toBuffer(signature.r), - ethUtil.toBuffer(signature.s)); - const retrievedAddress = ethUtil.bufferToHex(ethUtil.pubToAddress(pubKey)); - return retrievedAddress === signerAddress; - } catch (err) { - return false; - } + const isValidSignature = signatureUtils.isValidSignature(data, signature, signerAddress); + return isValidSignature; } /** * Generates a pseudo-random 256-bit salt. @@ -177,12 +174,6 @@ export class ZeroEx { if (!_.isUndefined(config)) { assert.doesConformToSchema('config', config, zeroExConfigSchema); } - if (_.isUndefined((provider as any).sendAsync)) { - // Web3@1.0 provider doesn't support synchronous http requests, - // so it only has an async `send` method, instead of a `send` and `sendAsync` in web3@0.x.x` - // We re-assign the send method so that Web3@1.0 providers work with 0x.js - (provider as any).sendAsync = (provider as any).send; - } const artifactJSONs = _.values(artifacts); const abiArrays = _.map(artifactJSONs, artifact => artifact.abi); this._abiDecoder = new AbiDecoder(abiArrays); @@ -213,6 +204,10 @@ export class ZeroEx { this.tokenRegistry = new TokenRegistryWrapper(this._web3Wrapper, tokenRegistryContractAddressIfExists); const etherTokenContractAddressIfExists = _.isUndefined(config) ? undefined : config.etherTokenContractAddress; this.etherToken = new EtherTokenWrapper(this._web3Wrapper, this.token, etherTokenContractAddressIfExists); + const orderWatcherConfig = _.isUndefined(config) ? undefined : config.orderWatcherConfig; + this.orderStateWatcher = new OrderStateWatcher( + this._web3Wrapper, this._abiDecoder, this.token, this.exchange, orderWatcherConfig, + ); } /** * Sets a new web3 provider for 0x.js. Updating the provider will stop all |