增加一个查询是否mint了活动nft的方法

This commit is contained in:
CounterFire2023 2023-06-26 16:39:49 +08:00
parent 569236a3aa
commit 475bbaf807
5 changed files with 18083 additions and 4 deletions

18049
src/abis/ClaimBoxFactory.json Normal file

File diff suppressed because one or more lines are too long

View File

@ -163,8 +163,8 @@ export class ApiServer {
let self = this
return new Promise(async (resolve, reject) => {
// await self.connectDB()
// self.initControllers()
// self.registerRouter()
self.initControllers()
self.registerRouter()
// self.setErrHandler()
// self.setFormatSend()
// self.initSchedules()

View File

@ -0,0 +1,23 @@
import { Contract } from 'web3-eth-contract'
import Web3 from 'web3'
import { Account } from 'web3-core'
const abi = require('abis/ClaimBoxFactory.json').abi
export class ActivityReactor {
private web3: Web3
private contract: Contract
private account: Account
constructor({ web3, address }: { web3: Web3; address: string }) {
this.web3 = web3
this.account = this.web3.eth.accounts.wallet[0]
this.contract = new this.web3.eth.Contract(abi, address, { from: this.account.address })
}
/**
* mint的数量
*/
async getMintableCount({ address, user }: { address?: string; user: string }) {
const contract = address ? new this.web3.eth.Contract(abi, address, { from: this.account.address }) : this.contract
return await contract.methods.claimHistory(user).call()
}
}

View File

@ -14,6 +14,7 @@ import assert from 'assert'
import { IPriceData } from 'structs/PriceData'
import { IChainData } from 'structs/ChainData'
import { PriceSvr } from 'service/price.service'
import { ActivityReactor } from './ActivityReactor'
@singleton
export class BlockChain {
@ -24,6 +25,7 @@ export class BlockChain {
public erc20Reactor: ERC20Reactor
public erc721Reactor: ERC721Reactor
public walletReactor: WalletReactor
public activityReactor: ActivityReactor
public distributorReactor: DistributorReactor
public confirmQueue: ConfirmQueue
public currentBlockNum: number = 0
@ -55,6 +57,10 @@ export class BlockChain {
web3: this.web3,
address: process.env.CHAIN_DISTRIBUTOR_ADDRESS,
})
this.activityReactor = new ActivityReactor({
web3: this.web3,
address: process.env.CHAIN_CLAIM_ADDRESS,
})
}
public get currentAccount() {

View File

@ -43,13 +43,14 @@ class ChainController extends BaseController {
@role('anon')
@router('post /chain/query_info')
@router('get /chain/query_info')
async queryUserInfo(req, res) {
let { address } = req.params
if (!address) {
throw new ZError(10, 'address is required')
}
let info = await new BlockChain().distributorReactor.getMintableCount({ user: address })
return { count: info }
let info = await new BlockChain().activityReactor.getMintableCount({ user: address })
return { id: parseInt(info) }
}
}
export default ChainController