hel 1 ano atrás
pai
commit
c9a21ff48d
5 arquivos alterados com 122 adições e 58 exclusões
  1. 1 0
      package.json
  2. 41 42
      src/JennieModule.ts
  3. 27 10
      src/decodeFunction.ts
  4. 16 6
      src/onchain/finalTask.ts
  5. 37 0
      src/onchain/mintJennie.ts

+ 1 - 0
package.json

@@ -42,6 +42,7 @@
     "generateRandom": "yarn build && node build/src/onchain/generateRandom.js",
     "randomTask": "yarn build && node build/src/onchain/randomTask.js",
     "finalTask": "yarn build && node build/src/onchain/finalTask.js",
+    "mintJennie": "yarn build && node build/src/onchain/mintJennie.js",
     "decode": "yarn build && node build/src/decodeFunction.js"
   },
   "license": "Apache-2.0",

+ 41 - 42
src/JennieModule.ts

@@ -40,10 +40,11 @@ export abstract class JennieModule extends BaseClient {
       [],
       [bcs.address().serialize(this.key.accAddress).toBase64()],
     )
+    console.log(mintProgress)
 
     // Check if 'jennie' is already minted
     if (mintProgress.is_minted) {
-      return
+      return `done`
     }
 
     // Initialize a flag to determine if all parts are minted
@@ -60,7 +61,7 @@ export abstract class JennieModule extends BaseClient {
 
     // If not all parts are minted, exit the function
     if (!allPartsMinted) {
-      return
+      return `undone`
     }
 
     // Prepare the minting message
@@ -74,56 +75,54 @@ export abstract class JennieModule extends BaseClient {
     )
 
     // Broadcast the minting message
-    await this.broadcast(msg)
+    return await this.broadcast(msg)
   }
-  async mintPartApprovedAll() {
+  // async mintPartApprovedAll() {
+  //   const axios = getAxiosClient(true)
+  //   const res = await axios.get(
+  //     `https://xp-api.initiation-1.initia.xyz/xp/mint_parts/${this.key.accAddress}`,
+  //   )
+  //   const data = res.data
+  //   console.log(data.length)
+  //   let undone = [1, 2, 3, 4, 5, 6]
+  //   for (const item of data) {
+  //     const task = Number(item.task_id) + 1
+  //     undone = undone.filter(value => value !== task)
+  //   }
+  //   return undone
+  // }
+  async mintPart() {
+    // 获取 'jennie' 的铸造进度
     const axios = getAxiosClient(true)
     const res = await axios.get(
       `https://xp-api.initiation-1.initia.xyz/xp/mint_parts/${this.key.accAddress}`,
     )
     const data = res.data
-    console.log(data)
-    const need = [1, 2, 3, 4, 5, 6]
-    let newUndone = []
+    console.log(data.length)
+    if (data.length !== 6) {
+      return `undone`
+    }
+    const msgs = []
     for (const item of data) {
-      const task = item.task_id + 1
-      newUndone = need.filter(value => value !== task)
+      const msg = new MsgExecute(
+        this.key.accAddress,
+        '0x9065fda28f52bb14ade545411f02e8e07a9cb4ba',
+        'jennie',
+        'mint_part_v2',
+        [],
+        [
+          bcs.u8().serialize(item.task_id).toBase64(),
+          bcs
+            .vector(bcs.u8())
+            .serialize(Buffer.from(item.signature, 'base64'))
+            .toBase64(),
+        ],
+      )
+      msgs.push(msg)
     }
-    console.log(newUndone)
-  }
-  async mintPart() {
-    // 获取 'jennie' 的铸造进度
-    const mintProgress: MintProgress = await this.lcd.move.viewFunction(
-      '0x9065fda28f52bb14ade545411f02e8e07a9cb4ba',
-      'jennie',
-      'get_jennie_mint_progress',
-      [],
-      [bcs.address().serialize(this.key.accAddress).toBase64()],
-    )
-
     // 初始化消息数组
-    const msgs: MsgExecute[] = []
-
-    // console.log(mintProgress.jennie_part_progresses)
-
-    // 遍历每个部件的进度
-    for (const item of mintProgress.jennie_part_progresses) {
-      // 如果部件已批准但未铸造,创建消息
-      if (item.is_approved && !item.is_minted) {
-        const msg = new MsgExecute(
-          this.key.accAddress,
-          '0x9065fda28f52bb14ade545411f02e8e07a9cb4ba',
-          'jennie',
-          'mint_part',
-          [],
-          [bcs.u8().serialize(item.task).toBase64()],
-        )
-        msgs.push(msg)
-      }
-    }
 
-    // 广播所有消息
-    await this.broadcast(msgs)
+    return await this.broadcast(msgs)
   }
   async claimable() {
     //https://xp-api.initiation-1.initia.xyz/xp/claimable/init1w6ftxlsv7y5putq955ymxh2kd0wru7nqshetka

+ 27 - 10
src/decodeFunction.ts

@@ -116,25 +116,42 @@ function parse5(): void {
   //   'AA==',
   // ]
 
-  const raw = ['gIQeAAAAAAA=', 'AXBdHgAAAAAA', 'BgAAAAAAAAA=']
+  const raw = [
+    'BQ==',
+    'QKroIsCES99i848oZJPjCeGMr11aDFUGU2Roat7L1LX8LqsTZL5TMJTv3saMfcvo3RjWMK1FtR+fzT715Z+bnh4=',
+  ]
+  const s = [
+    'AQ==',
+    'QCzDqo9I8xICLNbNuDICoH4yoxq5QNUeDW+Soq/WbAVxITr1fs+aJpiQuwo3w411O2EogH6qDmVqKSpAAluH2HY=',
+  ]
 
   const d0 = bcs
-    .u64() // type
-    .parse(Uint8Array.from(Buffer.from(raw[0], 'base64')))
+    .u8() // type
+    .parse(Uint8Array.from(Buffer.from(s[0], 'base64')))
 
   console.log(d0)
 
   const d1 = bcs
-    .option(bcs.u64()) // type
-    .parse(Uint8Array.from(Buffer.from(raw[1], 'base64')))
-
+    .vector(bcs.u8()) // type
+    .parse(Uint8Array.from(Buffer.from(s[1], 'base64')))
   console.log(d1)
 
-  const d2 = bcs
-    .u64() // type
-    .parse(Uint8Array.from(Buffer.from(raw[2], 'base64')))
+  const res = bcs
+    .vector(bcs.u8())
+    .serialize(
+      Buffer.from(
+        '3ViG4aV7ED54UmN/QBn2rwhze3muJwLbN+T6sC7uPpo2ev36VsFEZF7oOwj2/qC/6Z1XnP8uxhj8cePQs1D/gQ==',
+        'base64',
+      ),
+    )
 
-  console.log(d2)
+  console.log(res.toBase64())
+
+  // const d2 = bcs
+  //   .u8() // type
+  //   .parse(Uint8Array.from(Buffer.from(raw[2], 'base64')))
+  //
+  // console.log(d2)
   //
   // const d3 = bcs
   //   .string() // type

+ 16 - 6
src/onchain/finalTask.ts

@@ -6,19 +6,29 @@ import { InitiaClient } from '../InitiaClient'
 async function startCheck(concurrency) {
   const accountsRaw = await DBClient.instance.randomTask.findMany({
     where: {
-      id: 2002,
+      finish: 1,
     },
-    take: 1,
+    take: 100,
   })
   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 = []
       const client = new InitiaClient(account.mnemonic, true)
-      const unApprovedList = await client.mintPartApprovedAll()
-      console.log(unApprovedList)
+      const done = await client.mintPart()
+      if (done !== `undone`) {
+        await DBClient.instance.randomTask.update({
+          where: { id: account.id },
+          data: { finish: 2 },
+        })
+      } else {
+        await DBClient.instance.randomTask.update({
+          where: { id: account.id },
+          data: { finish: -2 },
+        })
+      }
+      // const unApprovedList = await client.mintJennie()
     } catch (e) {
       console.log(e)
       // await DBClient.instance.account.update({
@@ -29,4 +39,4 @@ async function startCheck(concurrency) {
   })
 }
 
-startCheck(1)
+startCheck(10)

+ 37 - 0
src/onchain/mintJennie.ts

@@ -0,0 +1,37 @@
+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: 2,
+    },
+    take: 100,
+  })
+  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 client = new InitiaClient(account.mnemonic, true)
+      const done = await client.mintJennie()
+      if (done == `done`) {
+        await DBClient.instance.randomTask.update({
+          where: { id: account.id },
+          data: { finish: 3 },
+        })
+      }
+      // const unApprovedList = await client.mintJennie()
+    } catch (e) {
+      console.log(e)
+      // await DBClient.instance.account.update({
+      //   where: { id: account.id },
+      //   data: { status: Status.MayQueued, message: e.message },
+      // })
+    }
+  })
+}
+
+startCheck(10)