diff options
author | Fabio Berger <me@fabioberger.com> | 2018-01-30 21:00:35 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-01-30 21:00:35 +0800 |
commit | 69151c06e42fd588506db3aa62b95df5b4399607 (patch) | |
tree | 878532483594627a5283f784ced0a2c0cfc68d59 /packages/kovan-faucets/src/ts/handler.ts | |
parent | 86cc011212088801a778d947ae925cc0b1ddadf8 (diff) | |
parent | 2e3c02887efc24de35ce82b3662d9c47a0056a8c (diff) | |
download | dexon-sol-tools-69151c06e42fd588506db3aa62b95df5b4399607.tar dexon-sol-tools-69151c06e42fd588506db3aa62b95df5b4399607.tar.gz dexon-sol-tools-69151c06e42fd588506db3aa62b95df5b4399607.tar.bz2 dexon-sol-tools-69151c06e42fd588506db3aa62b95df5b4399607.tar.lz dexon-sol-tools-69151c06e42fd588506db3aa62b95df5b4399607.tar.xz dexon-sol-tools-69151c06e42fd588506db3aa62b95df5b4399607.tar.zst dexon-sol-tools-69151c06e42fd588506db3aa62b95df5b4399607.zip |
Merge branch 'development' into feature/portal-ledger-support
* development:
Publish
Add PR number
Add config file specifically in prettier command and fix files
Fix prettier
Fix prettier
Add shouldAddPersonalMessagePrefix param to signOrderHashAsync instead of trying to infer whether to add it or not from the nodeVersion
Publish
Move @0xproject/types to dependencies
Updated web3-typescript-typings changelog
Fixed getTransactionReceipt not returning null
Run prettier
Update changelog
Add Rinkeby addresses to artifacts
Fix bad merge on package.json
Respond to GH comments and add /info endpoint
Change package name to @0xproject/testnet-faucets
Implement testnet faucets for any testnet available via infura
Rename to testnet-faucets
Add to the Pull Request Template
Create an ISSUE TEMPLATE
Diffstat (limited to 'packages/kovan-faucets/src/ts/handler.ts')
-rw-r--r-- | packages/kovan-faucets/src/ts/handler.ts | 93 |
1 files changed, 0 insertions, 93 deletions
diff --git a/packages/kovan-faucets/src/ts/handler.ts b/packages/kovan-faucets/src/ts/handler.ts deleted file mode 100644 index 4bf776264..000000000 --- a/packages/kovan-faucets/src/ts/handler.ts +++ /dev/null @@ -1,93 +0,0 @@ -import * as express from 'express'; -import * as _ from 'lodash'; -import ProviderEngine = require('web3-provider-engine'); -import HookedWalletSubprovider = require('web3-provider-engine/subproviders/hooked-wallet'); -import NonceSubprovider = require('web3-provider-engine/subproviders/nonce-tracker'); -import RpcSubprovider = require('web3-provider-engine/subproviders/rpc'); - -import { configs } from './configs'; -import { EtherRequestQueue } from './ether_request_queue'; -import { idManagement } from './id_management'; -import { utils } from './utils'; -import { ZRXRequestQueue } from './zrx_request_queue'; - -// HACK: web3 leaks XMLHttpRequest into the global scope and causes requests to hang -// because they are using the wrong XHR package. -// Filed issue: https://github.com/ethereum/web3.js/issues/844 -// tslint:disable-next-line:ordered-imports -import * as Web3 from 'web3'; - -export class Handler { - private _etherRequestQueue: EtherRequestQueue; - private _zrxRequestQueue: ZRXRequestQueue; - private _web3: Web3; - constructor() { - // Setup provider engine to talk with RPC node - const providerObj = this._createProviderEngine(configs.RPC_URL); - this._web3 = new Web3(providerObj); - - this._etherRequestQueue = new EtherRequestQueue(this._web3); - this._zrxRequestQueue = new ZRXRequestQueue(this._web3); - } - public dispenseEther(req: express.Request, res: express.Response) { - const recipientAddress = req.params.recipient; - if (_.isUndefined(recipientAddress) || !this._isValidEthereumAddress(recipientAddress)) { - res.status(400).send('INVALID_REQUEST'); - return; - } - const lowerCaseRecipientAddress = recipientAddress.toLowerCase(); - const didAddToQueue = this._etherRequestQueue.add(lowerCaseRecipientAddress); - if (!didAddToQueue) { - res.status(503).send('QUEUE_IS_FULL'); - return; - } - utils.consoleLog(`Added ${lowerCaseRecipientAddress} to the ETH queue`); - res.status(200).end(); - } - public dispenseZRX(req: express.Request, res: express.Response) { - const recipientAddress = req.params.recipient; - if (_.isUndefined(recipientAddress) || !this._isValidEthereumAddress(recipientAddress)) { - res.status(400).send('INVALID_REQUEST'); - return; - } - const lowerCaseRecipientAddress = recipientAddress.toLowerCase(); - const didAddToQueue = this._zrxRequestQueue.add(lowerCaseRecipientAddress); - if (!didAddToQueue) { - res.status(503).send('QUEUE_IS_FULL'); - return; - } - utils.consoleLog(`Added ${lowerCaseRecipientAddress} to the ZRX queue`); - res.status(200).end(); - } - public getQueueInfo(req: express.Request, res: express.Response) { - res.setHeader('Content-Type', 'application/json'); - const payload = JSON.stringify({ - ether: { - full: this._etherRequestQueue.isFull(), - size: this._etherRequestQueue.size(), - }, - zrx: { - full: this._zrxRequestQueue.isFull(), - size: this._zrxRequestQueue.size(), - }, - }); - res.status(200).send(payload); - } - // tslint:disable-next-line:prefer-function-over-method - private _createProviderEngine(rpcUrl: string) { - const engine = new ProviderEngine(); - engine.addProvider(new NonceSubprovider()); - engine.addProvider(new HookedWalletSubprovider(idManagement)); - engine.addProvider( - new RpcSubprovider({ - rpcUrl, - }), - ); - engine.start(); - return engine; - } - private _isValidEthereumAddress(address: string): boolean { - const lowercaseAddress = address.toLowerCase(); - return this._web3.isAddress(lowercaseAddress); - } -} |