diff options
Diffstat (limited to 'packages/testnet-faucets')
-rw-r--r-- | packages/testnet-faucets/Dockerfile | 2 | ||||
-rw-r--r-- | packages/testnet-faucets/README.md | 20 | ||||
-rw-r--r-- | packages/testnet-faucets/gulpfile.js | 6 | ||||
-rw-r--r-- | packages/testnet-faucets/package.json | 10 | ||||
-rw-r--r-- | packages/testnet-faucets/src/ts/dispatch_queue.ts | 4 | ||||
-rw-r--r-- | packages/testnet-faucets/src/ts/dispense_asset_tasks.ts | 6 | ||||
-rw-r--r-- | packages/testnet-faucets/src/ts/error_reporter.ts | 4 | ||||
-rw-r--r-- | packages/testnet-faucets/src/ts/handler.ts | 29 | ||||
-rw-r--r-- | packages/testnet-faucets/src/ts/parameter_transformer.ts | 2 | ||||
-rw-r--r-- | packages/testnet-faucets/src/ts/server.ts | 4 |
10 files changed, 45 insertions, 42 deletions
diff --git a/packages/testnet-faucets/Dockerfile b/packages/testnet-faucets/Dockerfile index bd1dcc4a4..198087ba6 100644 --- a/packages/testnet-faucets/Dockerfile +++ b/packages/testnet-faucets/Dockerfile @@ -15,4 +15,4 @@ COPY . . EXPOSE 3000 -CMD ["forever", "./bin/server.js"] +CMD ["forever", "./server/server.js"] diff --git a/packages/testnet-faucets/README.md b/packages/testnet-faucets/README.md index 93f97e1b7..a92b93fc0 100644 --- a/packages/testnet-faucets/README.md +++ b/packages/testnet-faucets/README.md @@ -28,28 +28,16 @@ yarn install ### Build -If this is your **first** time building this package, you must first build **all** packages within the monorepo. This is because packages that depend on other packages located inside this monorepo are symlinked when run from **within** the monorepo. This allows you to make changes across multiple packages without first publishing dependent packages to NPM. To build all packages, run the following from the monorepo root directory: +To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory: ```bash -yarn lerna:rebuild +PKG=@0xproject/testnet-faucets yarn build ``` Or continuously rebuild on change: ```bash -yarn dev -``` - -You can also build this specific package by running the following from within its directory: - -```bash -yarn build -``` - -or continuously rebuild on change: - -```bash -yarn build:watch +PKG=@0xproject/testnet-faucets yarn watch ``` ### Clean @@ -86,7 +74,7 @@ Infura API Key can be requested here: https://infura.io/signup Note: The above public/private keys exist when running `testrpc` with the following option `--mnemonic concert load couple harbor equip island argue ramp clarify fence smart topic`. ```bash -yarn dev +PKG=0x.js yarn watch ``` ### Endpoints diff --git a/packages/testnet-faucets/gulpfile.js b/packages/testnet-faucets/gulpfile.js index 773faf33a..7c4e25e0f 100644 --- a/packages/testnet-faucets/gulpfile.js +++ b/packages/testnet-faucets/gulpfile.js @@ -9,7 +9,7 @@ const config = { target: 'node', entry: [path.join(__dirname, '/src/ts/server.ts')], output: { - path: path.join(__dirname, '/bin'), + path: path.join(__dirname, '/server'), filename: 'server.js', }, devtool: 'source-map', @@ -47,7 +47,7 @@ const config = { modulesDir: path.join(__dirname, '../../node_modules') }), watchOptions: { - ignored: /bin|node_modules|transpiled/ + ignored: /server|node_modules|transpiled/ }, }; @@ -67,7 +67,7 @@ gulp.task('run', ['watch'], function() { execMap: { js: 'node', }, - script: path.join(__dirname, 'bin/server'), + script: path.join(__dirname, 'server/server'), ignore: ['*'], watch: ['foo/'], ext: 'noop', diff --git a/packages/testnet-faucets/package.json b/packages/testnet-faucets/package.json index 198c0b2f7..693e980ed 100644 --- a/packages/testnet-faucets/package.json +++ b/packages/testnet-faucets/package.json @@ -2,21 +2,25 @@ "private": true, "name": "@0xproject/testnet-faucets", "version": "1.0.29", + "engines": { + "node" : ">=6.12" + }, "description": "A faucet micro-service that dispenses test ERC20 tokens or Ether", "main": "server.js", "scripts": { - "build:watch": "tsc -w", + "watch": "tsc -w", "build": "node ../../node_modules/gulp/bin/gulp.js build", "dev": "node ../../node_modules/gulp/bin/gulp.js run", - "start": "node ./bin/server.js", + "start": "node ./server/server.js", "lint": "tslint --project .", - "clean": "shx rm -rf bin" + "clean": "shx rm -rf server" }, "author": "Fabio Berger", "license": "Apache-2.0", "dependencies": { "0x.js": "^0.37.2", "@0xproject/subproviders": "^0.10.1", + "@0xproject/types": "^0.6.3", "@0xproject/typescript-typings": "^0.3.1", "@0xproject/utils": "^0.6.1", "body-parser": "^1.17.1", diff --git a/packages/testnet-faucets/src/ts/dispatch_queue.ts b/packages/testnet-faucets/src/ts/dispatch_queue.ts index 2dbeeba7a..b1996a0c2 100644 --- a/packages/testnet-faucets/src/ts/dispatch_queue.ts +++ b/packages/testnet-faucets/src/ts/dispatch_queue.ts @@ -28,12 +28,12 @@ export class DispatchQueue { public isFull(): boolean { return this.size() >= MAX_QUEUE_SIZE; } - public stop() { + public stop(): void { if (!_.isUndefined(this._queueIntervalIdIfExists)) { intervalUtils.clearAsyncExcludingInterval(this._queueIntervalIdIfExists); } } - private _start() { + private _start(): void { this._queueIntervalIdIfExists = intervalUtils.setAsyncExcludingInterval( async () => { const taskAsync = this._queue.shift(); diff --git a/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts b/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts index 99f1bad36..39ba4bc14 100644 --- a/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts +++ b/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts @@ -11,8 +11,10 @@ const DISPENSE_AMOUNT_TOKEN = 0.1; const DISPENSE_MAX_AMOUNT_TOKEN = 2; const DISPENSE_MAX_AMOUNT_ETHER = 2; +type AsyncTask = () => Promise<void>; + export const dispenseAssetTasks = { - dispenseEtherTask(recipientAddress: string, web3: Web3) { + dispenseEtherTask(recipientAddress: string, web3: Web3): AsyncTask { return async () => { logUtils.log(`Processing ETH ${recipientAddress}`); const userBalance = await promisify<BigNumber>(web3.eth.getBalance)(recipientAddress); @@ -32,7 +34,7 @@ export const dispenseAssetTasks = { logUtils.log(`Sent ${DISPENSE_AMOUNT_ETHER} ETH to ${recipientAddress} tx: ${txHash}`); }; }, - dispenseTokenTask(recipientAddress: string, tokenSymbol: string, zeroEx: ZeroEx) { + dispenseTokenTask(recipientAddress: string, tokenSymbol: string, zeroEx: ZeroEx): AsyncTask { return async () => { logUtils.log(`Processing ${tokenSymbol} ${recipientAddress}`); const amountToDispense = new BigNumber(DISPENSE_AMOUNT_TOKEN); diff --git a/packages/testnet-faucets/src/ts/error_reporter.ts b/packages/testnet-faucets/src/ts/error_reporter.ts index f0f3ca679..a0abcc07b 100644 --- a/packages/testnet-faucets/src/ts/error_reporter.ts +++ b/packages/testnet-faucets/src/ts/error_reporter.ts @@ -5,7 +5,7 @@ import rollbar = require('rollbar'); import { configs } from './configs'; export const errorReporter = { - setup() { + setup(): void { rollbar.init(configs.ROLLBAR_ACCESS_KEY, { environment: configs.ENVIRONMENT, }); @@ -31,7 +31,7 @@ export const errorReporter = { }); }); }, - errorHandler() { + errorHandler(): any { return rollbar.errorHandler(configs.ROLLBAR_ACCESS_KEY); }, }; diff --git a/packages/testnet-faucets/src/ts/handler.ts b/packages/testnet-faucets/src/ts/handler.ts index a6e786552..3858b5339 100644 --- a/packages/testnet-faucets/src/ts/handler.ts +++ b/packages/testnet-faucets/src/ts/handler.ts @@ -1,4 +1,5 @@ import { Order, SignedOrder, ZeroEx } from '0x.js'; +import { Provider } from '@0xproject/types'; import { BigNumber, logUtils } from '@0xproject/utils'; import * as express from 'express'; import * as _ from 'lodash'; @@ -38,7 +39,7 @@ const FIVE_DAYS_IN_MS = 4.32e8; // TODO: make this configurable export class Handler { private _networkConfigByNetworkId: ItemByNetworkId<NetworkConfig> = {}; - private static _createProviderEngine(rpcUrl: string) { + private static _createProviderEngine(rpcUrl: string): Provider { if (_.isUndefined(configs.DISPENSER_PRIVATE_KEY)) { throw new Error('Dispenser Private key not found'); } @@ -69,7 +70,7 @@ export class Handler { }; }); } - public getQueueInfo(req: express.Request, res: express.Response) { + public getQueueInfo(req: express.Request, res: express.Response): void { res.setHeader('Content-Type', 'application/json'); const queueInfo = _.mapValues(rpcUrls, (rpcUrl: string, networkId: string) => { const dispatchQueue = this._networkConfigByNetworkId[networkId].dispatchQueue; @@ -81,19 +82,23 @@ export class Handler { const payload = JSON.stringify(queueInfo); res.status(200).send(payload); } - public dispenseEther(req: express.Request, res: express.Response) { + public dispenseEther(req: express.Request, res: express.Response): void { this._dispenseAsset(req, res, RequestedAssetType.ETH); } - public dispenseZRX(req: express.Request, res: express.Response) { + public dispenseZRX(req: express.Request, res: express.Response): void { this._dispenseAsset(req, res, RequestedAssetType.ZRX); } - public async dispenseWETHOrder(req: express.Request, res: express.Response) { - await this._dispenseOrder(req, res, RequestedAssetType.WETH); + public async dispenseWETHOrderAsync(req: express.Request, res: express.Response): Promise<void> { + await this._dispenseOrderAsync(req, res, RequestedAssetType.WETH); } - public async dispenseZRXOrder(req: express.Request, res: express.Response, next: express.NextFunction) { - await this._dispenseOrder(req, res, RequestedAssetType.ZRX); + public async dispenseZRXOrderAsync( + req: express.Request, + res: express.Response, + next: express.NextFunction, + ): Promise<void> { + await this._dispenseOrderAsync(req, res, RequestedAssetType.ZRX); } - private _dispenseAsset(req: express.Request, res: express.Response, requestedAssetType: RequestedAssetType) { + private _dispenseAsset(req: express.Request, res: express.Response, requestedAssetType: RequestedAssetType): void { const networkId = req.params.networkId; const recipient = req.params.recipient; const networkConfig = this._networkConfigByNetworkId[networkId]; @@ -121,7 +126,11 @@ export class Handler { logUtils.log(`Added ${recipient} to queue: ${requestedAssetType} networkId: ${networkId}`); res.status(200).end(); } - private async _dispenseOrder(req: express.Request, res: express.Response, requestedAssetType: RequestedAssetType) { + private async _dispenseOrderAsync( + req: express.Request, + res: express.Response, + requestedAssetType: RequestedAssetType, + ): Promise<void> { const networkConfig = _.get(this._networkConfigByNetworkId, req.params.networkId); if (_.isUndefined(networkConfig)) { res.status(400).send('UNSUPPORTED_NETWORK_ID'); diff --git a/packages/testnet-faucets/src/ts/parameter_transformer.ts b/packages/testnet-faucets/src/ts/parameter_transformer.ts index 2630a5e0b..58bf154dc 100644 --- a/packages/testnet-faucets/src/ts/parameter_transformer.ts +++ b/packages/testnet-faucets/src/ts/parameter_transformer.ts @@ -8,7 +8,7 @@ import { rpcUrls } from './rpc_urls'; const DEFAULT_NETWORK_ID = 42; // kovan export const parameterTransformer = { - transform(req: Request, res: Response, next: NextFunction) { + transform(req: Request, res: Response, next: NextFunction): void { const recipientAddress = req.params.recipient; if (_.isUndefined(recipientAddress) || !addressUtils.isAddress(recipientAddress)) { res.status(400).send('INVALID_RECIPIENT_ADDRESS'); diff --git a/packages/testnet-faucets/src/ts/server.ts b/packages/testnet-faucets/src/ts/server.ts index be1077756..198a5fdc9 100644 --- a/packages/testnet-faucets/src/ts/server.ts +++ b/packages/testnet-faucets/src/ts/server.ts @@ -23,8 +23,8 @@ app.get('/ping', (req: express.Request, res: express.Response) => { app.get('/info', handler.getQueueInfo.bind(handler)); app.get('/ether/:recipient', parameterTransformer.transform, handler.dispenseEther.bind(handler)); app.get('/zrx/:recipient', parameterTransformer.transform, handler.dispenseZRX.bind(handler)); -app.get('/order/weth/:recipient', parameterTransformer.transform, handler.dispenseWETHOrder.bind(handler)); -app.get('/order/zrx/:recipient', parameterTransformer.transform, handler.dispenseZRXOrder.bind(handler)); +app.get('/order/weth/:recipient', parameterTransformer.transform, handler.dispenseWETHOrderAsync.bind(handler)); +app.get('/order/zrx/:recipient', parameterTransformer.transform, handler.dispenseZRXOrderAsync.bind(handler)); // Log to rollbar any errors unhandled by handlers app.use(errorReporter.errorHandler()); |