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