aboutsummaryrefslogtreecommitdiffstats
path: root/packages/testnet-faucets
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-05-14 17:30:51 +0800
committerFabio Berger <me@fabioberger.com>2018-05-14 17:30:51 +0800
commitc94d1b22754c1d1bf10f0dd2b9c13eea91e17cb6 (patch)
tree986b220cf80aab8d8e8ef6c4cef8c08be6eeab10 /packages/testnet-faucets
parent7d60356facce60c1d4d80c703bfc565c5c47e73b (diff)
parent58fa35641d3016ef106496c929e48febcf827dc6 (diff)
downloaddexon-sol-tools-c94d1b22754c1d1bf10f0dd2b9c13eea91e17cb6.tar
dexon-sol-tools-c94d1b22754c1d1bf10f0dd2b9c13eea91e17cb6.tar.gz
dexon-sol-tools-c94d1b22754c1d1bf10f0dd2b9c13eea91e17cb6.tar.bz2
dexon-sol-tools-c94d1b22754c1d1bf10f0dd2b9c13eea91e17cb6.tar.lz
dexon-sol-tools-c94d1b22754c1d1bf10f0dd2b9c13eea91e17cb6.tar.xz
dexon-sol-tools-c94d1b22754c1d1bf10f0dd2b9c13eea91e17cb6.tar.zst
dexon-sol-tools-c94d1b22754c1d1bf10f0dd2b9c13eea91e17cb6.zip
Merge branch 'development' of github.com:0xProject/0x-monorepo into development
* 'development' of github.com:0xProject/0x-monorepo: Add missing type definitions
Diffstat (limited to 'packages/testnet-faucets')
-rw-r--r--packages/testnet-faucets/package.json1
-rw-r--r--packages/testnet-faucets/src/ts/dispatch_queue.ts4
-rw-r--r--packages/testnet-faucets/src/ts/dispense_asset_tasks.ts6
-rw-r--r--packages/testnet-faucets/src/ts/error_reporter.ts4
-rw-r--r--packages/testnet-faucets/src/ts/handler.ts29
-rw-r--r--packages/testnet-faucets/src/ts/parameter_transformer.ts2
-rw-r--r--packages/testnet-faucets/src/ts/server.ts4
7 files changed, 31 insertions, 19 deletions
diff --git a/packages/testnet-faucets/package.json b/packages/testnet-faucets/package.json
index 198c0b2f7..48fe77bf4 100644
--- a/packages/testnet-faucets/package.json
+++ b/packages/testnet-faucets/package.json
@@ -17,6 +17,7 @@
"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());