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)