randomWeek3.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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: 1,
  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(
  40. `${index}/${accountsRaw.length}: processing ${account.address} notDone`,
  41. notDone,
  42. )
  43. if (notDone.length === 0) {
  44. await DBClient.instance.randomTask2.update({
  45. where: { id: account.id },
  46. data: { finish: 1 },
  47. })
  48. return
  49. }
  50. const randomPick = notDone[Math.floor(Math.random() * notDone.length)]
  51. const client = new InitiaClient(account.mnemonic, true)
  52. // const gasGot = await client.gasGot()
  53. // if (!gasGot) {
  54. // // await DBClient.instance.randomTask2.update({
  55. // // where: { id: account.id },
  56. // // data: { finish: -1 },
  57. // // })
  58. // return
  59. // }
  60. if (randomPick === 1) {
  61. console.log(
  62. `${index}/${accountsRaw.length}: processing ${account.address},task1`,
  63. )
  64. const bool = await client.week5Task1()
  65. console.log(
  66. `${index}/${accountsRaw.length}: processing ${account.address},task1`,
  67. bool,
  68. )
  69. if (bool === `done`) {
  70. await DBClient.instance.randomTask2.update({
  71. where: { id: account.id },
  72. data: { task1: 1 },
  73. })
  74. }
  75. } else if (randomPick === 2) {
  76. console.log(
  77. `${index}/${accountsRaw.length}: processing ${account.address},task2`,
  78. )
  79. const bool = await client.week5Task2()
  80. console.log(
  81. `${index}/${accountsRaw.length}: processing ${account.address},task2`,
  82. bool,
  83. )
  84. if (bool === `done`) {
  85. await DBClient.instance.randomTask2.update({
  86. where: { id: account.id },
  87. data: { task2: 1 },
  88. })
  89. }
  90. } else if (randomPick === 3) {
  91. console.log(
  92. `${index}/${accountsRaw.length}: processing ${account.address},task3`,
  93. )
  94. const bool = await client.week5Task3()
  95. console.log(
  96. `${index}/${accountsRaw.length}: processing ${account.address},task3`,
  97. bool,
  98. )
  99. if (bool === `done`) {
  100. await DBClient.instance.randomTask2.update({
  101. where: { id: account.id },
  102. data: { task3: 1 },
  103. })
  104. }
  105. } else if (randomPick === 4) {
  106. console.log(
  107. `${index}/${accountsRaw.length}: processing ${account.address},task4`,
  108. )
  109. const bool = await client.week5Task4()
  110. console.log(
  111. `${index}/${accountsRaw.length}: processing ${account.address},task4`,
  112. bool,
  113. )
  114. if (bool === `done`) {
  115. await DBClient.instance.randomTask2.update({
  116. where: { id: account.id },
  117. data: { task4: 1 },
  118. })
  119. }
  120. } else if (randomPick === 5) {
  121. console.log(
  122. `${index}/${accountsRaw.length}: processing ${account.address},task5`,
  123. )
  124. const bool = await client.week5Task5()
  125. console.log(
  126. `${index}/${accountsRaw.length}: processing ${account.address},task5`,
  127. bool,
  128. )
  129. if (bool === `done`) {
  130. await DBClient.instance.randomTask2.update({
  131. where: { id: account.id },
  132. data: { task5: 1 },
  133. })
  134. }
  135. } else if (randomPick === 6) {
  136. console.log(
  137. `${index}/${accountsRaw.length}: processing ${account.address},task6`,
  138. )
  139. const bool = await client.week5Task6()
  140. console.log(
  141. `${index}/${accountsRaw.length}: processing ${account.address},task6`,
  142. bool,
  143. )
  144. if (bool === `done`) {
  145. await DBClient.instance.randomTask2.update({
  146. where: { id: account.id },
  147. data: { task6: 1 },
  148. })
  149. }
  150. }
  151. } catch (e) {
  152. console.log(e.message)
  153. // process.exit(0)
  154. return
  155. // await DBClient.instance.account.update({
  156. // where: { id: account.id },
  157. // data: { status: Status.MayQueued, message: e.message },
  158. // })
  159. }
  160. })
  161. }
  162. startCheck(1)