Skip to content

Commit

Permalink
add: 添加initQuest函数
Browse files Browse the repository at this point in the history
  • Loading branch information
liangjies committed Dec 4, 2023
1 parent 44650bf commit 16c00e5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
13 changes: 12 additions & 1 deletion contracts/Badge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ contract Badge is IBadge, SBTBase, Ownable {
event MinterSet(address minter, bool enabled);
event QuestInit(uint256 indexed questId, QuestData questData);
event QuestUpdated(uint256 indexed questId, QuestData questData);
event Claimed(uint256 indexed tokenId, uint256 questId, address sender);
event Claimed(uint256 indexed tokenId, uint256 questId, address receiver);
event Donation(address from, address to, uint256 amount);
event URIUpdated(uint indexed tokenId, string uri);

Expand Down Expand Up @@ -92,6 +92,15 @@ contract Badge is IBadge, SBTBase, Ownable {
_claim(to, questId, uri);
}

function initQuest(
uint256 questId,
QuestData calldata questData
) external onlyMinter {
if (_questBadgeNum[questId] != 0) revert QuestIdAlreadyExists();

_initQuest(questId, questData);
}

function updateURI(uint tokenId, string memory uri) external onlyMinter {
_setTokenURI(tokenId, uri);
emit URIUpdated(tokenId, uri);
Expand All @@ -116,7 +125,9 @@ contract Badge is IBadge, SBTBase, Ownable {
}

function _initQuest(uint256 questId, QuestData memory quest) internal {
if (quests[questId].creator!=address(0)) revert QuestIdAlreadyExists();
quests[questId] = quest;

emit QuestInit(questId, quest);
}

Expand Down
31 changes: 30 additions & 1 deletion contracts/BadgeMinter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,35 @@ contract BadgeMinter is Ownable {
}
}

function initQuest(
uint256 questId,
IBadge.QuestData calldata questData,
bytes calldata signature
) external {
address creator = questData.creator;
uint32 startTs = questData.startTs;
uint32 endTs = questData.endTs;
string memory title = questData.title;
string memory questUri = questData.uri;

bytes32 hash = keccak256(
abi.encodePacked(
creator,
questId,
startTs,
endTs,
title,
questUri,
address(this),
address(msg.sender)
)
);

if (!_verify(hash, signature)) revert InvalidSigner();

badge.initQuest(questId, questData);
}

function claim(
address to,
uint256 questId,
Expand Down Expand Up @@ -162,7 +191,7 @@ contract BadgeMinter is Ownable {
address receiver = receivers[i];
uint questId = questIds[i];
string memory uri = uris[i];

IBadge.QuestData memory questData;
questData = badge.getQuest(questId);
if (
Expand Down
10 changes: 4 additions & 6 deletions contracts/interface/IBadge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ interface IBadge is IERC721 {

function setMinter(address minter, bool enabled) external;

function claim(
address to,
uint256 questId,
string memory uri
) external;
function claim(address to, uint256 questId, string memory uri) external;

function claimWithInit(
IBadge.QuestData calldata questData,
Expand All @@ -39,6 +35,8 @@ interface IBadge is IERC721 {
function getQuest(uint256 questId) external view returns (QuestData memory);

function totalSupply() external view returns (uint256);

function updateURI(uint tokenId, string memory uri) external;

function initQuest(uint256 questId, QuestData calldata questData) external;
}

0 comments on commit 16c00e5

Please sign in to comment.