文件 1 的 13:Address.sol
pragma solidity ^0.8.0;
library Address {
function isContract(address account) internal view returns (bool) {
return account.code.length > 0;
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
文件 2 的 13:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 3 的 13:ERC1155.sol
pragma solidity ^0.8.0;
import "./IERC1155.sol";
import "./IERC1155Receiver.sol";
import "./IERC1155MetadataURI.sol";
import "./Address.sol";
import "./Context.sol";
import "./ERC165.sol";
contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
using Address for address;
mapping(uint256 => mapping(address => uint256)) private _balances;
mapping(address => mapping(address => bool)) private _operatorApprovals;
string private _uri;
constructor(string memory uri_) {
_setURI(uri_);
}
function uri(uint256) public view virtual override returns (string memory) {
return _uri;
}
function balanceOf(address account, uint256 id) public view virtual override returns (uint256) {
require(account != address(0), "ERC1155: balance query for the zero address");
return _balances[id][account];
}
function balanceOfBatch(address[] memory accounts, uint256[] memory ids)
public
view
virtual
override
returns (uint256[] memory)
{
require(accounts.length == ids.length, "ERC1155: accounts and ids length mismatch");
uint256[] memory batchBalances = new uint256[](accounts.length);
for (uint256 i = 0; i < accounts.length; ++i) {
batchBalances[i] = balanceOf(accounts[i], ids[i]);
}
return batchBalances;
}
function setApprovalForAll(address operator, bool approved) public virtual override {
_setApprovalForAll(_msgSender(), operator, approved);
}
function isApprovedForAll(address account, address operator) public view virtual override returns (bool) {
return _operatorApprovals[account][operator];
}
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) public virtual override {
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: caller is not owner nor approved"
);
_safeTransferFrom(from, to, id, amount, data);
}
function safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) public virtual override {
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: transfer caller is not owner nor approved"
);
_safeBatchTransferFrom(from, to, ids, amounts, data);
}
function _safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) internal virtual {
require(to != address(0), "ERC1155: transfer to the zero address");
address operator = _msgSender();
_beforeTokenTransfer(operator, from, to, _asSingletonArray(id), _asSingletonArray(amount), data);
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
unchecked {
_balances[id][from] = fromBalance - amount;
}
_balances[id][to] += amount;
emit TransferSingle(operator, from, to, id, amount);
_doSafeTransferAcceptanceCheck(operator, from, to, id, amount, data);
}
function _safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
require(to != address(0), "ERC1155: transfer to the zero address");
address operator = _msgSender();
_beforeTokenTransfer(operator, from, to, ids, amounts, data);
for (uint256 i = 0; i < ids.length; ++i) {
uint256 id = ids[i];
uint256 amount = amounts[i];
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
unchecked {
_balances[id][from] = fromBalance - amount;
}
_balances[id][to] += amount;
}
emit TransferBatch(operator, from, to, ids, amounts);
_doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, amounts, data);
}
function _setURI(string memory newuri) internal virtual {
_uri = newuri;
}
function _mint(
address to,
uint256 id,
uint256 amount,
bytes memory data
) internal virtual {
require(to != address(0), "ERC1155: mint to the zero address");
address operator = _msgSender();
_beforeTokenTransfer(operator, address(0), to, _asSingletonArray(id), _asSingletonArray(amount), data);
_balances[id][to] += amount;
emit TransferSingle(operator, address(0), to, id, amount);
_doSafeTransferAcceptanceCheck(operator, address(0), to, id, amount, data);
}
function _mintBatch(
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {
require(to != address(0), "ERC1155: mint to the zero address");
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
address operator = _msgSender();
_beforeTokenTransfer(operator, address(0), to, ids, amounts, data);
for (uint256 i = 0; i < ids.length; i++) {
_balances[ids[i]][to] += amounts[i];
}
emit TransferBatch(operator, address(0), to, ids, amounts);
_doSafeBatchTransferAcceptanceCheck(operator, address(0), to, ids, amounts, data);
}
function _burn(
address from,
uint256 id,
uint256 amount
) internal virtual {
require(from != address(0), "ERC1155: burn from the zero address");
address operator = _msgSender();
_beforeTokenTransfer(operator, from, address(0), _asSingletonArray(id), _asSingletonArray(amount), "");
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
unchecked {
_balances[id][from] = fromBalance - amount;
}
emit TransferSingle(operator, from, address(0), id, amount);
}
function _burnBatch(
address from,
uint256[] memory ids,
uint256[] memory amounts
) internal virtual {
require(from != address(0), "ERC1155: burn from the zero address");
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
address operator = _msgSender();
_beforeTokenTransfer(operator, from, address(0), ids, amounts, "");
for (uint256 i = 0; i < ids.length; i++) {
uint256 id = ids[i];
uint256 amount = amounts[i];
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
unchecked {
_balances[id][from] = fromBalance - amount;
}
}
emit TransferBatch(operator, from, address(0), ids, amounts);
}
function _setApprovalForAll(
address owner,
address operator,
bool approved
) internal virtual {
require(owner != operator, "ERC1155: setting approval status for self");
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
function _beforeTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {}
function _doSafeTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) private {
if (to.isContract()) {
try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
if (response != IERC1155Receiver.onERC1155Received.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catch Error(string memory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non ERC1155Receiver implementer");
}
}
}
function _doSafeBatchTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) private {
if (to.isContract()) {
try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (
bytes4 response
) {
if (response != IERC1155Receiver.onERC1155BatchReceived.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catch Error(string memory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non ERC1155Receiver implementer");
}
}
}
function _asSingletonArray(uint256 element) private pure returns (uint256[] memory) {
uint256[] memory array = new uint256[](1);
array[0] = element;
return array;
}
}
文件 4 的 13:ERC165.sol
pragma solidity ^0.8.0;
import './IERC165.sol';
abstract contract ERC165 is IERC165 {
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override
returns (bool)
{
return interfaceId == type(IERC165).interfaceId;
}
}
文件 5 的 13:FishGame.sol
pragma solidity ^0.8.0;
import "./base/ERC1155.sol";
import "./base/Ownable.sol";
import "./base/IERC721.sol";
import "./base/IERC1155Receiver.sol";
import "./base/IVRF.sol";
import "./base/ReentrancyGuard.sol";
interface Fillet{
function mint(address receiver,uint amount) external;
}
interface GoodFish is IERC721{
function mint(address receiver) external;
function burn(uint tokenId) external;
}
contract FishGame is ERC1155, Ownable, ReentrancyGuard{
IERC721 fisherman;
IVRF RandomnessEngine;
Fillet fillet;
GoodFish goodFish;
constructor(address _fishermanAddress,address _vrf,address _fillet,address _goodFish) ERC1155("https://fishgametoken.s3.ap-south-1.amazonaws.com/{id}.json") {
fisherman = IERC721(_fishermanAddress);
RandomnessEngine = IVRF(_vrf);
fillet = Fillet(_fillet);
goodFish = GoodFish(_goodFish);
}
event FishStatus(string Fish);
uint public coolDownTime = 1 days;
mapping (uint => bool) public isLegendary;
mapping (uint => uint) public level;
mapping (uint => uint) public lastClaim;
mapping (uint => uint) public lastClaimFishWorm;
mapping (uint => indexInfo) randomIndex;
mapping (uint => uint) public coolDownForCooking;
mapping (address => uint) public coolDownForClaimingWithGoodFish;
mapping (uint => bool) public bonusClaimed;
mapping (uint => uint) public wormClaimedOnFish;
uint8 public constant WORM = 1;
struct indexInfo {
uint cook;
uint fish;
}
function contractSetter(address _address) external onlyOwner {
fisherman = IERC721(_address);
}
function vrfSetter(address _vrf) external onlyOwner{
RandomnessEngine = IVRF(_vrf);
}
function filletSetter(address _fillet) external onlyOwner{
fillet = Fillet(_fillet);
}
function goodFishSetter(address _goodFish) external onlyOwner{
goodFish = GoodFish(_goodFish);
}
function setLegendary(uint tokenId) external onlyOwner {
isLegendary[tokenId] = true;
}
function initiateGame(uint _tokenId) external {
require(fisherman.ownerOf(_tokenId) == _msgSender(), "Caller doesn't own the token");
require(level[_tokenId]== 0, "Game already initiated");
level[_tokenId]++;
uint index = RandomnessEngine.getCurrentIndex();
randomIndex[_tokenId] = indexInfo(index,index);
}
function bonusClaim(uint tokenId) external nonReentrant {
require(level[tokenId]>0, "Game not inititaed");
require(tokenId<1597, "Bonus $WORM cannot be claimed");
require(!bonusClaimed[tokenId], "Bonus already claimed");
require (lastClaim[tokenId] + coolDownTime <= block.timestamp, "Cooldown time not exceeded");
_mint(_msgSender(), WORM, 410 ether, "");
lastClaim[tokenId] = block.timestamp;
bonusClaimed[tokenId] = true;
}
function levelUp(uint tokenId) external nonReentrant{
require(level[tokenId]>0, "Game not initiated yet");
require(fisherman.ownerOf(tokenId) == _msgSender(),"Caller doesn't own the token(s)");
require(level[tokenId]<5, "Maximum level reached");
uint tokenToBurn = LevelUpCalculation(tokenId)* 1 ether;
_burn(_msgSender(),WORM,tokenToBurn);
level[tokenId]++;
}
function LevelUpCalculation(uint tokenId) internal view returns(uint) {
if(isLegendary[tokenId]){
return 1000+1000*(level[tokenId]-1);
}
else {
return 600+200*(level[tokenId]-1);
}
}
function claimWorm(uint[] memory fishermen) external nonReentrant{
for(uint i=0; i<fishermen.length; i++){
require(level[fishermen[i]]>0, "Game not initiated yet");
require(fisherman.ownerOf(fishermen[i]) == _msgSender(),"Caller doesn't own the token(s)");
if(lastClaim[fishermen[i]] == 0) {
uint calculatedValue = calculateWorm(fishermen[i]);
_mint(_msgSender(), WORM, calculatedValue*1 ether, "");
lastClaim[fishermen[i]] = block.timestamp;
}
else {
require( lastClaim[fishermen[i]] + coolDownTime <= block.timestamp, "Cooldown time not exceeded");
uint calculatedValue = calculateWorm(fishermen[i]);
calculatedValue = ((block.timestamp - lastClaim[fishermen[i]])/coolDownTime) * calculatedValue* 1 ether;
_mint(_msgSender(), WORM, calculatedValue, "");
lastClaim[fishermen[i]] = block.timestamp;
}
}
}
function calculateWorm(uint tokenId) internal view returns(uint){
if(isLegendary[tokenId]){
return 50*(level[tokenId]);
}
else{
return 10*(level[tokenId]);
}
}
function fishingPrice(uint tokenId) internal view returns (uint) {
if(isLegendary[tokenId]){
return (10-2*(level[tokenId]-1));
}
else{
return (15-3*(level[tokenId]-1));
}
}
function fish(uint tokenId) external nonReentrant{
require(fisherman.ownerOf(tokenId) == _msgSender(),"Caller doesn't own the token(s)");
require(level[tokenId]>0, "Game not initiated yet");
indexInfo storage info = randomIndex[tokenId];
uint rand = RandomnessEngine.initiateRandomness(tokenId,info.fish)%100;
require(rand > 0,"New randomess not retrieved yet");
uint toBurn = fishingPrice(tokenId);
_burn(_msgSender(),WORM, toBurn * 1 ether);
info.fish = RandomnessEngine.getCurrentIndex();
if(isLegendary[tokenId]){
if(rand<50+10*(level[tokenId]-1)){
goodFish.mint(_msgSender());
emit FishStatus("Good fish");
}
else{
emit FishStatus("Bad fish");
autoCompost(tokenId, 0,rand);
}
}
else{
if(rand<15*(level[tokenId])){
goodFish.mint(_msgSender());
emit FishStatus("Good fish");
}
else if(rand<15*level[tokenId]+35-5*(level[tokenId]-1)){
emit FishStatus("Bad fish");
autoCompost(tokenId, 1, rand);
}
else{
emit FishStatus("No fish");
}
}
}
function autoCompost(uint tokenId,uint fisherType, uint rand) internal{
if(fisherType == 1) {
if(rand< 40+10*(level[tokenId]-1)){
_mint(_msgSender(), WORM, (4.5*1 ether)-(0.9*1 ether *(level[tokenId]-1)) , "");
}
}
else {
if(rand< 75+5*(level[tokenId]-1)){
_mint(_msgSender(), WORM, 5*1 ether-1 ether*(level[tokenId]-1), "");
}
}
}
function calculateWormOnGoodFish(uint tokenId) internal view returns(uint){
if(isLegendary[tokenId]){
return 16 ether;
}
else{
return 8 ether;
}
}
function claimWormOnGoodFish(uint tokenId,uint fishId) external nonReentrant{
require(fisherman.ownerOf(tokenId) == _msgSender(),"Caller doesn't own the token(s)");
require(goodFish.ownerOf(fishId) == _msgSender(),"Caller not owner");
require(level[tokenId]>0, "Game not initiated yet");
require (block.timestamp - wormClaimedOnFish[fishId] >= coolDownTime, "CoolDown time not over");
if(lastClaimFishWorm[tokenId] == 0){
uint wormValue = calculateWormOnGoodFish(tokenId);
_mint(_msgSender(), WORM, wormValue, "");
wormClaimedOnFish[fishId] = block.timestamp;
lastClaimFishWorm[tokenId] = block.timestamp;
}
else{
require(lastClaimFishWorm[tokenId] + coolDownTime <= block.timestamp, "Cooldown time not exceeded");
uint wormValue = calculateWormOnGoodFish(tokenId);
wormValue = ((block.timestamp - wormClaimedOnFish[fishId])/coolDownTime) * wormValue;
_mint(_msgSender(), WORM, wormValue, "");
wormClaimedOnFish[fishId] = block.timestamp;
lastClaimFishWorm[tokenId] = block.timestamp;
}
}
function Cook(uint tokenId,uint fishId) external nonReentrant {
require(goodFish.ownerOf(fishId) == msg.sender, "Invalid fish");
require(fisherman.ownerOf(tokenId)== msg.sender,"Invalid Fisherman");
require(level[tokenId]>0, "Game not Initiated");
require (block.timestamp - coolDownForCooking[tokenId] >= coolDownTime, "Cool down time not exceeded");
indexInfo storage info = randomIndex[tokenId];
uint rand = RandomnessEngine.initiateRandomness(tokenId,info.cook)%100;
require(rand > 0,"New randomness not retrieved yet");
info.cook = RandomnessEngine.getCurrentIndex();
if(isLegendary[tokenId]){
if(rand< 40){
cooker(700,fishId);
coolDownForCooking[tokenId] = block.timestamp;
emit FishStatus("Dish Cooked: Caviar");
}
else if(rand<75){
cooker(200,fishId);
coolDownForCooking[tokenId] = block.timestamp;
emit FishStatus("Dish Cooked: Sushi");
}
else{
cooker(75,fishId);
coolDownForCooking[tokenId] = block.timestamp;
emit FishStatus("Dish Cooked: Tuna Sandwich");
}
}
else{
if(rand<10){
cooker(700,fishId);
coolDownForCooking[tokenId] = block.timestamp;
emit FishStatus("Dish Cooked: Caviar");
}
else if(rand<30){
cooker(200,fishId);
coolDownForCooking[tokenId] = block.timestamp;
emit FishStatus("Dish Cooked: Sushi");
}
else if(rand<60){
cooker(75,fishId);
coolDownForCooking[tokenId] = block.timestamp;
emit FishStatus("Dish Cooked: Tuna Sandwich");
}
else{
cooker(25,fishId);
coolDownForCooking[tokenId] = block.timestamp;
emit FishStatus("Dish Cooked: Soup");
}
}
}
function cooker(uint amount,uint tokenId) internal{
goodFish.burn(tokenId);
fillet.mint(_msgSender(),amount*1 ether);
}
function _setURIOfToken(string memory newuri) external onlyOwner {
_setURI(newuri);
}
function setCoolDownTime (uint _time) external onlyOwner {
coolDownTime = _time;
}
}
文件 6 的 13:IERC1155.sol
pragma solidity ^0.8.0;
import "./IERC165.sol";
interface IERC1155 is IERC165 {
event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
event TransferBatch(
address indexed operator,
address indexed from,
address indexed to,
uint256[] ids,
uint256[] values
);
event ApprovalForAll(address indexed account, address indexed operator, bool approved);
event URI(string value, uint256 indexed id);
function balanceOf(address account, uint256 id) external view returns (uint256);
function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids)
external
view
returns (uint256[] memory);
function setApprovalForAll(address operator, bool approved) external;
function isApprovedForAll(address account, address operator) external view returns (bool);
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes calldata data
) external;
function safeBatchTransferFrom(
address from,
address to,
uint256[] calldata ids,
uint256[] calldata amounts,
bytes calldata data
) external;
}
文件 7 的 13:IERC1155MetadataURI.sol
pragma solidity ^0.8.0;
import "./IERC1155.sol";
interface IERC1155MetadataURI is IERC1155 {
function uri(uint256 id) external view returns (string memory);
}
文件 8 的 13:IERC1155Receiver.sol
pragma solidity ^0.8.0;
interface IERC1155Receiver {
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
) external returns (bytes4);
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external returns (bytes4);
}
文件 9 的 13:IERC165.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 10 的 13:IERC721.sol
pragma solidity ^0.8.0;
import "./IERC165.sol";
interface IERC721 is IERC165 {
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
function balanceOf(address owner) external view returns (uint256 balance);
function ownerOf(uint256 tokenId) external view returns (address owner);
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
function approve(address to, uint256 tokenId) external;
function getApproved(uint256 tokenId) external view returns (address operator);
function setApprovalForAll(address operator, bool _approved) external;
function isApprovedForAll(address owner, address operator) external view returns (bool);
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
}
文件 11 的 13:IVRF.sol
pragma solidity ^0.8.0;
interface IVRF{
function initiateRandomness(uint _tokenId,uint _timestamp) external view returns(uint);
function getCurrentIndex() external view returns(uint);
}
文件 12 的 13:Ownable.sol
pragma solidity ^0.8.0;
import "./Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_transferOwnership(_msgSender());
}
function owner() public view virtual returns (address) {
return _owner;
}
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
文件 13 的 13:ReentrancyGuard.sol
pragma solidity ^0.8.0;
abstract contract ReentrancyGuard {
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
modifier nonReentrant() {
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
_status = _ENTERED;
_;
_status = _NOT_ENTERED;
}
}
{
"compilationTarget": {
"FishGame.sol": "FishGame"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_fishermanAddress","type":"address"},{"internalType":"address","name":"_vrf","type":"address"},{"internalType":"address","name":"_fillet","type":"address"},{"internalType":"address","name":"_goodFish","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"Fish","type":"string"}],"name":"FishStatus","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"values","type":"uint256[]"}],"name":"TransferBatch","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"TransferSingle","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"value","type":"string"},{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"}],"name":"URI","type":"event"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"fishId","type":"uint256"}],"name":"Cook","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"WORM","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"newuri","type":"string"}],"name":"_setURIOfToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"accounts","type":"address[]"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"}],"name":"balanceOfBatch","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"bonusClaim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"bonusClaimed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"fishermen","type":"uint256[]"}],"name":"claimWorm","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"fishId","type":"uint256"}],"name":"claimWormOnGoodFish","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"contractSetter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"coolDownForClaimingWithGoodFish","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"coolDownForCooking","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"coolDownTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_fillet","type":"address"}],"name":"filletSetter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"fish","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_goodFish","type":"address"}],"name":"goodFishSetter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"initiateGame","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"isLegendary","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"lastClaim","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"lastClaimFishWorm","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"level","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"levelUp","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeBatchTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_time","type":"uint256"}],"name":"setCoolDownTime","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"setLegendary","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"uri","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_vrf","type":"address"}],"name":"vrfSetter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"wormClaimedOnFish","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]