123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- import { DBClient } from '../singletons'
- import { Status } from '../models/Status'
- import { forEachAsync } from '../utils'
- import { InitiaClient } from '../InitiaClient'
- async function startCheck(concurrency) {
- const accountsRaw = await DBClient.instance.randomTask.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.task2 === 0) {
- notDone.push(2)
- }
- if (account.task3 === 0) {
- notDone.push(3)
- }
- if (account.task4 === 0) {
- notDone.push(4)
- }
- if (account.task3 === 1 && account.task5 === 0) {
- notDone.push(5)
- }
- if ((account.task5 === 1 || account.task4 === 1) && account.task6 === 0) {
- notDone.push(6)
- }
- console.log(`notDone`, notDone)
- if (notDone.length === 0) {
- await DBClient.instance.randomTask.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.nameRegister()
- console.log(bool)
- if (bool == `done`) {
- await DBClient.instance.randomTask.update({
- where: { id: account.id },
- data: { task2: 1 },
- })
- }
- } else if (randomPick === 3) {
- console.log(`task3`)
- const bool = await client.swapScript()
- console.log(bool)
- if (bool == `done`) {
- await DBClient.instance.randomTask.update({
- where: { id: account.id },
- data: { task3: 1 },
- })
- }
- } else if (randomPick === 4) {
- console.log(`task4`)
- const bool = await client.stakeInit()
- console.log(bool)
- if (bool) {
- await DBClient.instance.randomTask.update({
- where: { id: account.id },
- data: { task4: 1 },
- })
- }
- } else if (randomPick === 5) {
- console.log(`task5`)
- const bool = await client.stakeSingle()
- console.log(bool)
- if (bool) {
- await DBClient.instance.randomTask.update({
- where: { id: account.id },
- data: { task5: 1 },
- })
- }
- } else if (randomPick === 6) {
- console.log(`task6`)
- const bool = await client.claimReward()
- console.log(bool)
- if (bool) {
- await DBClient.instance.randomTask.update({
- where: { id: account.id },
- data: { task6: 1 },
- })
- }
- }
- } catch (e) {
- console.log(e)
- // await DBClient.instance.account.update({
- // where: { id: account.id },
- // data: { status: Status.MayQueued, message: e.message },
- // })
- }
- })
- }
- startCheck(50)
|