From 2a3c5dae0bdc0ba959fe01ca7b0af5649884bcf0 Mon Sep 17 00:00:00 2001 From: CounterFire2023 <136581895+CounterFire2023@users.noreply.github.com> Date: Fri, 23 Aug 2024 14:48:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BB=91=E5=AE=9A=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=8C=20=E8=BF=90=E8=A1=8Caddress=E5=92=8Caccounti?= =?UTF-8?q?d=E4=B8=BA=E7=A9=BA=EF=BC=88=E5=88=A0=E9=99=A4=E7=BB=91?= =?UTF-8?q?=E5=AE=9A=E5=85=B3=E7=B3=BB=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/cec.controller.ts | 27 +++++++++++++++------------ src/services/chain.svr.ts | 18 ++++++++---------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/controllers/cec.controller.ts b/src/controllers/cec.controller.ts index f3472c3..654bd07 100644 --- a/src/controllers/cec.controller.ts +++ b/src/controllers/cec.controller.ts @@ -39,6 +39,8 @@ const queryCECClaimStatus = async (address: string) => { let claimed = 0n let unavailable = 0n const records = await CECRecordTotal.find({ address }) + //@ts-ignore + await updateClaimStatus({ address, token: CEC_ADDRESS, records}) const bindRecord = await BitgetBindInfo.findOne({ wallet: address }) let bit = 0n for (const record of records) { @@ -96,8 +98,6 @@ class CECController extends BaseController { let available = 0n let claimed = 0n const records = await CECRecord.find({ address }) - //@ts-ignore - await updateClaimStatus({ address, token: CEC_ADDRESS, records}) const now = Date.now() const stages = [] const lists = [] @@ -212,12 +212,19 @@ class CECController extends BaseController { @router('post /api/cec/bind_account') async bindAccount(req: any) { + await new SyncLocker().checkLock(req) + logger.db('bind_bitget_acc', req) const user = req.user const { accid, address } = req.body - if (!accid || !address) { - throw new ZError(11, 'accid is required') + if (CEC_CLAIM_STAGE !== 0) { + throw new ZError(14, 'bind parse ended') } - if (!ethers.utils.isAddress(address)) { + + if (accid && !address || !accid && address) { + throw new ZError(11, 'address and accid are required') + } + + if (address && !ethers.utils.isAddress(address)) { throw new ZError(12, 'address is invalid') } @@ -238,15 +245,11 @@ class CECController extends BaseController { const records = await CECRecordTotal.find({ address: wallet }) if (records.length === 0) { - throw new ZError(15, 'record not found') + throw new ZError(15, 'no claimable record found') } - let record = await BitgetBindInfo.findOne({ wallet }) - if (record) { - throw new ZError(17, 'already bind') - } - record = new BitgetBindInfo({ address, wallet, biggetAcc: accid }) - await record.save() + await BitgetBindInfo.insertOrUpdate({ wallet }, {address, biggetAcc: accid}) + return {} } } diff --git a/src/services/chain.svr.ts b/src/services/chain.svr.ts index f5167cc..a379412 100644 --- a/src/services/chain.svr.ts +++ b/src/services/chain.svr.ts @@ -1,5 +1,5 @@ import { Contract } from 'ethers' -import { CECRecordTotalClass, CECStatusEnum } from 'models/CECRecordTotal' +import { CECRecordTotalClass, CECStatusEnum, ClaimStatusEnum } from 'models/CECRecordTotal' import { CheckIn } from 'models/chain/CheckIn' import { NftHolder } from 'models/chain/NftHolder' import { NftStake } from 'models/chain/NftStake' @@ -177,17 +177,15 @@ export const updateClaimStatus = async ( if (!record) { return } + const bitTotal = BigInt(record.bit) for (let item of records) { - let bit = BigInt(item.bit * 2) - let bit1 = bit + 1n let changed = false - if (item.status == CECStatusEnum.NORMAL && (BigInt(record.bit) & 1n << bit) > 0n ) { - item.status = CECStatusEnum.STAGE1_CLAIMED - changed = true - } - if (item.firstRate < 100 && item.status != CECStatusEnum.STAGE2_CLAIMED && (BigInt(record.bit) & 1n << bit1) > 0n) { - item.status = CECStatusEnum.STAGE2_CLAIMED - changed = true + for ( let value of item.claimStatus.values()) { + let bit = BigInt(value.bit) + if (value.status == ClaimStatusEnum.NORMAL && (bitTotal & 1n << bit) > 0n ) { + value.status = ClaimStatusEnum.CLAIMED + changed = true + } } if (changed) { //@ts-ignore