diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2017-12-13 09:18:15 +0800 |
---|---|---|
committer | Brandon Millman <brandon.millman@gmail.com> | 2017-12-14 04:36:29 +0800 |
commit | 91f276d9254bba3d93fc821c4fadab2eb6fc1d65 (patch) | |
tree | 9c33a09f44f06d5f9b45da74e027012cf4dfbbb6 /packages/kovan-faucets | |
parent | 1e9f23ebba5e0729b64e757d6901205278871e9f (diff) | |
download | dexon-0x-contracts-91f276d9254bba3d93fc821c4fadab2eb6fc1d65.tar.gz dexon-0x-contracts-91f276d9254bba3d93fc821c4fadab2eb6fc1d65.tar.zst dexon-0x-contracts-91f276d9254bba3d93fc821c4fadab2eb6fc1d65.zip |
Cleanup kovan-faucet package
Diffstat (limited to 'packages/kovan-faucets')
-rw-r--r-- | packages/kovan-faucets/README.md | 10 | ||||
-rw-r--r-- | packages/kovan-faucets/package.json | 8 | ||||
-rw-r--r-- | packages/kovan-faucets/src/ts/configs.ts | 3 | ||||
-rw-r--r-- | packages/kovan-faucets/src/ts/ether_request_queue.ts | 2 | ||||
-rw-r--r-- | packages/kovan-faucets/src/ts/global.d.ts | 17 | ||||
-rw-r--r-- | packages/kovan-faucets/src/ts/handler.ts | 5 | ||||
-rw-r--r-- | packages/kovan-faucets/src/ts/id_management.ts | 11 | ||||
-rw-r--r-- | packages/kovan-faucets/src/ts/request_queue.ts | 4 | ||||
-rw-r--r-- | packages/kovan-faucets/src/ts/server.ts | 2 | ||||
-rw-r--r-- | packages/kovan-faucets/src/ts/zrx_request_queue.ts | 13 |
10 files changed, 36 insertions, 39 deletions
diff --git a/packages/kovan-faucets/README.md b/packages/kovan-faucets/README.md index b372c8b15..8903440e3 100644 --- a/packages/kovan-faucets/README.md +++ b/packages/kovan-faucets/README.md @@ -21,8 +21,11 @@ export FAUCET_ENVIRONMENT=development export DISPENSER_ADDRESS=0x5409ed021d9299bf6814279a6a1411a7e866a631 export DISPENSER_PRIVATE_KEY=f2f48ee19680706196e2e339e5da3491186e0c4c5030670656b0e0164837257d export FAUCET_ROLLBAR_ACCESS_KEY={GET_THIS_FROM_ROLLBAR_ACCOUNT_SETTINGS} +export INFURA_API_KEY={GET_THIS_FROM_INFURA} ``` +Infura API Key can be requested here: https://infura.io/register.html + 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`. ``` @@ -31,13 +34,14 @@ npm run dev ## Endpoints -```GET /rain/:recipient_address``` +```GET /ether/:recipient``` Where recipient_address is a hex encoded Ethereum address prefixed with `0x`. -```GET /queue``` +```GET /zrx/:recipient``` + +Where recipient_address is a hex encoded Ethereum address prefixed with `0x`. -Returns the status of the queue ```javascript { diff --git a/packages/kovan-faucets/package.json b/packages/kovan-faucets/package.json index b4fe84b86..378cd2613 100644 --- a/packages/kovan-faucets/package.json +++ b/packages/kovan-faucets/package.json @@ -1,6 +1,6 @@ { "private": true, - "name": "@0xproject/token-and-ether-faucet", + "name": "@0xproject/kovan_faucets", "version": "1.0.0", "description": "A faucet micro-service that dispenses test ERC20 tokens or Ether", "main": "server.js", @@ -8,16 +8,16 @@ "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", + "lint": "tslint --project . 'src/**/*.ts'", "clean": "shx rm -rf bin" }, "author": "Fabio Berger", "license": "Apache-2.0", "dependencies": { + "@0xproject/utils": "^0.1.0", "0x.js": "~0.27.2", "bignumber.js": "~4.1.0", "body-parser": "^1.17.1", - "es6-promisify": "^5.0.0", "ethereumjs-tx": "^1.3.3", "express": "^4.15.2", "lodash": "^4.17.4", @@ -34,7 +34,7 @@ "gulp": "^3.9.1", "nodemon": "^1.11.0", "shx": "^0.2.2", - "source-map-loader": "^0.2.0", + "source-map-loader": "^0.1.6", "tslint": "5.8.0", "typescript": "~2.6.1", "web3-typescript-typings": "^0.7.2", diff --git a/packages/kovan-faucets/src/ts/configs.ts b/packages/kovan-faucets/src/ts/configs.ts index 2b130446d..f432ba66f 100644 --- a/packages/kovan-faucets/src/ts/configs.ts +++ b/packages/kovan-faucets/src/ts/configs.ts @@ -5,6 +5,7 @@ export const configs = { ROLLBAR_ACCESS_KEY: process.env.FAUCET_ROLLBAR_ACCESS_KEY, RPC_URL: process.env.FAUCET_ENVIRONMENT === 'development' ? 'http://127.0.0.1:8545' : - 'https://kovan.infura.io/T5WSC8cautR4KXyYgsRs', + `https://kovan.infura.io/${process.env.INFURA_API_KEY}`, ZRX_TOKEN_ADDRESS: '0x6ff6c0ff1d68b964901f986d4c9fa3ac68346570', + KOVAN_NETWORK_ID: 42, }; diff --git a/packages/kovan-faucets/src/ts/ether_request_queue.ts b/packages/kovan-faucets/src/ts/ether_request_queue.ts index b1648ca28..0750e6170 100644 --- a/packages/kovan-faucets/src/ts/ether_request_queue.ts +++ b/packages/kovan-faucets/src/ts/ether_request_queue.ts @@ -1,4 +1,4 @@ -import promisify = require('es6-promisify'); +import {promisify} from '@0xproject/utils'; import * as _ from 'lodash'; import {configs} from './configs'; diff --git a/packages/kovan-faucets/src/ts/global.d.ts b/packages/kovan-faucets/src/ts/global.d.ts index cdfa67378..c698207dd 100644 --- a/packages/kovan-faucets/src/ts/global.d.ts +++ b/packages/kovan-faucets/src/ts/global.d.ts @@ -1,7 +1,4 @@ -declare module 'elliptic'; declare module 'rollbar'; -declare module 'ethereumjs-tx'; -declare module 'es6-promisify'; declare module 'web3-provider-engine'; declare module 'web3-provider-engine/subproviders/rpc'; declare module 'web3-provider-engine/subproviders/nonce-tracker'; @@ -13,3 +10,17 @@ declare module '*.json' { 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; +} diff --git a/packages/kovan-faucets/src/ts/handler.ts b/packages/kovan-faucets/src/ts/handler.ts index f3c6ba1f0..d76a29514 100644 --- a/packages/kovan-faucets/src/ts/handler.ts +++ b/packages/kovan-faucets/src/ts/handler.ts @@ -12,11 +12,6 @@ import {idManagement} from './id_management'; import {utils} from './utils'; import {ZRXRequestQueue} from './zrx_request_queue'; -// HACK: web3 leaks XMLHttpRequest into the global scope and causes requests to hang -// because they are using the wrong XHR package. -// Issue: https://github.com/trufflesuite/truffle-contract/issues/14 -delete (global as any).XMLHttpRequest; - export class Handler { private etherRequestQueue: EtherRequestQueue; private zrxRequestQueue: ZRXRequestQueue; diff --git a/packages/kovan-faucets/src/ts/id_management.ts b/packages/kovan-faucets/src/ts/id_management.ts index 2090ce58a..89d6f6fd1 100644 --- a/packages/kovan-faucets/src/ts/id_management.ts +++ b/packages/kovan-faucets/src/ts/id_management.ts @@ -1,14 +1,13 @@ -import * as EthereumTx from 'ethereumjs-tx'; +import EthereumTx = require('ethereumjs-tx'); import {configs} from './configs'; +import {utils} from './utils'; type Callback = (err: Error, accounts: any) => void; export const idManagement = { getAccounts(callback: Callback) { - /* tslint:disable */ - console.log('configs.DISPENSER_ADDRESS', configs.DISPENSER_ADDRESS); - /* tslint:enable */ + utils.consoleLog(`configs.DISPENSER_ADDRESS: ${configs.DISPENSER_ADDRESS}`); callback(null, [ configs.DISPENSER_ADDRESS, ]); @@ -17,9 +16,7 @@ export const idManagement = { callback(null, true); }, signTransaction(txData: object, callback: Callback) { - /* tslint:disable */ - let tx = new EthereumTx(txData); - /* tslint:enable */ + const tx = new EthereumTx(txData); const privateKeyBuffer = new Buffer(configs.DISPENSER_PRIVATE_KEY, 'hex'); tx.sign(privateKeyBuffer); const rawTx = `0x${tx.serialize().toString('hex')}`; diff --git a/packages/kovan-faucets/src/ts/request_queue.ts b/packages/kovan-faucets/src/ts/request_queue.ts index 98e8e381a..2a3fd4d03 100644 --- a/packages/kovan-faucets/src/ts/request_queue.ts +++ b/packages/kovan-faucets/src/ts/request_queue.ts @@ -1,10 +1,6 @@ import * as _ from 'lodash'; import * as timers from 'timers'; import * as Web3 from 'web3'; -// HACK: web3 leaks XMLHttpRequest into the global scope and causes requests to hang -// because they are using the wrong XHR package. -// Issue: https://github.com/trufflesuite/truffle-contract/issues/14 -delete (global as any).XMLHttpRequest; const MAX_QUEUE_SIZE = 500; const DEFAULT_QUEUE_INTERVAL_MS = 1000; diff --git a/packages/kovan-faucets/src/ts/server.ts b/packages/kovan-faucets/src/ts/server.ts index d60363ceb..fbb9caf1e 100644 --- a/packages/kovan-faucets/src/ts/server.ts +++ b/packages/kovan-faucets/src/ts/server.ts @@ -17,10 +17,8 @@ app.use((req, res, next) => { const handler = new Handler(); app.get('/ping', (req: express.Request, res: express.Response) => { res.status(200).send('pong'); }); -app.get('/rain/:recipient', handler.dispenseEther.bind(handler)); // Deprecated gracefully app.get('/ether/:recipient', handler.dispenseEther.bind(handler)); app.get('/zrx/:recipient', handler.dispenseZRX.bind(handler)); -app.get('/queue', handler.getQueueInfo.bind(handler)); // Deprecated gracefully // Log to rollbar any errors unhandled by handlers app.use(errorReporter.errorHandler()); diff --git a/packages/kovan-faucets/src/ts/zrx_request_queue.ts b/packages/kovan-faucets/src/ts/zrx_request_queue.ts index 8971f94f0..72500789c 100644 --- a/packages/kovan-faucets/src/ts/zrx_request_queue.ts +++ b/packages/kovan-faucets/src/ts/zrx_request_queue.ts @@ -1,6 +1,6 @@ import {ZeroEx} from '0x.js'; +import {promisify} from '@0xproject/utils'; import BigNumber from 'bignumber.js'; -import promisify = require('es6-promisify'); import * as _ from 'lodash'; import * as Web3 from 'web3'; @@ -8,24 +8,19 @@ import {configs} from './configs'; import {errorReporter} from './error_reporter'; import {RequestQueue} from './request_queue'; import {utils} from './utils'; -// HACK: web3 leaks XMLHttpRequest into the global scope and causes requests to hang -// because they are using the wrong XHR package. -// Issue: https://github.com/trufflesuite/truffle-contract/issues/14 -delete (global as any).XMLHttpRequest; const DISPENSE_AMOUNT_ZRX = new BigNumber(0.1); const QUEUE_INTERVAL_MS = 5000; -const KOVAN_NETWORK_ID = 42; export class ZRXRequestQueue extends RequestQueue { private zeroEx: ZeroEx; constructor(web3: Web3) { super(web3); this.queueIntervalMs = QUEUE_INTERVAL_MS; - const config = { - networkId: KOVAN_NETWORK_ID, + const zeroExConfig = { + networkId: configs.KOVAN_NETWORK_ID, }; - this.zeroEx = new ZeroEx(web3.currentProvider, config); + this.zeroEx = new ZeroEx(web3.currentProvider, zeroExConfig); } protected async processNextRequestFireAndForgetAsync(recipientAddress: string) { utils.consoleLog(`Processing ZRX ${recipientAddress}`); |