|
@@ -0,0 +1,49 @@
|
|
|
+import { MnemonicKey } from '@initia/initia.js'
|
|
|
+import { getAxiosClient } from '../utils'
|
|
|
+import { DBClient } from '../singletons'
|
|
|
+import { forEachAsync } from 'useless-helpers'
|
|
|
+
|
|
|
+async function faucetMilkyWay(mnemonic: string) {
|
|
|
+ const wallet = new MnemonicKey({ mnemonic: mnemonic })
|
|
|
+ const address = wallet.accAddress
|
|
|
+ const pub_key = JSON.parse(wallet.publicKey.toJSON()).key
|
|
|
+ const signatureBuffer = await wallet.sign(Buffer.from(address))
|
|
|
+ const signature = signatureBuffer.toString('base64')
|
|
|
+ const axiosClient = getAxiosClient(true)
|
|
|
+ const res = await axiosClient.post(
|
|
|
+ 'https://apis.milkyway.zone/faucet/milkyway',
|
|
|
+ {
|
|
|
+ address,
|
|
|
+ pub_key,
|
|
|
+ signature,
|
|
|
+ },
|
|
|
+ )
|
|
|
+ console.log(res.data)
|
|
|
+ // console.log(signatureBuffer.toString())
|
|
|
+}
|
|
|
+
|
|
|
+async function startFaucet(concurrency: number) {
|
|
|
+ const accounts = await DBClient.instance.randomTask2.findMany({
|
|
|
+ where: { task5: 0 },
|
|
|
+ })
|
|
|
+ await forEachAsync(accounts, concurrency, async account => {
|
|
|
+ try {
|
|
|
+ await faucetMilkyWay(account.mnemonic)
|
|
|
+ await DBClient.instance.randomTask2.update({
|
|
|
+ where: { id: account.id },
|
|
|
+ data: { task5: 1 },
|
|
|
+ })
|
|
|
+ } catch (e) {
|
|
|
+ console.log(e)
|
|
|
+ await DBClient.instance.randomTask2.update({
|
|
|
+ where: { id: account.id },
|
|
|
+ data: { task5: -1 },
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+//"bKL8sOZgmwSp9EBq+QempUqdNVPOwlPlKI5o1JiSn8EYMPPNQdNv5OJh4Z+xOC+GWNscJ8IihgUtb1mLTy03ag=="
|
|
|
+// decoded: 0x6ca2fcb0e6609b04a9f4406af907a6a54a9d3553cec253e5288e68d498929fc1
|
|
|
+// await startFaucet(20)
|
|
|
+
|