finalTask.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { DBClient } from '../singletons'
  2. import { forEachAsync } from '../utils'
  3. import { InitiaClient } from '../InitiaClient'
  4. async function startCheck(concurrency) {
  5. const accountsRaw = await DBClient.instance.account.findMany({
  6. where: {
  7. status: -4,
  8. },
  9. orderBy: {
  10. lastRun: 'desc',
  11. },
  12. take: 1000,
  13. })
  14. await forEachAsync(accountsRaw, concurrency, async (account, index) => {
  15. console.log(`${index}/${accountsRaw.length}: processing ${account.address}`)
  16. try {
  17. // if (Number(account.message) < 1000000) {
  18. // return
  19. // }
  20. const client = new InitiaClient(account.mnemonic, true)
  21. const gasGot = await client.lcd.bank.balanceByDenom(
  22. account.address,
  23. `move/944f8dd8dc49f96c25fea9849f16436dcfa6d564eec802f3ef7f8b3ea85368ff`,
  24. )
  25. if (Number(gasGot.amount) < 300000) {
  26. await DBClient.instance.account.update({
  27. where: { id: account.id },
  28. data: { status: -3 },
  29. //可能领过还没到账的
  30. })
  31. return
  32. }
  33. // if (!gasGot) {
  34. // console.log(`gas got:`, gasGot)
  35. // await DBClient.instance.account.update({
  36. // where: { id: account.id },
  37. // data: { status: -2 },
  38. // //可能领过还没到账的
  39. // })
  40. // return
  41. // }
  42. const done = await client.feedJennie()
  43. if (done == `done`) {
  44. console.log(`done work`)
  45. await DBClient.instance.account.update({
  46. where: { id: account.id },
  47. data: { status: 3 },
  48. })
  49. }
  50. } catch (e) {
  51. console.log(
  52. `${index}/${accountsRaw.length}: processing ${account.address}: fail`,
  53. )
  54. console.log(
  55. `${index}/${accountsRaw.length}: processing ${account.address}: ${e.message}`,
  56. )
  57. }
  58. })
  59. }
  60. startCheck(20)