randomTask.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { DBClient } from '../singletons'
  2. import { Status } from '../models/Status'
  3. import { forEachAsync } from '../utils'
  4. import { InitiaClient } from '../InitiaClient'
  5. async function startCheck(concurrency) {
  6. const accountsRaw = await DBClient.instance.randomTask.findMany({
  7. where: {
  8. finish: 0,
  9. },
  10. take: 10000,
  11. })
  12. await forEachAsync(accountsRaw, concurrency, async (account, index) => {
  13. console.log(`${index}/${accountsRaw.length}: processing ${account.address}`)
  14. console.log(account.id)
  15. try {
  16. // await faucetAccount(account.address)
  17. const notDone = []
  18. if (account.task2 === 0) {
  19. notDone.push(2)
  20. }
  21. if (account.task3 === 0) {
  22. notDone.push(3)
  23. }
  24. if (account.task4 === 0) {
  25. notDone.push(4)
  26. }
  27. if (account.task3 === 1 && account.task5 === 0) {
  28. notDone.push(5)
  29. }
  30. if ((account.task5 === 1 || account.task4 === 1) && account.task6 === 0) {
  31. notDone.push(6)
  32. }
  33. console.log(`notDone`, notDone)
  34. if (notDone.length === 0) {
  35. await DBClient.instance.randomTask.update({
  36. where: { id: account.id },
  37. data: { finish: 1 },
  38. })
  39. }
  40. const randomPick = notDone[Math.floor(Math.random() * notDone.length)]
  41. const client = new InitiaClient(account.mnemonic, true)
  42. if (randomPick === 2) {
  43. console.log(`task2`)
  44. const bool = await client.nameRegister()
  45. console.log(bool)
  46. if (bool == `done`) {
  47. await DBClient.instance.randomTask.update({
  48. where: { id: account.id },
  49. data: { task2: 1 },
  50. })
  51. }
  52. } else if (randomPick === 3) {
  53. console.log(`task3`)
  54. const bool = await client.swapScript()
  55. console.log(bool)
  56. if (bool == `done`) {
  57. await DBClient.instance.randomTask.update({
  58. where: { id: account.id },
  59. data: { task3: 1 },
  60. })
  61. }
  62. } else if (randomPick === 4) {
  63. console.log(`task4`)
  64. const bool = await client.stakeInit()
  65. console.log(bool)
  66. if (bool) {
  67. await DBClient.instance.randomTask.update({
  68. where: { id: account.id },
  69. data: { task4: 1 },
  70. })
  71. }
  72. } else if (randomPick === 5) {
  73. console.log(`task5`)
  74. const bool = await client.stakeSingle()
  75. console.log(bool)
  76. if (bool) {
  77. await DBClient.instance.randomTask.update({
  78. where: { id: account.id },
  79. data: { task5: 1 },
  80. })
  81. }
  82. } else if (randomPick === 6) {
  83. console.log(`task6`)
  84. const bool = await client.claimReward()
  85. console.log(bool)
  86. if (bool) {
  87. await DBClient.instance.randomTask.update({
  88. where: { id: account.id },
  89. data: { task6: 1 },
  90. })
  91. }
  92. }
  93. } catch (e) {
  94. console.log(e)
  95. // await DBClient.instance.account.update({
  96. // where: { id: account.id },
  97. // data: { status: Status.MayQueued, message: e.message },
  98. // })
  99. }
  100. })
  101. }
  102. startCheck(50)