randomWeek3.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import { forEachAsync } from '../../utils'
  2. import { DBClient } from '../../singletons'
  3. import { InitiaClient } from '../../InitiaClient'
  4. async function startCheck(concurrency) {
  5. const accountsRaw = await DBClient.instance.randomTask2.findMany({
  6. where: {
  7. finish: 0,
  8. },
  9. take: 10000,
  10. orderBy: {
  11. id: 'asc',
  12. },
  13. })
  14. await forEachAsync(accountsRaw, concurrency, async (account, index) => {
  15. console.log(
  16. `${index}/${accountsRaw.length}: processing ${account.address},account id: ${account.id}`,
  17. )
  18. try {
  19. // await faucetAccount(account.address)
  20. const notDone = []
  21. if (account.task1 === 0) {
  22. notDone.push(1)
  23. }
  24. if (account.task2 === 0) {
  25. notDone.push(2)
  26. }
  27. if (account.task3 === 0) {
  28. notDone.push(3)
  29. }
  30. if (account.task4 === 0) {
  31. notDone.push(4)
  32. }
  33. if (account.task5 === 0) {
  34. notDone.push(5)
  35. }
  36. if (account.task6 === 0) {
  37. notDone.push(6)
  38. }
  39. console.log(`notDone`, notDone)
  40. if (notDone.length === 0) {
  41. await DBClient.instance.randomTask2.update({
  42. where: { id: account.id },
  43. data: { finish: 1 },
  44. })
  45. return
  46. }
  47. const randomPick = notDone[Math.floor(Math.random() * notDone.length)]
  48. const client = new InitiaClient(account.mnemonic, true)
  49. const gasGot = await client.gasGot()
  50. if (!gasGot) {
  51. console.log()
  52. await DBClient.instance.randomTask2.update({
  53. where: { id: account.id },
  54. data: { finish: -1 },
  55. })
  56. return
  57. }
  58. if (randomPick === 1) {
  59. console.log(`task1`)
  60. const bool = await client.week5Task1()
  61. if (bool === `done`) {
  62. await DBClient.instance.randomTask2.update({
  63. where: { id: account.id },
  64. data: { task1: 1 },
  65. })
  66. }
  67. } else if (randomPick === 2) {
  68. console.log(`task2`)
  69. const bool = await client.week5Task2()
  70. if (bool === `done`) {
  71. await DBClient.instance.randomTask2.update({
  72. where: { id: account.id },
  73. data: { task2: 1 },
  74. })
  75. }
  76. } else if (randomPick === 3) {
  77. console.log(`task3`)
  78. const bool = await client.week5Task3()
  79. if (bool === `done`) {
  80. await DBClient.instance.randomTask2.update({
  81. where: { id: account.id },
  82. data: { task3: 1 },
  83. })
  84. }
  85. } else if (randomPick === 4) {
  86. console.log(`task4`)
  87. const bool = await client.week5Task4()
  88. if (bool === `done`) {
  89. await DBClient.instance.randomTask2.update({
  90. where: { id: account.id },
  91. data: { task4: 1 },
  92. })
  93. }
  94. } else if (randomPick === 5) {
  95. console.log(`task5`)
  96. const bool = await client.week5Task5()
  97. console.log(bool === `done`)
  98. if (bool === `done`) {
  99. await DBClient.instance.randomTask2.update({
  100. where: { id: account.id },
  101. data: { task5: 1 },
  102. })
  103. }
  104. } else if (randomPick === 6) {
  105. console.log(`task6`)
  106. const bool = await client.week5Task6()
  107. if (bool === `done`) {
  108. await DBClient.instance.randomTask2.update({
  109. where: { id: account.id },
  110. data: { task6: 1 },
  111. })
  112. }
  113. }
  114. } catch (e) {
  115. console.log(e.message)
  116. // process.exit(0)
  117. return
  118. // await DBClient.instance.account.update({
  119. // where: { id: account.id },
  120. // data: { status: Status.MayQueued, message: e.message },
  121. // })
  122. }
  123. })
  124. }
  125. startCheck(50)