增加一个查询是否mint了活动nft的方法
This commit is contained in:
parent
569236a3aa
commit
475bbaf807
18049
src/abis/ClaimBoxFactory.json
Normal file
18049
src/abis/ClaimBoxFactory.json
Normal file
File diff suppressed because one or more lines are too long
@ -163,8 +163,8 @@ export class ApiServer {
|
|||||||
let self = this
|
let self = this
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
// await self.connectDB()
|
// await self.connectDB()
|
||||||
// self.initControllers()
|
self.initControllers()
|
||||||
// self.registerRouter()
|
self.registerRouter()
|
||||||
// self.setErrHandler()
|
// self.setErrHandler()
|
||||||
// self.setFormatSend()
|
// self.setFormatSend()
|
||||||
// self.initSchedules()
|
// self.initSchedules()
|
||||||
|
23
src/chain/ActivityReactor.ts
Normal file
23
src/chain/ActivityReactor.ts
Normal 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()
|
||||||
|
}
|
||||||
|
}
|
@ -14,6 +14,7 @@ import assert from 'assert'
|
|||||||
import { IPriceData } from 'structs/PriceData'
|
import { IPriceData } from 'structs/PriceData'
|
||||||
import { IChainData } from 'structs/ChainData'
|
import { IChainData } from 'structs/ChainData'
|
||||||
import { PriceSvr } from 'service/price.service'
|
import { PriceSvr } from 'service/price.service'
|
||||||
|
import { ActivityReactor } from './ActivityReactor'
|
||||||
|
|
||||||
@singleton
|
@singleton
|
||||||
export class BlockChain {
|
export class BlockChain {
|
||||||
@ -24,6 +25,7 @@ export class BlockChain {
|
|||||||
public erc20Reactor: ERC20Reactor
|
public erc20Reactor: ERC20Reactor
|
||||||
public erc721Reactor: ERC721Reactor
|
public erc721Reactor: ERC721Reactor
|
||||||
public walletReactor: WalletReactor
|
public walletReactor: WalletReactor
|
||||||
|
public activityReactor: ActivityReactor
|
||||||
public distributorReactor: DistributorReactor
|
public distributorReactor: DistributorReactor
|
||||||
public confirmQueue: ConfirmQueue
|
public confirmQueue: ConfirmQueue
|
||||||
public currentBlockNum: number = 0
|
public currentBlockNum: number = 0
|
||||||
@ -55,6 +57,10 @@ export class BlockChain {
|
|||||||
web3: this.web3,
|
web3: this.web3,
|
||||||
address: process.env.CHAIN_DISTRIBUTOR_ADDRESS,
|
address: process.env.CHAIN_DISTRIBUTOR_ADDRESS,
|
||||||
})
|
})
|
||||||
|
this.activityReactor = new ActivityReactor({
|
||||||
|
web3: this.web3,
|
||||||
|
address: process.env.CHAIN_CLAIM_ADDRESS,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public get currentAccount() {
|
public get currentAccount() {
|
||||||
|
@ -43,13 +43,14 @@ class ChainController extends BaseController {
|
|||||||
|
|
||||||
@role('anon')
|
@role('anon')
|
||||||
@router('post /chain/query_info')
|
@router('post /chain/query_info')
|
||||||
|
@router('get /chain/query_info')
|
||||||
async queryUserInfo(req, res) {
|
async queryUserInfo(req, res) {
|
||||||
let { address } = req.params
|
let { address } = req.params
|
||||||
if (!address) {
|
if (!address) {
|
||||||
throw new ZError(10, 'address is required')
|
throw new ZError(10, 'address is required')
|
||||||
}
|
}
|
||||||
let info = await new BlockChain().distributorReactor.getMintableCount({ user: address })
|
let info = await new BlockChain().activityReactor.getMintableCount({ user: address })
|
||||||
return { count: info }
|
return { id: parseInt(info) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export default ChainController
|
export default ChainController
|
||||||
|
Loading…
x
Reference in New Issue
Block a user