faucetTuc.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { getAxiosClient } from '../utils'
  2. import { DBClient } from '../singletons'
  3. import polly from 'polly-js'
  4. import { forEachAsync } from 'useless-helpers'
  5. async function faucetTuc(address: string) {
  6. await polly()
  7. .waitAndRetry(3)
  8. .executeForPromise(async () => {
  9. const client = getAxiosClient(true)
  10. const res = await client.post(
  11. 'https://birdee-faucet.testnet.mesoops.net/',
  12. {
  13. address: address,
  14. coins: ['10000000utuc'],
  15. },
  16. )
  17. if (res.data.error) {
  18. throw new Error(res.data.error)
  19. }
  20. })
  21. }
  22. async function startFaucet(concurrency: number) {
  23. const accounts = await DBClient.instance.account.findMany({
  24. where: { status: 5 },
  25. // take: 500,
  26. })
  27. await forEachAsync(accounts, concurrency, async account => {
  28. try {
  29. await faucetTuc(account.address)
  30. await DBClient.instance.account.update({
  31. where: { id: account.id },
  32. data: { status: 6 },
  33. })
  34. } catch (e) {
  35. console.log(e)
  36. // await DBClient.instance.faucet.update({
  37. // where: { id: account.id },
  38. // data: { tucStatus: Status.FaucetFailed },
  39. // })
  40. }
  41. })
  42. }
  43. await startFaucet(20)