修改BEBadge,metajson从合约获取
This commit is contained in:
parent
fc2b20dfce
commit
17b67330eb
File diff suppressed because one or more lines are too long
10734
build/contracts/JSONMetadata.json
Normal file
10734
build/contracts/JSONMetadata.json
Normal file
File diff suppressed because one or more lines are too long
58
contracts/core/JSONMetadata.sol
Normal file
58
contracts/core/JSONMetadata.sol
Normal file
@ -0,0 +1,58 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity 0.8.10;
|
||||
import "@openzeppelin/contracts/utils/Base64.sol";
|
||||
import "@openzeppelin/contracts/access/Ownable.sol";
|
||||
import "@openzeppelin/contracts/utils/Strings.sol";
|
||||
|
||||
contract JSONMetadata is Ownable {
|
||||
using Strings for uint256;
|
||||
string constant _dataUri = "data:application/json;base64,";
|
||||
|
||||
struct MetaData {
|
||||
string name;
|
||||
string desc;
|
||||
string image;
|
||||
string external_str;
|
||||
}
|
||||
|
||||
mapping(address => MetaData) public metaDatas;
|
||||
|
||||
function getMetaData(
|
||||
address token,
|
||||
uint256 tokenId
|
||||
) public view returns (string memory) {
|
||||
MetaData memory metaData = metaDatas[token];
|
||||
string memory external_str;
|
||||
if (bytes(metaData.external_str).length > 0) {
|
||||
external_str = metaData.external_str;
|
||||
}
|
||||
bytes memory json = abi.encodePacked(
|
||||
'{"name":"',
|
||||
metaData.name,
|
||||
" #",
|
||||
tokenId.toString(),
|
||||
'","description":"',
|
||||
metaData.desc,
|
||||
'","image":"',
|
||||
metaData.image,
|
||||
'","external_url":"',
|
||||
metaData.image,
|
||||
'"',
|
||||
external_str,
|
||||
"}"
|
||||
);
|
||||
|
||||
return string(abi.encodePacked(_dataUri, Base64.encode(json)));
|
||||
}
|
||||
|
||||
function setMetaData(
|
||||
address token,
|
||||
string memory name,
|
||||
string memory desc,
|
||||
string memory image,
|
||||
string memory external_str
|
||||
) external onlyOwner {
|
||||
MetaData memory metaData = MetaData(name, desc, image, external_str);
|
||||
metaDatas[token] = metaData;
|
||||
}
|
||||
}
|
9
contracts/interfaces/IMetaData.sol
Normal file
9
contracts/interfaces/IMetaData.sol
Normal file
@ -0,0 +1,9 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity 0.8.10;
|
||||
|
||||
interface IMetaData {
|
||||
function getMetaData(
|
||||
address token,
|
||||
uint256 tokenId
|
||||
) external view returns (string memory);
|
||||
}
|
@ -2,10 +2,11 @@
|
||||
pragma solidity 0.8.10;
|
||||
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
|
||||
import "@openzeppelin/contracts/access/AccessControl.sol";
|
||||
import "../../interfaces/IMetaData.sol";
|
||||
|
||||
contract BEBadge is AccessControl, ERC721Enumerable {
|
||||
mapping(uint256 => bool) public lockedTokens;
|
||||
string private _baseTokenURI = "https://market.cebg.games/api/nft/info/";
|
||||
address private _metaAddress;
|
||||
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
|
||||
bytes32 public constant BURN_ROLE = keccak256("BURN_ROLE");
|
||||
bytes32 public constant LOCK_ROLE = keccak256("LOCK_ROLE");
|
||||
@ -32,10 +33,6 @@ contract BEBadge is AccessControl, ERC721Enumerable {
|
||||
supplyLimit = _supplyLimt;
|
||||
}
|
||||
|
||||
function _baseURI() internal view virtual override returns (string memory) {
|
||||
return _baseTokenURI;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Batch mint tokens and transfer to specified address.
|
||||
*
|
||||
@ -139,10 +136,10 @@ contract BEBadge is AccessControl, ERC721Enumerable {
|
||||
/**
|
||||
* @dev Set token URI
|
||||
*/
|
||||
function updateBaseURI(
|
||||
string calldata baseTokenURI
|
||||
function updateMetaAddress(
|
||||
address metaAddress
|
||||
) external onlyRole(DEFAULT_ADMIN_ROLE) {
|
||||
_baseTokenURI = baseTokenURI;
|
||||
_metaAddress = metaAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -150,9 +147,9 @@ contract BEBadge is AccessControl, ERC721Enumerable {
|
||||
*/
|
||||
function tokenURI(
|
||||
uint256 tokenId
|
||||
) public view virtual override returns (string memory) {
|
||||
string memory baseURI = _baseURI();
|
||||
return bytes(baseURI).length > 0 ? baseURI : "";
|
||||
) public view override returns (string memory) {
|
||||
require(_exists(tokenId), "URI query for nonexistent token");
|
||||
return IMetaData(_metaAddress).getMetaData(address(this), tokenId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,45 +1,71 @@
|
||||
const Factory = artifacts.require("activity/ClaimBoxFactory");
|
||||
const Box = artifacts.require("tokens/erc721/BEBadge");
|
||||
const Metadata = artifacts.require("core/JSONMetadata");
|
||||
const base = require("../scripts/base");
|
||||
const config = require("../config/config");
|
||||
|
||||
module.exports = async function (deployer, network, accounts) {
|
||||
const name = "Gacha";
|
||||
const symbol = "GACHA";
|
||||
await deployer.deploy(Box, name, symbol, 0);
|
||||
const boxInstance = await Box.deployed();
|
||||
if (boxInstance) {
|
||||
// await deployer.deploy(Box, name, symbol, 0);
|
||||
const gachaInstance = await Box.deployed();
|
||||
if (gachaInstance) {
|
||||
console.log("claim box successfully deployed.");
|
||||
}
|
||||
base.updateArray({
|
||||
name: "Gacha",
|
||||
type: "erc721",
|
||||
json: "assets/contracts/BEBadge.json",
|
||||
address: boxInstance.address,
|
||||
network,
|
||||
});
|
||||
// base.updateArray({
|
||||
// name: "Gacha",
|
||||
// type: "erc721",
|
||||
// json: "assets/contracts/BEBadge.json",
|
||||
// address: gachaInstance.address,
|
||||
// network,
|
||||
// });
|
||||
|
||||
await deployer.deploy(Factory);
|
||||
// await deployer.deploy(Factory);
|
||||
const factoryInstance = await Factory.deployed();
|
||||
if (factoryInstance) {
|
||||
console.log("claim box factory successfully deployed.");
|
||||
}
|
||||
// base.updateArray({
|
||||
// name: "ClaimGachaFactory",
|
||||
// type: "logic",
|
||||
// json: "assets/contracts/ClaimBoxFactory.json",
|
||||
// address: factoryInstance.address,
|
||||
// network,
|
||||
// });
|
||||
|
||||
await deployer.deploy(Metadata);
|
||||
const metadataInstance = await Metadata.deployed();
|
||||
if (metadataInstance) {
|
||||
console.log("metadataInstance successfully deployed.");
|
||||
}
|
||||
base.updateArray({
|
||||
name: "ClaimGachaFactory",
|
||||
name: "JSONMetadata",
|
||||
type: "logic",
|
||||
json: "assets/contracts/ClaimBoxFactory.json",
|
||||
address: factoryInstance.address,
|
||||
json: "assets/contracts/JSONMetadata.json",
|
||||
address: metadataInstance.address,
|
||||
network,
|
||||
});
|
||||
|
||||
await boxInstance.setMintRole(factoryInstance.address);
|
||||
console.log(
|
||||
`success set mint role to: ${factoryInstance.address} claim box `
|
||||
// await gachaInstance.setMintRole(factoryInstance.address);
|
||||
// console.log(
|
||||
// `success set mint role to: ${factoryInstance.address} claim box `
|
||||
// );
|
||||
|
||||
// await factoryInstance.addTokenSupport(gachaInstance.address);
|
||||
// console.log(`success add token support to: ${gachaInstance.address}`);
|
||||
|
||||
// await factoryInstance.updateExecutor(config.admins.admin);
|
||||
// console.log(`success update executor to: ${config.admins.admin}`);
|
||||
|
||||
await gachaInstance.updateMetaAddress(metadataInstance.address);
|
||||
console.log(`success update meta address for: ${gachaInstance.address}`);
|
||||
await metadataInstance.setMetaData(
|
||||
gachaInstance.address,
|
||||
"Gacha",
|
||||
"The Gacha featuring the character 'Hill' from the game, as rewards for Quest missions before CounterFire's official launch.\\nCan get it by participating in the Quest, and it will have multiple benefits.\\nCounterFire is the highly-anticipated first blockchain-based game to offer a unique combination of MOBA and Battle Royale gameplay.Available on Google Play.\\n official website:CounterFire.games",
|
||||
"https://gateway.pinata.cloud/ipfs/Qmdbki45yWsdCvWJmLkTDb2TRPM1Kxe3gDFr6q3xaBHxeF",
|
||||
""
|
||||
);
|
||||
|
||||
await factoryInstance.addTokenSupport(boxInstance.address);
|
||||
console.log(`success add token support to: ${boxInstance.address}`);
|
||||
|
||||
await factoryInstance.updateExecutor(config.admins.admin);
|
||||
console.log(`success update executor to: ${config.admins.admin}`);
|
||||
console.log(`success update metadata for: ${gachaInstance.address}`);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user