aboutsummaryrefslogtreecommitdiffstats
path: root/packages/testnet-faucets
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-05-23 00:25:02 +0800
committerFabio Berger <me@fabioberger.com>2018-05-23 00:25:02 +0800
commit4a0c8d72b05152ee2fd71245873d5a70f7281058 (patch)
tree2c28ad8214aaaa10913a621509d0ae4020ee4d3d /packages/testnet-faucets
parentd460c0e8b9c6f4081803fff4e2d2347be8cd5ce3 (diff)
parentab9cfd293b3ccc2aacb4238aebe2b033e55b7935 (diff)
downloaddexon-sol-tools-4a0c8d72b05152ee2fd71245873d5a70f7281058.tar
dexon-sol-tools-4a0c8d72b05152ee2fd71245873d5a70f7281058.tar.gz
dexon-sol-tools-4a0c8d72b05152ee2fd71245873d5a70f7281058.tar.bz2
dexon-sol-tools-4a0c8d72b05152ee2fd71245873d5a70f7281058.tar.lz
dexon-sol-tools-4a0c8d72b05152ee2fd71245873d5a70f7281058.tar.xz
dexon-sol-tools-4a0c8d72b05152ee2fd71245873d5a70f7281058.tar.zst
dexon-sol-tools-4a0c8d72b05152ee2fd71245873d5a70f7281058.zip
merge development
Diffstat (limited to 'packages/testnet-faucets')
-rw-r--r--packages/testnet-faucets/src/ts/constants.ts5
-rw-r--r--packages/testnet-faucets/src/ts/handler.ts11
-rw-r--r--packages/testnet-faucets/src/ts/parameter_transformer.ts5
-rw-r--r--packages/testnet-faucets/src/ts/server.ts6
4 files changed, 18 insertions, 9 deletions
diff --git a/packages/testnet-faucets/src/ts/constants.ts b/packages/testnet-faucets/src/ts/constants.ts
new file mode 100644
index 000000000..c6370e3f6
--- /dev/null
+++ b/packages/testnet-faucets/src/ts/constants.ts
@@ -0,0 +1,5 @@
+export const constants = {
+ SUCCESS_STATUS: 200,
+ SERVICE_UNAVAILABLE_STATUS: 503,
+ BAD_REQUEST_STATUS: 400,
+};
diff --git a/packages/testnet-faucets/src/ts/handler.ts b/packages/testnet-faucets/src/ts/handler.ts
index 3858b5339..d5f0dc2f9 100644
--- a/packages/testnet-faucets/src/ts/handler.ts
+++ b/packages/testnet-faucets/src/ts/handler.ts
@@ -15,6 +15,7 @@ import ProviderEngine = require('web3-provider-engine');
import RpcSubprovider = require('web3-provider-engine/subproviders/rpc');
import { configs } from './configs';
+import { constants } from './constants';
import { DispatchQueue } from './dispatch_queue';
import { dispenseAssetTasks } from './dispense_asset_tasks';
import { rpcUrls } from './rpc_urls';
@@ -80,7 +81,7 @@ export class Handler {
};
});
const payload = JSON.stringify(queueInfo);
- res.status(200).send(payload);
+ res.status(constants.SUCCESS_STATUS).send(payload);
}
public dispenseEther(req: express.Request, res: express.Response): void {
this._dispenseAsset(req, res, RequestedAssetType.ETH);
@@ -120,11 +121,11 @@ export class Handler {
}
const didAddToQueue = networkConfig.dispatchQueue.add(dispenserTask);
if (!didAddToQueue) {
- res.status(503).send('QUEUE_IS_FULL');
+ res.status(constants.SERVICE_UNAVAILABLE_STATUS).send('QUEUE_IS_FULL');
return;
}
logUtils.log(`Added ${recipient} to queue: ${requestedAssetType} networkId: ${networkId}`);
- res.status(200).end();
+ res.status(constants.SUCCESS_STATUS).end();
}
private async _dispenseOrderAsync(
req: express.Request,
@@ -133,7 +134,7 @@ export class Handler {
): Promise<void> {
const networkConfig = _.get(this._networkConfigByNetworkId, req.params.networkId);
if (_.isUndefined(networkConfig)) {
- res.status(400).send('UNSUPPORTED_NETWORK_ID');
+ res.status(constants.BAD_REQUEST_STATUS).send('UNSUPPORTED_NETWORK_ID');
return;
}
const zeroEx = networkConfig.zeroEx;
@@ -173,6 +174,6 @@ export class Handler {
const signedOrderHash = ZeroEx.getOrderHashHex(signedOrder);
const payload = JSON.stringify(signedOrder);
logUtils.log(`Dispensed signed order: ${payload}`);
- res.status(200).send(payload);
+ res.status(constants.SUCCESS_STATUS).send(payload);
}
}
diff --git a/packages/testnet-faucets/src/ts/parameter_transformer.ts b/packages/testnet-faucets/src/ts/parameter_transformer.ts
index 58bf154dc..b9929a0d9 100644
--- a/packages/testnet-faucets/src/ts/parameter_transformer.ts
+++ b/packages/testnet-faucets/src/ts/parameter_transformer.ts
@@ -3,6 +3,7 @@ import { NextFunction, Request, Response } from 'express';
import * as _ from 'lodash';
import { configs } from './configs';
+import { constants } from './constants';
import { rpcUrls } from './rpc_urls';
const DEFAULT_NETWORK_ID = 42; // kovan
@@ -11,7 +12,7 @@ export const parameterTransformer = {
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');
+ res.status(constants.BAD_REQUEST_STATUS).send('INVALID_RECIPIENT_ADDRESS');
return;
}
const lowerCaseRecipientAddress = recipientAddress.toLowerCase();
@@ -19,7 +20,7 @@ export const parameterTransformer = {
const networkId = _.get(req.query, 'networkId', DEFAULT_NETWORK_ID);
const rpcUrlIfExists = _.get(rpcUrls, networkId);
if (_.isUndefined(rpcUrlIfExists)) {
- res.status(400).send('UNSUPPORTED_NETWORK_ID');
+ res.status(constants.BAD_REQUEST_STATUS).send('UNSUPPORTED_NETWORK_ID');
return;
}
req.params.networkId = networkId;
diff --git a/packages/testnet-faucets/src/ts/server.ts b/packages/testnet-faucets/src/ts/server.ts
index 198a5fdc9..55c1d55d8 100644
--- a/packages/testnet-faucets/src/ts/server.ts
+++ b/packages/testnet-faucets/src/ts/server.ts
@@ -1,6 +1,7 @@
import * as bodyParser from 'body-parser';
import * as express from 'express';
+import { constants } from './constants';
import { errorReporter } from './error_reporter';
import { Handler } from './handler';
import { parameterTransformer } from './parameter_transformer';
@@ -18,7 +19,7 @@ app.use((req, res, next) => {
const handler = new Handler();
app.get('/ping', (req: express.Request, res: express.Response) => {
- res.status(200).send('pong');
+ res.status(constants.SUCCESS_STATUS).send('pong');
});
app.get('/info', handler.getQueueInfo.bind(handler));
app.get('/ether/:recipient', parameterTransformer.transform, handler.dispenseEther.bind(handler));
@@ -28,5 +29,6 @@ app.get('/order/zrx/:recipient', parameterTransformer.transform, handler.dispens
// Log to rollbar any errors unhandled by handlers
app.use(errorReporter.errorHandler());
-const port = process.env.PORT || 3000;
+const DEFAULT_PORT = 3000;
+const port = process.env.PORT || DEFAULT_PORT;
app.listen(port);