123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- import { forEachAsync } from '../../utils'
- import { DBClient } from '../../singletons'
- import { InitiaClient } from '../../InitiaClient'
- async function startCheck(concurrency) {
- const accountsRaw = await DBClient.instance.randomTask2.findMany({
- where: {
- finish: 0,
- },
- take: 1,
- orderBy: {
- id: 'asc',
- },
- })
- await forEachAsync(accountsRaw, concurrency, async (account, index) => {
- console.log(
- `${index}/${accountsRaw.length}: processing ${account.address},account id: ${account.id}`,
- )
- try {
- // await faucetAccount(account.address)
- const notDone = []
- if (account.task1 === 0) {
- notDone.push(1)
- }
- if (account.task2 === 0) {
- notDone.push(2)
- }
- if (account.task3 === 0) {
- notDone.push(3)
- }
- if (account.task4 === 0) {
- // notDone.push(4)
- }
- if (account.task5 === 0) {
- // notDone.push(5)
- }
- if (account.task6 === 0) {
- // notDone.push(6)
- }
- console.log(
- `${index}/${accountsRaw.length}: processing ${account.address} notDone`,
- notDone,
- )
- if (notDone.length === 0) {
- await DBClient.instance.randomTask2.update({
- where: { id: account.id },
- data: { finish: 1 },
- })
- return
- }
- const randomPick = notDone[Math.floor(Math.random() * notDone.length)]
- const client = new InitiaClient(account.mnemonic, true)
- // const gasGot = await client.gasGot()
- // if (!gasGot) {
- // // await DBClient.instance.randomTask2.update({
- // // where: { id: account.id },
- // // data: { finish: -1 },
- // // })
- // return
- // }
- if (randomPick === 1) {
- console.log(
- `${index}/${accountsRaw.length}: processing ${account.address},task1`,
- )
- const bool = await client.week5Task1()
- console.log(
- `${index}/${accountsRaw.length}: processing ${account.address},task1`,
- bool,
- )
- if (bool === `done`) {
- await DBClient.instance.randomTask2.update({
- where: { id: account.id },
- data: { task1: 1 },
- })
- }
- } else if (randomPick === 2) {
- console.log(
- `${index}/${accountsRaw.length}: processing ${account.address},task2`,
- )
- const bool = await client.week5Task2()
- console.log(
- `${index}/${accountsRaw.length}: processing ${account.address},task2`,
- bool,
- )
- if (bool === `done`) {
- await DBClient.instance.randomTask2.update({
- where: { id: account.id },
- data: { task2: 1 },
- })
- }
- } else if (randomPick === 3) {
- console.log(
- `${index}/${accountsRaw.length}: processing ${account.address},task3`,
- )
- const bool = await client.week5Task3()
- console.log(
- `${index}/${accountsRaw.length}: processing ${account.address},task3`,
- bool,
- )
- if (bool === `done`) {
- await DBClient.instance.randomTask2.update({
- where: { id: account.id },
- data: { task3: 1 },
- })
- }
- } else if (randomPick === 4) {
- console.log(
- `${index}/${accountsRaw.length}: processing ${account.address},task4`,
- )
- const bool = await client.week5Task4()
- console.log(
- `${index}/${accountsRaw.length}: processing ${account.address},task4`,
- bool,
- )
- if (bool === `done`) {
- await DBClient.instance.randomTask2.update({
- where: { id: account.id },
- data: { task4: 1 },
- })
- }
- } else if (randomPick === 5) {
- console.log(
- `${index}/${accountsRaw.length}: processing ${account.address},task5`,
- )
- const bool = await client.week5Task5()
- console.log(
- `${index}/${accountsRaw.length}: processing ${account.address},task5`,
- bool,
- )
- if (bool === `done`) {
- await DBClient.instance.randomTask2.update({
- where: { id: account.id },
- data: { task5: 1 },
- })
- }
- } else if (randomPick === 6) {
- console.log(
- `${index}/${accountsRaw.length}: processing ${account.address},task6`,
- )
- const bool = await client.week5Task6()
- console.log(
- `${index}/${accountsRaw.length}: processing ${account.address},task6`,
- bool,
- )
- if (bool === `done`) {
- await DBClient.instance.randomTask2.update({
- where: { id: account.id },
- data: { task6: 1 },
- })
- }
- }
- } catch (e) {
- console.log(e.message)
- // process.exit(0)
- return
- // await DBClient.instance.account.update({
- // where: { id: account.id },
- // data: { status: Status.MayQueued, message: e.message },
- // })
- }
- })
- }
- startCheck(1)
|