aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-01-25 09:11:14 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-01-25 09:11:14 +0800
commitd3aa4f2bc7f2341a98c4aa6018c0d2ede221a3ed (patch)
tree8871a646678749dbe21d21ef724ac83b778d5257
parentb08bd0f9ab8d5e556c0be3867eafa264b08e8e0e (diff)
downloaddexon-sol-tools-d3aa4f2bc7f2341a98c4aa6018c0d2ede221a3ed.tar
dexon-sol-tools-d3aa4f2bc7f2341a98c4aa6018c0d2ede221a3ed.tar.gz
dexon-sol-tools-d3aa4f2bc7f2341a98c4aa6018c0d2ede221a3ed.tar.bz2
dexon-sol-tools-d3aa4f2bc7f2341a98c4aa6018c0d2ede221a3ed.tar.lz
dexon-sol-tools-d3aa4f2bc7f2341a98c4aa6018c0d2ede221a3ed.tar.xz
dexon-sol-tools-d3aa4f2bc7f2341a98c4aa6018c0d2ede221a3ed.tar.zst
dexon-sol-tools-d3aa4f2bc7f2341a98c4aa6018c0d2ede221a3ed.zip
Respond to GH comments and add /info endpoint
-rw-r--r--packages/testnet-faucets/README.md35
-rw-r--r--packages/testnet-faucets/src/ts/handler.ts33
-rw-r--r--packages/testnet-faucets/src/ts/server.ts1
3 files changed, 64 insertions, 5 deletions
diff --git a/packages/testnet-faucets/README.md b/packages/testnet-faucets/README.md
index cd98b4a64..00352cc2a 100644
--- a/packages/testnet-faucets/README.md
+++ b/packages/testnet-faucets/README.md
@@ -53,6 +53,39 @@ yarn dev
### Endpoints
+`GET /ping`
+
+Returns `pong`
+
+`GET /info`
+
+Returns a JSON payload describing the state of the queues for each network. For example:
+
+```json
+{
+ "3":{
+ "ether":{
+ "full":false,
+ "size":4
+ },
+ "zrx":{
+ "full":false,
+ "size":6
+ }
+ },
+ "42":{
+ "ether":{
+ "full":false,
+ "size":8
+ },
+ "zrx":{
+ "full":false,
+ "size":20
+ }
+ }
+}
+```
+
`GET /ether/:recipient`
Where recipient is a hex encoded Ethereum address prefixed with `0x`.
@@ -63,7 +96,7 @@ Where recipient is a hex encoded Ethereum address prefixed with `0x`.
#### Parameters
-Both endpoints take a query parameter named `networkId` to specify the desired network where you would like to receive the ETH or ZRX. For example:
+The endpoints `/ether` and `/zrx` take a query parameter named `networkId` to specify the desired network where you would like to receive the ETH or ZRX. For example:
```bash
curl -i http://localhost:3000/ether/0x14e2F1F157E7DD4057D02817436D628A37120FD1\?networkId=3
diff --git a/packages/testnet-faucets/src/ts/handler.ts b/packages/testnet-faucets/src/ts/handler.ts
index 8c859be2e..bf5b3e81e 100644
--- a/packages/testnet-faucets/src/ts/handler.ts
+++ b/packages/testnet-faucets/src/ts/handler.ts
@@ -23,6 +23,11 @@ interface RequestQueueByNetworkId {
[networkId: string]: RequestQueue;
}
+enum QueueType {
+ ETH = 'ETH',
+ ZRX = 'ZRX',
+}
+
const DEFAULT_NETWORK_ID = 42; // kovan
export class Handler {
@@ -36,17 +41,37 @@ export class Handler {
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, 'ETH');
+ this._dispense(req, res, this._etherRequestQueueByNetworkId, QueueType.ETH);
}
public dispenseZRX(req: express.Request, res: express.Response) {
- this._dispense(req, res, this._zrxRequestQueueByNetworkId, 'ZRX');
+ this._dispense(req, res, this._zrxRequestQueueByNetworkId, QueueType.ZRX);
}
private _dispense(
req: express.Request,
res: express.Response,
requestQueueByNetworkId: RequestQueueByNetworkId,
- assetSymbol: string,
+ queueType: QueueType,
) {
const recipientAddress = req.params.recipient;
if (_.isUndefined(recipientAddress) || !this._isValidEthereumAddress(recipientAddress)) {
@@ -65,7 +90,7 @@ export class Handler {
res.status(503).send('QUEUE_IS_FULL');
return;
}
- utils.consoleLog(`Added ${lowerCaseRecipientAddress} to queue: ${assetSymbol} networkId: ${networkId}`);
+ utils.consoleLog(`Added ${lowerCaseRecipientAddress} to queue: ${queueType} networkId: ${networkId}`);
res.status(200).end();
}
// tslint:disable-next-line:prefer-function-over-method
diff --git a/packages/testnet-faucets/src/ts/server.ts b/packages/testnet-faucets/src/ts/server.ts
index 23642787d..26edfff5a 100644
--- a/packages/testnet-faucets/src/ts/server.ts
+++ b/packages/testnet-faucets/src/ts/server.ts
@@ -19,6 +19,7 @@ const handler = new Handler();
app.get('/ping', (req: express.Request, res: express.Response) => {
res.status(200).send('pong');
});
+app.get('/info', handler.getQueueInfo.bind(handler));
app.get('/ether/:recipient', handler.dispenseEther.bind(handler));
app.get('/zrx/:recipient', handler.dispenseZRX.bind(handler));