diff options
author | Fabio Berger <me@fabioberger.com> | 2018-01-30 20:21:01 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-01-30 20:21:01 +0800 |
commit | 93a5b3f457c1211676296840c285759007a55500 (patch) | |
tree | d1682b657c207f447748e08550095bafc79b6997 /packages/testnet-faucets | |
parent | 4242176d291f54212797de9f5df80b1346724ebb (diff) | |
download | dexon-sol-tools-93a5b3f457c1211676296840c285759007a55500.tar dexon-sol-tools-93a5b3f457c1211676296840c285759007a55500.tar.gz dexon-sol-tools-93a5b3f457c1211676296840c285759007a55500.tar.bz2 dexon-sol-tools-93a5b3f457c1211676296840c285759007a55500.tar.lz dexon-sol-tools-93a5b3f457c1211676296840c285759007a55500.tar.xz dexon-sol-tools-93a5b3f457c1211676296840c285759007a55500.tar.zst dexon-sol-tools-93a5b3f457c1211676296840c285759007a55500.zip |
Fix prettier
Diffstat (limited to 'packages/testnet-faucets')
-rw-r--r-- | packages/testnet-faucets/README.md | 40 | ||||
-rw-r--r-- | packages/testnet-faucets/package.json | 82 | ||||
-rw-r--r-- | packages/testnet-faucets/src/ts/configs.ts | 10 | ||||
-rw-r--r-- | packages/testnet-faucets/src/ts/error_reporter.ts | 58 | ||||
-rw-r--r-- | packages/testnet-faucets/src/ts/ether_request_queue.ts | 30 | ||||
-rw-r--r-- | packages/testnet-faucets/src/ts/global.d.ts | 28 | ||||
-rw-r--r-- | packages/testnet-faucets/src/ts/handler.ts | 166 | ||||
-rw-r--r-- | packages/testnet-faucets/src/ts/id_management.ts | 26 | ||||
-rw-r--r-- | packages/testnet-faucets/src/ts/request_queue.ts | 80 | ||||
-rw-r--r-- | packages/testnet-faucets/src/ts/rpc_urls.ts | 8 | ||||
-rw-r--r-- | packages/testnet-faucets/src/ts/server.ts | 8 | ||||
-rw-r--r-- | packages/testnet-faucets/src/ts/utils.ts | 10 | ||||
-rw-r--r-- | packages/testnet-faucets/src/ts/zrx_request_queue.ts | 52 | ||||
-rw-r--r-- | packages/testnet-faucets/tsconfig.json | 10 | ||||
-rw-r--r-- | packages/testnet-faucets/tslint.json | 2 |
15 files changed, 305 insertions, 305 deletions
diff --git a/packages/testnet-faucets/README.md b/packages/testnet-faucets/README.md index a52d16a00..36322e76e 100644 --- a/packages/testnet-faucets/README.md +++ b/packages/testnet-faucets/README.md @@ -63,26 +63,26 @@ Returns a JSON payload describing the state of the queues for each network. For ```json { - "3": { - "ether": { - "full": false, - "size": 4 - }, - "zrx": { - "full": false, - "size": 6 - } - }, - "42": { - "ether": { - "full": false, - "size": 8 - }, - "zrx": { - "full": false, - "size": 20 - } - } + "3": { + "ether": { + "full": false, + "size": 4 + }, + "zrx": { + "full": false, + "size": 6 + } + }, + "42": { + "ether": { + "full": false, + "size": 8 + }, + "zrx": { + "full": false, + "size": 20 + } + } } ``` diff --git a/packages/testnet-faucets/package.json b/packages/testnet-faucets/package.json index 6c27df0d5..4f8bcfdcf 100644 --- a/packages/testnet-faucets/package.json +++ b/packages/testnet-faucets/package.json @@ -1,43 +1,43 @@ { - "private": true, - "name": "@0xproject/testnet-faucets", - "version": "1.0.7", - "description": "A faucet micro-service that dispenses test ERC20 tokens or Ether", - "main": "server.js", - "scripts": { - "build": "node ../../node_modules/gulp/bin/gulp.js build", - "dev": "node ../../node_modules/gulp/bin/gulp.js run", - "start": "node ./bin/server.js", - "lint": "tslint --project . 'src/**/*.ts'", - "clean": "shx rm -rf bin" - }, - "author": "Fabio Berger", - "license": "Apache-2.0", - "dependencies": { - "0x.js": "^0.30.2", - "@0xproject/utils": "^0.2.2", - "body-parser": "^1.17.1", - "ethereumjs-tx": "^1.3.3", - "express": "^4.15.2", - "lodash": "^4.17.4", - "rollbar": "^0.6.5", - "web3": "^0.20.0", - "web3-provider-engine": "^13.0.1" - }, - "devDependencies": { - "@0xproject/tslint-config": "^0.4.4", - "@types/body-parser": "^1.16.1", - "@types/express": "^4.0.35", - "@types/lodash": "^4.14.86", - "awesome-typescript-loader": "^3.1.3", - "gulp": "^3.9.1", - "nodemon": "^1.11.0", - "shx": "^0.2.2", - "source-map-loader": "^0.1.6", - "tslint": "5.8.0", - "typescript": "~2.6.1", - "web3-typescript-typings": "^0.9.6", - "webpack": "^3.1.0", - "webpack-node-externals": "^1.6.0" - } + "private": true, + "name": "@0xproject/testnet-faucets", + "version": "1.0.7", + "description": "A faucet micro-service that dispenses test ERC20 tokens or Ether", + "main": "server.js", + "scripts": { + "build": "node ../../node_modules/gulp/bin/gulp.js build", + "dev": "node ../../node_modules/gulp/bin/gulp.js run", + "start": "node ./bin/server.js", + "lint": "tslint --project . 'src/**/*.ts'", + "clean": "shx rm -rf bin" + }, + "author": "Fabio Berger", + "license": "Apache-2.0", + "dependencies": { + "0x.js": "^0.30.2", + "@0xproject/utils": "^0.2.2", + "body-parser": "^1.17.1", + "ethereumjs-tx": "^1.3.3", + "express": "^4.15.2", + "lodash": "^4.17.4", + "rollbar": "^0.6.5", + "web3": "^0.20.0", + "web3-provider-engine": "^13.0.1" + }, + "devDependencies": { + "@0xproject/tslint-config": "^0.4.4", + "@types/body-parser": "^1.16.1", + "@types/express": "^4.0.35", + "@types/lodash": "^4.14.86", + "awesome-typescript-loader": "^3.1.3", + "gulp": "^3.9.1", + "nodemon": "^1.11.0", + "shx": "^0.2.2", + "source-map-loader": "^0.1.6", + "tslint": "5.8.0", + "typescript": "~2.6.1", + "web3-typescript-typings": "^0.9.6", + "webpack": "^3.1.0", + "webpack-node-externals": "^1.6.0" + } } diff --git a/packages/testnet-faucets/src/ts/configs.ts b/packages/testnet-faucets/src/ts/configs.ts index 038c8e22a..038df5322 100644 --- a/packages/testnet-faucets/src/ts/configs.ts +++ b/packages/testnet-faucets/src/ts/configs.ts @@ -1,7 +1,7 @@ export const configs = { - DISPENSER_ADDRESS: (process.env.DISPENSER_ADDRESS as string).toLowerCase(), - DISPENSER_PRIVATE_KEY: process.env.DISPENSER_PRIVATE_KEY, - ENVIRONMENT: process.env.FAUCET_ENVIRONMENT, - INFURA_API_KEY: process.env.INFURA_API_KEY, - ROLLBAR_ACCESS_KEY: process.env.FAUCET_ROLLBAR_ACCESS_KEY, + DISPENSER_ADDRESS: (process.env.DISPENSER_ADDRESS as string).toLowerCase(), + DISPENSER_PRIVATE_KEY: process.env.DISPENSER_PRIVATE_KEY, + ENVIRONMENT: process.env.FAUCET_ENVIRONMENT, + INFURA_API_KEY: process.env.INFURA_API_KEY, + ROLLBAR_ACCESS_KEY: process.env.FAUCET_ROLLBAR_ACCESS_KEY, }; diff --git a/packages/testnet-faucets/src/ts/error_reporter.ts b/packages/testnet-faucets/src/ts/error_reporter.ts index 6865d3893..0cef6cfa8 100644 --- a/packages/testnet-faucets/src/ts/error_reporter.ts +++ b/packages/testnet-faucets/src/ts/error_reporter.ts @@ -5,36 +5,36 @@ import { configs } from './configs'; import { utils } from './utils'; export const errorReporter = { - setup() { - rollbar.init(configs.ROLLBAR_ACCESS_KEY, { - environment: configs.ENVIRONMENT, - }); + setup() { + rollbar.init(configs.ROLLBAR_ACCESS_KEY, { + environment: configs.ENVIRONMENT, + }); - rollbar.handleUncaughtExceptions(configs.ROLLBAR_ACCESS_KEY); + rollbar.handleUncaughtExceptions(configs.ROLLBAR_ACCESS_KEY); - process.on('unhandledRejection', async (err: Error) => { - utils.consoleLog(`Uncaught exception ${err}. Stack: ${err.stack}`); - await this.reportAsync(err); - process.exit(1); - }); - }, - async reportAsync(err: Error, req?: express.Request): Promise<any> { - if (configs.ENVIRONMENT === 'development') { - return; // Do not log development environment errors - } + process.on('unhandledRejection', async (err: Error) => { + utils.consoleLog(`Uncaught exception ${err}. Stack: ${err.stack}`); + await this.reportAsync(err); + process.exit(1); + }); + }, + async reportAsync(err: Error, req?: express.Request): Promise<any> { + if (configs.ENVIRONMENT === 'development') { + return; // Do not log development environment errors + } - return new Promise((resolve, reject) => { - rollbar.handleError(err, req, (rollbarErr: Error) => { - if (rollbarErr) { - utils.consoleLog(`Error reporting to rollbar, ignoring: ${rollbarErr}`); - reject(rollbarErr); - } else { - resolve(); - } - }); - }); - }, - errorHandler() { - return rollbar.errorHandler(configs.ROLLBAR_ACCESS_KEY); - }, + return new Promise((resolve, reject) => { + rollbar.handleError(err, req, (rollbarErr: Error) => { + if (rollbarErr) { + utils.consoleLog(`Error reporting to rollbar, ignoring: ${rollbarErr}`); + reject(rollbarErr); + } else { + resolve(); + } + }); + }); + }, + errorHandler() { + return rollbar.errorHandler(configs.ROLLBAR_ACCESS_KEY); + }, }; diff --git a/packages/testnet-faucets/src/ts/ether_request_queue.ts b/packages/testnet-faucets/src/ts/ether_request_queue.ts index 1c4b19ab9..aa75a00e4 100644 --- a/packages/testnet-faucets/src/ts/ether_request_queue.ts +++ b/packages/testnet-faucets/src/ts/ether_request_queue.ts @@ -9,19 +9,19 @@ import { utils } from './utils'; const DISPENSE_AMOUNT_ETHER = 0.1; export class EtherRequestQueue extends RequestQueue { - protected async processNextRequestFireAndForgetAsync(recipientAddress: string) { - utils.consoleLog(`Processing ETH ${recipientAddress}`); - const sendTransactionAsync = promisify(this.web3.eth.sendTransaction); - try { - const txHash = await sendTransactionAsync({ - from: configs.DISPENSER_ADDRESS, - to: recipientAddress, - value: this.web3.toWei(DISPENSE_AMOUNT_ETHER, 'ether'), - }); - utils.consoleLog(`Sent ${DISPENSE_AMOUNT_ETHER} ETH to ${recipientAddress} tx: ${txHash}`); - } catch (err) { - utils.consoleLog(`Unexpected err: ${err} - ${JSON.stringify(err)}`); - await errorReporter.reportAsync(err); - } - } + protected async processNextRequestFireAndForgetAsync(recipientAddress: string) { + utils.consoleLog(`Processing ETH ${recipientAddress}`); + const sendTransactionAsync = promisify(this.web3.eth.sendTransaction); + try { + const txHash = await sendTransactionAsync({ + from: configs.DISPENSER_ADDRESS, + to: recipientAddress, + value: this.web3.toWei(DISPENSE_AMOUNT_ETHER, 'ether'), + }); + utils.consoleLog(`Sent ${DISPENSE_AMOUNT_ETHER} ETH to ${recipientAddress} tx: ${txHash}`); + } catch (err) { + utils.consoleLog(`Unexpected err: ${err} - ${JSON.stringify(err)}`); + await errorReporter.reportAsync(err); + } + } } diff --git a/packages/testnet-faucets/src/ts/global.d.ts b/packages/testnet-faucets/src/ts/global.d.ts index 97cd35680..90866565d 100644 --- a/packages/testnet-faucets/src/ts/global.d.ts +++ b/packages/testnet-faucets/src/ts/global.d.ts @@ -5,22 +5,22 @@ declare module 'web3-provider-engine/subproviders/nonce-tracker'; declare module 'web3-provider-engine/subproviders/hooked-wallet'; declare module '*.json' { - const json: any; - /* tslint:disable */ - export default json; - /* tslint:enable */ + const json: any; + /* tslint:disable */ + export default json; + /* tslint:enable */ } // Ethereumjs-tx declarations declare module 'ethereumjs-tx' { - class EthereumTx { - public raw: Buffer[]; - public r: Buffer; - public s: Buffer; - public v: Buffer; - public serialize(): Buffer; - public sign(buffer: Buffer): void; - constructor(txParams: any); - } - export = EthereumTx; + class EthereumTx { + public raw: Buffer[]; + public r: Buffer; + public s: Buffer; + public v: Buffer; + public serialize(): Buffer; + public sign(buffer: Buffer): void; + constructor(txParams: any); + } + export = EthereumTx; } diff --git a/packages/testnet-faucets/src/ts/handler.ts b/packages/testnet-faucets/src/ts/handler.ts index bf5b3e81e..455a925e3 100644 --- a/packages/testnet-faucets/src/ts/handler.ts +++ b/packages/testnet-faucets/src/ts/handler.ts @@ -20,95 +20,95 @@ import { ZRXRequestQueue } from './zrx_request_queue'; import * as Web3 from 'web3'; interface RequestQueueByNetworkId { - [networkId: string]: RequestQueue; + [networkId: string]: RequestQueue; } enum QueueType { - ETH = 'ETH', - ZRX = 'ZRX', + ETH = 'ETH', + ZRX = 'ZRX', } const DEFAULT_NETWORK_ID = 42; // kovan export class Handler { - private _etherRequestQueueByNetworkId: RequestQueueByNetworkId = {}; - private _zrxRequestQueueByNetworkId: RequestQueueByNetworkId = {}; - constructor() { - _.forIn(rpcUrls, (rpcUrl: string, networkId: string) => { - const providerObj = this._createProviderEngine(rpcUrl); - const web3 = new Web3(providerObj); - this._etherRequestQueueByNetworkId[networkId] = new EtherRequestQueue(web3); - this._zrxRequestQueueByNetworkId[networkId] = new ZRXRequestQueue(web3, +networkId); - }); - } - public getQueueInfo(req: express.Request, res: express.Response) { - res.setHeader('Content-Type', 'application/json'); - const queueInfo = _.mapValues(rpcUrls, (rpcUrl: string, networkId: string) => { - utils.consoleLog(networkId); - const etherRequestQueue = this._etherRequestQueueByNetworkId[networkId]; - const zrxRequestQueue = this._zrxRequestQueueByNetworkId[networkId]; - return { - ether: { - full: etherRequestQueue.isFull(), - size: etherRequestQueue.size(), - }, - zrx: { - full: zrxRequestQueue.isFull(), - size: zrxRequestQueue.size(), - }, - }; - }); - const payload = JSON.stringify(queueInfo); - res.status(200).send(payload); - } - public dispenseEther(req: express.Request, res: express.Response) { - this._dispense(req, res, this._etherRequestQueueByNetworkId, QueueType.ETH); - } - public dispenseZRX(req: express.Request, res: express.Response) { - this._dispense(req, res, this._zrxRequestQueueByNetworkId, QueueType.ZRX); - } - private _dispense( - req: express.Request, - res: express.Response, - requestQueueByNetworkId: RequestQueueByNetworkId, - queueType: QueueType, - ) { - const recipientAddress = req.params.recipient; - if (_.isUndefined(recipientAddress) || !this._isValidEthereumAddress(recipientAddress)) { - res.status(400).send('INVALID_RECIPIENT_ADDRESS'); - return; - } - const networkId = _.get(req.query, 'networkId', DEFAULT_NETWORK_ID); - const requestQueue = _.get(requestQueueByNetworkId, networkId); - if (_.isUndefined(requestQueue)) { - res.status(400).send('INVALID_NETWORK_ID'); - return; - } - const lowerCaseRecipientAddress = recipientAddress.toLowerCase(); - const didAddToQueue = requestQueue.add(lowerCaseRecipientAddress); - if (!didAddToQueue) { - res.status(503).send('QUEUE_IS_FULL'); - return; - } - utils.consoleLog(`Added ${lowerCaseRecipientAddress} to queue: ${queueType} networkId: ${networkId}`); - res.status(200).end(); - } - // 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; - } - // tslint:disable-next-line:prefer-function-over-method - private _isValidEthereumAddress(address: string): boolean { - const lowercaseAddress = address.toLowerCase(); - return addressUtils.isAddress(lowercaseAddress); - } + private _etherRequestQueueByNetworkId: RequestQueueByNetworkId = {}; + private _zrxRequestQueueByNetworkId: RequestQueueByNetworkId = {}; + constructor() { + _.forIn(rpcUrls, (rpcUrl: string, networkId: string) => { + const providerObj = this._createProviderEngine(rpcUrl); + const web3 = new Web3(providerObj); + this._etherRequestQueueByNetworkId[networkId] = new EtherRequestQueue(web3); + this._zrxRequestQueueByNetworkId[networkId] = new ZRXRequestQueue(web3, +networkId); + }); + } + public getQueueInfo(req: express.Request, res: express.Response) { + res.setHeader('Content-Type', 'application/json'); + const queueInfo = _.mapValues(rpcUrls, (rpcUrl: string, networkId: string) => { + utils.consoleLog(networkId); + const etherRequestQueue = this._etherRequestQueueByNetworkId[networkId]; + const zrxRequestQueue = this._zrxRequestQueueByNetworkId[networkId]; + return { + ether: { + full: etherRequestQueue.isFull(), + size: etherRequestQueue.size(), + }, + zrx: { + full: zrxRequestQueue.isFull(), + size: zrxRequestQueue.size(), + }, + }; + }); + const payload = JSON.stringify(queueInfo); + res.status(200).send(payload); + } + public dispenseEther(req: express.Request, res: express.Response) { + this._dispense(req, res, this._etherRequestQueueByNetworkId, QueueType.ETH); + } + public dispenseZRX(req: express.Request, res: express.Response) { + this._dispense(req, res, this._zrxRequestQueueByNetworkId, QueueType.ZRX); + } + private _dispense( + req: express.Request, + res: express.Response, + requestQueueByNetworkId: RequestQueueByNetworkId, + queueType: QueueType, + ) { + const recipientAddress = req.params.recipient; + if (_.isUndefined(recipientAddress) || !this._isValidEthereumAddress(recipientAddress)) { + res.status(400).send('INVALID_RECIPIENT_ADDRESS'); + return; + } + const networkId = _.get(req.query, 'networkId', DEFAULT_NETWORK_ID); + const requestQueue = _.get(requestQueueByNetworkId, networkId); + if (_.isUndefined(requestQueue)) { + res.status(400).send('INVALID_NETWORK_ID'); + return; + } + const lowerCaseRecipientAddress = recipientAddress.toLowerCase(); + const didAddToQueue = requestQueue.add(lowerCaseRecipientAddress); + if (!didAddToQueue) { + res.status(503).send('QUEUE_IS_FULL'); + return; + } + utils.consoleLog(`Added ${lowerCaseRecipientAddress} to queue: ${queueType} networkId: ${networkId}`); + res.status(200).end(); + } + // 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; + } + // tslint:disable-next-line:prefer-function-over-method + private _isValidEthereumAddress(address: string): boolean { + const lowercaseAddress = address.toLowerCase(); + return addressUtils.isAddress(lowercaseAddress); + } } diff --git a/packages/testnet-faucets/src/ts/id_management.ts b/packages/testnet-faucets/src/ts/id_management.ts index db9b610a3..2f04b5ff9 100644 --- a/packages/testnet-faucets/src/ts/id_management.ts +++ b/packages/testnet-faucets/src/ts/id_management.ts @@ -5,17 +5,17 @@ import { configs } from './configs'; type Callback = (err: Error | null, accounts: any) => void; export const idManagement = { - getAccounts(callback: Callback) { - callback(null, [configs.DISPENSER_ADDRESS]); - }, - approveTransaction(txData: object, callback: Callback) { - callback(null, true); - }, - signTransaction(txData: object, callback: Callback) { - const tx = new EthereumTx(txData); - const privateKeyBuffer = new Buffer(configs.DISPENSER_PRIVATE_KEY as string, 'hex'); - tx.sign(privateKeyBuffer); - const rawTx = `0x${tx.serialize().toString('hex')}`; - callback(null, rawTx); - }, + getAccounts(callback: Callback) { + callback(null, [configs.DISPENSER_ADDRESS]); + }, + approveTransaction(txData: object, callback: Callback) { + callback(null, true); + }, + signTransaction(txData: object, callback: Callback) { + const tx = new EthereumTx(txData); + const privateKeyBuffer = new Buffer(configs.DISPENSER_PRIVATE_KEY as string, 'hex'); + tx.sign(privateKeyBuffer); + const rawTx = `0x${tx.serialize().toString('hex')}`; + callback(null, rawTx); + }, }; diff --git a/packages/testnet-faucets/src/ts/request_queue.ts b/packages/testnet-faucets/src/ts/request_queue.ts index 20f2833a1..37b5505f8 100644 --- a/packages/testnet-faucets/src/ts/request_queue.ts +++ b/packages/testnet-faucets/src/ts/request_queue.ts @@ -11,46 +11,46 @@ const MAX_QUEUE_SIZE = 500; const DEFAULT_QUEUE_INTERVAL_MS = 1000; export class RequestQueue { - protected queueIntervalMs: number; - protected queue: string[]; - protected queueIntervalId: NodeJS.Timer; - protected web3: Web3; - constructor(web3: any) { - this.queueIntervalMs = DEFAULT_QUEUE_INTERVAL_MS; - this.queue = []; + protected queueIntervalMs: number; + protected queue: string[]; + protected queueIntervalId: NodeJS.Timer; + protected web3: Web3; + constructor(web3: any) { + this.queueIntervalMs = DEFAULT_QUEUE_INTERVAL_MS; + this.queue = []; - this.web3 = web3; + this.web3 = web3; - this.start(); - } - public add(recipientAddress: string): boolean { - if (this.isFull()) { - return false; - } - this.queue.push(recipientAddress); - return true; - } - public size(): number { - return this.queue.length; - } - public isFull(): boolean { - return this.size() >= MAX_QUEUE_SIZE; - } - protected start() { - this.queueIntervalId = timers.setInterval(() => { - const recipientAddress = this.queue.shift(); - if (_.isUndefined(recipientAddress)) { - return; - } - // tslint:disable-next-line:no-floating-promises - this.processNextRequestFireAndForgetAsync(recipientAddress); - }, this.queueIntervalMs); - } - protected stop() { - clearInterval(this.queueIntervalId); - } - // tslint:disable-next-line:prefer-function-over-method - protected async processNextRequestFireAndForgetAsync(recipientAddress: string) { - throw new Error('Expected processNextRequestFireAndForgetAsync to be implemented by a subclass'); - } + this.start(); + } + public add(recipientAddress: string): boolean { + if (this.isFull()) { + return false; + } + this.queue.push(recipientAddress); + return true; + } + public size(): number { + return this.queue.length; + } + public isFull(): boolean { + return this.size() >= MAX_QUEUE_SIZE; + } + protected start() { + this.queueIntervalId = timers.setInterval(() => { + const recipientAddress = this.queue.shift(); + if (_.isUndefined(recipientAddress)) { + return; + } + // tslint:disable-next-line:no-floating-promises + this.processNextRequestFireAndForgetAsync(recipientAddress); + }, this.queueIntervalMs); + } + protected stop() { + clearInterval(this.queueIntervalId); + } + // tslint:disable-next-line:prefer-function-over-method + protected async processNextRequestFireAndForgetAsync(recipientAddress: string) { + throw new Error('Expected processNextRequestFireAndForgetAsync to be implemented by a subclass'); + } } diff --git a/packages/testnet-faucets/src/ts/rpc_urls.ts b/packages/testnet-faucets/src/ts/rpc_urls.ts index 25a3b938f..9e12bca37 100644 --- a/packages/testnet-faucets/src/ts/rpc_urls.ts +++ b/packages/testnet-faucets/src/ts/rpc_urls.ts @@ -1,13 +1,13 @@ import { configs } from './configs'; const productionRpcUrls = { - '2': `https://ropsten.infura.io/${configs.INFURA_API_KEY}`, - '3': `https://rinkeby.infura.io/${configs.INFURA_API_KEY}`, - '42': `https://kovan.infura.io/${configs.INFURA_API_KEY}`, + '2': `https://ropsten.infura.io/${configs.INFURA_API_KEY}`, + '3': `https://rinkeby.infura.io/${configs.INFURA_API_KEY}`, + '42': `https://kovan.infura.io/${configs.INFURA_API_KEY}`, }; const developmentRpcUrls = { - '50': 'http://127.0.0.1:8545', + '50': 'http://127.0.0.1:8545', }; export const rpcUrls = configs.ENVIRONMENT === 'development' ? developmentRpcUrls : productionRpcUrls; diff --git a/packages/testnet-faucets/src/ts/server.ts b/packages/testnet-faucets/src/ts/server.ts index 26edfff5a..6fb555538 100644 --- a/packages/testnet-faucets/src/ts/server.ts +++ b/packages/testnet-faucets/src/ts/server.ts @@ -10,14 +10,14 @@ errorReporter.setup(); const app = express(); app.use(bodyParser.json()); // for parsing application/json app.use((req, res, next) => { - res.header('Access-Control-Allow-Origin', '*'); - res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept'); - next(); + res.header('Access-Control-Allow-Origin', '*'); + res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept'); + next(); }); const handler = new Handler(); app.get('/ping', (req: express.Request, res: express.Response) => { - res.status(200).send('pong'); + res.status(200).send('pong'); }); app.get('/info', handler.getQueueInfo.bind(handler)); app.get('/ether/:recipient', handler.dispenseEther.bind(handler)); diff --git a/packages/testnet-faucets/src/ts/utils.ts b/packages/testnet-faucets/src/ts/utils.ts index 893f82ca3..821fe453c 100644 --- a/packages/testnet-faucets/src/ts/utils.ts +++ b/packages/testnet-faucets/src/ts/utils.ts @@ -1,7 +1,7 @@ export const utils = { - consoleLog(message: string) { - /* tslint:disable */ - console.log(message); - /* tslint:enable */ - }, + consoleLog(message: string) { + /* tslint:disable */ + console.log(message); + /* tslint:enable */ + }, }; diff --git a/packages/testnet-faucets/src/ts/zrx_request_queue.ts b/packages/testnet-faucets/src/ts/zrx_request_queue.ts index 3d73f9dd2..b81a44cd1 100644 --- a/packages/testnet-faucets/src/ts/zrx_request_queue.ts +++ b/packages/testnet-faucets/src/ts/zrx_request_queue.ts @@ -17,30 +17,30 @@ const DISPENSE_AMOUNT_ZRX = new BigNumber(0.1); const QUEUE_INTERVAL_MS = 5000; export class ZRXRequestQueue extends RequestQueue { - private _zeroEx: ZeroEx; - constructor(web3: Web3, networkId: number) { - super(web3); - this.queueIntervalMs = QUEUE_INTERVAL_MS; - const zeroExConfig = { - networkId, - }; - this._zeroEx = new ZeroEx(web3.currentProvider, zeroExConfig); - } - protected async processNextRequestFireAndForgetAsync(recipientAddress: string) { - utils.consoleLog(`Processing ZRX ${recipientAddress}`); - const baseUnitAmount = ZeroEx.toBaseUnitAmount(DISPENSE_AMOUNT_ZRX, 18); - try { - const zrxTokenAddress = this._zeroEx.exchange.getZRXTokenAddress(); - const txHash = await this._zeroEx.token.transferAsync( - zrxTokenAddress, - configs.DISPENSER_ADDRESS, - recipientAddress, - baseUnitAmount, - ); - utils.consoleLog(`Sent ${DISPENSE_AMOUNT_ZRX} ZRX to ${recipientAddress} tx: ${txHash}`); - } catch (err) { - utils.consoleLog(`Unexpected err: ${err} - ${JSON.stringify(err)}`); - await errorReporter.reportAsync(err); - } - } + private _zeroEx: ZeroEx; + constructor(web3: Web3, networkId: number) { + super(web3); + this.queueIntervalMs = QUEUE_INTERVAL_MS; + const zeroExConfig = { + networkId, + }; + this._zeroEx = new ZeroEx(web3.currentProvider, zeroExConfig); + } + protected async processNextRequestFireAndForgetAsync(recipientAddress: string) { + utils.consoleLog(`Processing ZRX ${recipientAddress}`); + const baseUnitAmount = ZeroEx.toBaseUnitAmount(DISPENSE_AMOUNT_ZRX, 18); + try { + const zrxTokenAddress = this._zeroEx.exchange.getZRXTokenAddress(); + const txHash = await this._zeroEx.token.transferAsync( + zrxTokenAddress, + configs.DISPENSER_ADDRESS, + recipientAddress, + baseUnitAmount, + ); + utils.consoleLog(`Sent ${DISPENSE_AMOUNT_ZRX} ZRX to ${recipientAddress} tx: ${txHash}`); + } catch (err) { + utils.consoleLog(`Unexpected err: ${err} - ${JSON.stringify(err)}`); + await errorReporter.reportAsync(err); + } + } } diff --git a/packages/testnet-faucets/tsconfig.json b/packages/testnet-faucets/tsconfig.json index 7f0c084ff..e3353cc95 100644 --- a/packages/testnet-faucets/tsconfig.json +++ b/packages/testnet-faucets/tsconfig.json @@ -1,7 +1,7 @@ { - "extends": "../../tsconfig", - "compilerOptions": { - "outDir": "lib" - }, - "include": ["./src/ts/**/*", "../../node_modules/web3-typescript-typings/index.d.ts"] + "extends": "../../tsconfig", + "compilerOptions": { + "outDir": "lib" + }, + "include": ["./src/ts/**/*", "../../node_modules/web3-typescript-typings/index.d.ts"] } diff --git a/packages/testnet-faucets/tslint.json b/packages/testnet-faucets/tslint.json index ffaefe83a..e63054bfc 100644 --- a/packages/testnet-faucets/tslint.json +++ b/packages/testnet-faucets/tslint.json @@ -1,3 +1,3 @@ { - "extends": ["@0xproject/tslint-config"] + "extends": ["@0xproject/tslint-config"] } |