Shawn Lu 1 year ago
parent
commit
e2e92bef81
3 changed files with 9 additions and 5 deletions
  1. 4 2
      src/faucet/captcha.ts
  2. 4 2
      src/faucet/faucet.ts
  3. 1 1
      src/test.ts

+ 4 - 2
src/faucet/captcha.ts

@@ -2,8 +2,10 @@ import axios, { AxiosInstance } from 'axios'
 import dotenv from 'dotenv'
 import polly from 'polly-js'
 import { solveChallenge, solveChallengeWorkers } from 'shawnlu96-altcha-lib'
+import * as os from 'node:os'
 dotenv.config()
-
+const cpus = os.cpus()
+console.log('current cores', cpus.length)
 const googlekey = '6LdLhtYpAAAAAOe1xmceNR-i6MTtzq7N6AYztoVI'
 const hCaptchaKey = '04d28d90-d5b9-4a90-94e5-a12c595bd4e2'
 const captchaApiKey = process.env.CAPTCHA_API_KEY
@@ -49,7 +51,7 @@ export async function getAltchaPayload(client: AxiosInstance) {
       // console.log(challenge)
       const solution = await solveChallengeWorkers(
         './build/src/faucet/worker.js',
-        8,
+        cpus.length,
         challenge.challenge,
         challenge.salt,
         challenge.max,

+ 4 - 2
src/faucet/faucet.ts

@@ -4,7 +4,7 @@ import { DBClient } from '../singletons'
 import { Status } from '../models/Status'
 
 export async function faucetAccount(address: string) {
-  const client = getAxiosClient(false)
+  const client = getAxiosClient(true)
   const altcha = await getAltchaPayload(client)
   const hCaptcha = await solveHCaptcha(address)
   try {
@@ -25,11 +25,13 @@ export async function faucetAccount(address: string) {
 }
 
 async function startFaucet(concurrency = 10) {
-  const accounts = await DBClient.instance.account.findMany({
+  const accountsRaw = await DBClient.instance.account.findMany({
     where: {
       status: Status.Inited,
     },
   })
+  const accounts = accountsRaw
+    // .filter(account => account.id)
   await forEachAsync(accounts, concurrency, async (account, index) => {
     console.log(`${index}/${accounts.length}: processing ${account.address}`)
     try {

+ 1 - 1
src/test.ts

@@ -33,7 +33,7 @@ async function createAccounts(count: number) {
 
 // await createAccounts(10000)
 // await faucetAccount('init1xj0ekwu5n3t4c8aj2xfxr9l94lwr0sssl4rkxy')
-await getAltchaPayload(getAxiosClient(false))
+await getAltchaPayload(getAxiosClient(true))
 // const client = new InitiaClient(
 //   'scheme address way popular shrug fall rail eyebrow buzz learn cross involve spatial rookie ostrich grocery chest ice glory security slogan summer also comfort',
 // )