增加发布空投名单的功能
This commit is contained in:
parent
97d44f2d31
commit
cf0fdbf0a3
17499
src/abis/NftDistributor.json
Normal file
17499
src/abis/NftDistributor.json
Normal file
File diff suppressed because one or more lines are too long
@ -8,6 +8,7 @@ import { ERC20Reactor } from './ERC20Reactor'
|
||||
import { ERC721Reactor } from './ERC721Reactor'
|
||||
import { HttpRetryProvider } from './HttpRetryProvider'
|
||||
import { WalletReactor } from './WalletReactor'
|
||||
import { DistributorReactor } from './DistributorReactor'
|
||||
|
||||
@singleton
|
||||
export class BlockChain {
|
||||
@ -17,6 +18,7 @@ export class BlockChain {
|
||||
public erc20Reactor: ERC20Reactor
|
||||
public erc721Reactor: ERC721Reactor
|
||||
public walletReactor: WalletReactor
|
||||
public distributorReactor: DistributorReactor
|
||||
public confirmQueue: ConfirmQueue
|
||||
public currentBlockNum: number = 0
|
||||
|
||||
@ -39,6 +41,10 @@ export class BlockChain {
|
||||
web3: this.web3,
|
||||
address: process.env.CHAIN_WALLET_ADDRESS,
|
||||
})
|
||||
this.distributorReactor = new DistributorReactor({
|
||||
web3: this.web3,
|
||||
address: process.env.CHAIN_DISTRIBUTOR_ADDRESS,
|
||||
})
|
||||
}
|
||||
|
||||
public async getContractInstance(address: string, abi: any) {
|
||||
@ -83,6 +89,10 @@ export class BlockChain {
|
||||
reqData.tokenId = reqData.tokenId || reqData.tokenid
|
||||
abi = await this.erc721Reactor.transfer(reqData)
|
||||
break
|
||||
case TaskType.PUBLISH_AIRDROP_LIST:
|
||||
reqData.nftList = [reqData.tokenId || reqData.tokenid]
|
||||
abi = await this.distributorReactor.publishAirdropList(reqData)
|
||||
break
|
||||
}
|
||||
return abi
|
||||
}
|
||||
|
66
src/chain/DistributorReactor.ts
Normal file
66
src/chain/DistributorReactor.ts
Normal file
@ -0,0 +1,66 @@
|
||||
import { Contract } from 'web3-eth-contract'
|
||||
import Web3 from 'web3'
|
||||
import { Account } from 'web3-core'
|
||||
const abi = require('abis/NftDistributor.json').abi
|
||||
|
||||
export class DistributorReactor {
|
||||
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 })
|
||||
}
|
||||
/**
|
||||
* 发布NFT列表
|
||||
*/
|
||||
async publishAirdropList({
|
||||
address,
|
||||
to,
|
||||
nftList,
|
||||
encodeABI = false,
|
||||
}: {
|
||||
address?: string
|
||||
to: string
|
||||
nftList: string[]
|
||||
encodeABI?: boolean
|
||||
}) {
|
||||
const contract = address ? new this.web3.eth.Contract(abi, address, { from: this.account.address }) : this.contract
|
||||
if (encodeABI) {
|
||||
return contract.methods.addNFTData(to, nftList).encodeABI()
|
||||
}
|
||||
let gas = await contract.methods.addNFTData(to, nftList).estimateGas({ from: this.account.address })
|
||||
let res = await contract.methods.addNFTData(to, nftList).send({ gas: gas | 0 })
|
||||
return res
|
||||
}
|
||||
/**
|
||||
* mint nft to user
|
||||
*/
|
||||
async mintNft({
|
||||
address,
|
||||
to,
|
||||
nftList,
|
||||
encodeABI = false,
|
||||
}: {
|
||||
address?: string
|
||||
to: string
|
||||
nftList: string[]
|
||||
encodeABI?: boolean
|
||||
}) {
|
||||
const contract = address ? new this.web3.eth.Contract(abi, address, { from: this.account.address }) : this.contract
|
||||
if (encodeABI) {
|
||||
return contract.methods.mintToUser(to, nftList).encodeABI()
|
||||
}
|
||||
let gas = await contract.methods.mintToUser(to, nftList).estimateGas({ from: this.account.address })
|
||||
let res = await contract.methods.mintToUser(to, nftList).send({ gas: gas | 0 })
|
||||
return res
|
||||
}
|
||||
/**
|
||||
* 查询用户可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.getMintableCount(user).call()
|
||||
}
|
||||
}
|
@ -141,6 +141,7 @@ export class ChainTaskClass extends BaseModule {
|
||||
/**
|
||||
* 解析企业微信审批信息
|
||||
*/
|
||||
// TODO:: mint nft 处理原始数据, 如果传入的是amount, 那么根据规则生成tokenid
|
||||
public static async parseWxApprovalInfo({ taskId, name, desc, data, starter, starterName }) {
|
||||
let maxTryCount = parseInt(process.env.CHAIN_MAX_TRY)
|
||||
let chainTask = await ChainTask.insertOrUpdate({ taskId }, { name, desc, starter, starterName, data })
|
||||
|
@ -10,7 +10,7 @@ export enum TaskType {
|
||||
MINT_NFT = 2,
|
||||
TRANSFER_FT = 3,
|
||||
TRANSFER_NFT = 4,
|
||||
PUBLIC_AIRDROP_LIST = 5,
|
||||
PUBLISH_AIRDROP_LIST = 5,
|
||||
}
|
||||
|
||||
export const TaskTypeMap = new Map([
|
||||
@ -19,7 +19,7 @@ export const TaskTypeMap = new Map([
|
||||
[TaskType.MINT_NFT, 'Mint NFT'],
|
||||
[TaskType.TRANSFER_FT, 'Ft转账'],
|
||||
[TaskType.TRANSFER_NFT, 'NFT转账'],
|
||||
[TaskType.PUBLIC_AIRDROP_LIST, '公布空投名单'],
|
||||
[TaskType.PUBLISH_AIRDROP_LIST, '公布空投名单'],
|
||||
])
|
||||
|
||||
export enum ReqTaskStatus {
|
||||
|
Loading…
x
Reference in New Issue
Block a user