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: 10000, }) await forEachAsync(accountsRaw, concurrency, async (account, index) => { console.log(`${index}/${accountsRaw.length}: processing ${account.address}`) console.log(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(`notDone`, notDone) if (notDone.length === 0) { await DBClient.instance.randomTask2.update({ where: { id: account.id }, data: { finish: 1 }, }) } const randomPick = notDone[Math.floor(Math.random() * notDone.length)] const client = new InitiaClient(account.mnemonic, true) if (randomPick === 2) { console.log(`task2`) const bool = await client.week2Task2(account.toAddress) console.log(bool) if (bool == `done`) { await DBClient.instance.randomTask2.update({ where: { id: account.id }, data: { task2: 1 }, }) } } else if (randomPick === 3) { console.log(`task3`) await client.drawFood() const bool = await client.feedJennie() console.log(bool) if (bool == `done`) { await DBClient.instance.randomTask2.update({ where: { id: account.id }, data: { task3: 1 }, }) } } else if (randomPick === 4) { console.log(`task4`) const bool = await client.stakeSingle() if (bool == `done`) { await DBClient.instance.randomTask2.update({ where: { id: account.id }, data: { task4: 1 }, }) } } else if (randomPick === 5) { console.log(`task5`) const bool = await client.stakeTiaSingle() console.log(bool) if (bool == `done`) { await DBClient.instance.randomTask2.update({ where: { id: account.id }, data: { task5: 1 }, }) } } else if (randomPick === 6) { console.log(`task6`) const bool = await client.stakeEthSingle() if (bool == `done`) { await DBClient.instance.randomTask2.update({ where: { id: account.id }, data: { task6: 1 }, }) } } else if (randomPick === 1) { console.log(`task6`) const bool = await client.claimableXp() if (bool == `done`) { await DBClient.instance.randomTask2.update({ where: { id: account.id }, data: { task1: 1 }, }) } } } catch (e) { console.log(e.message) return // await DBClient.instance.account.update({ // where: { id: account.id }, // data: { status: Status.MayQueued, message: e.message }, // }) } }) } startCheck(100)