aboutsummaryrefslogtreecommitdiffstats
path: root/packages/kovan-faucets/src/ts/ether_request_queue.ts
blob: 1c4b19ab97d0d343f9475aae07c648c1064f8598 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { promisify } from '@0xproject/utils';
import * as _ from 'lodash';

import { configs } from './configs';
import { errorReporter } from './error_reporter';
import { RequestQueue } from './request_queue';
import { utils } from './utils';

const DISPENSE_AMOUNT_ETHER = 0.1;

export class EtherRequestQueue extends RequestQueue {
    protected async processNextRequestFireAndForgetAsync(recipientAddress: string) {
        utils.consoleLog(`Processing ETH ${recipientAddress}`);
        const sendTransactionAsync = promisify(this.web3.eth.sendTransaction);
        try {
            const txHash = await sendTransactionAsync({
                from: configs.DISPENSER_ADDRESS,
                to: recipientAddress,
                value: this.web3.toWei(DISPENSE_AMOUNT_ETHER, 'ether'),
            });
            utils.consoleLog(`Sent ${DISPENSE_AMOUNT_ETHER} ETH to ${recipientAddress} tx: ${txHash}`);
        } catch (err) {
            utils.consoleLog(`Unexpected err: ${err} - ${JSON.stringify(err)}`);
            await errorReporter.reportAsync(err);
        }
    }
}