1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import { getAxiosClient } from '../utils'
- import { DBClient } from '../singletons'
- import { Status } from '../models/Status'
- import polly from 'polly-js'
- import { forEachAsync } from 'useless-helpers'
- async function faucetTuc(address: string) {
- await polly()
- .waitAndRetry(3)
- .executeForPromise(async () => {
- const client = getAxiosClient(true)
- const res = await client.post(
- 'https://birdee-faucet.testnet.mesoops.net/',
- {
- address: address,
- coins: ['10000000utuc'],
- },
- )
- if (res.data.error) {
- throw new Error(res.data.error)
- }
- })
- }
- async function startFaucet(concurrency: number) {
- const accounts = await DBClient.instance.faucet.findMany()
- await forEachAsync(accounts, concurrency, async account => {
- try {
- await faucetTuc(account.address)
- await DBClient.instance.faucet.update({
- where: { id: account.id },
- data: { tucStatus: Status.Fauceted },
- })
- } catch (e) {
- console.log(e)
- await DBClient.instance.faucet.update({
- where: { id: account.id },
- data: { tucStatus: Status.FaucetFailed },
- })
- }
- })
- }
- await startFaucet(5)
|