Commit bf959dc3 authored by vicotor's avatar vicotor

fix bug for deploy

parent 50f6d41d
node_modules node_modules
.idea
.env .env
# Hardhat files # Hardhat files
...@@ -15,3 +16,4 @@ node_modules ...@@ -15,3 +16,4 @@ node_modules
# Hardhat Ignition default folder for deployments against a local node # Hardhat Ignition default folder for deployments against a local node
ignition/deployments/chain-31337 ignition/deployments/chain-31337
.secret
ADDR_USDT_TOKEN=
ADDR_API_SERVER=0x9f8fb0488de145e7467fded872098e1115d6ea4c
ADDR_MINT_RECEIVER=0xf5F236e1249C427100E3aB989ebFE829f700E352
ADDR_BONUS_POOL=0xac8b968d7c45919eE468c0DF421A6EA1567A6cb4
ADDR_BONUS_BURNED=0x8452D87bb98db41C5c4A0E7D1992b4EA3c9959Cd
ADDR_BONUS_PLATFORM=0x19Bd3121fEC07F047ac991e7b35C265a2B1F51eE
ADDR_FEE_RECEIVER=0x19Bd3121fEC07F047ac991e7b35C265a2B1F51eE
\ No newline at end of file
ADDR_USDT_TOKEN=
ADDR_API_SERVER=0x9f8fb0488de145e7467fded872098e1115d6ea4c
ADDR_MINT_RECEIVER=0x565897f5A092d754f5Eff148baF0Adefe7e4074D
ADDR_BONUS_POOL=0x525Dca17813e4d9b0b6c77FFB4F8F88748066Fa0
ADDR_BONUS_BURNED=0x4BccBC797a7f4041A5E4609bB98406582615984e
ADDR_BONUS_PLATFORM=0x46604a83103c7963dd0CD6e35434EB6C025A6913
ADDR_FEE_RECEIVER=0x46604a83103c7963dd0CD6e35434EB6C025A6913
ADDR_USDT_TOKEN=
ADDR_API_SERVER=0x9f8fb0488de145e7467fded872098e1115d6ea4c
ADDR_MINT_RECEIVER=0xf5F236e1249C427100E3aB989ebFE829f700E352
ADDR_BONUS_POOL=0xac8b968d7c45919eE468c0DF421A6EA1567A6cb4
ADDR_BONUS_BURNED=0x8452D87bb98db41C5c4A0E7D1992b4EA3c9959Cd
ADDR_BONUS_PLATFORM=0x19Bd3121fEC07F047ac991e7b35C265a2B1F51eE
ADDR_FEE_RECEIVER=0x19Bd3121fEC07F047ac991e7b35C265a2B1F51eE
\ No newline at end of file
ADDR_USDT_TOKEN=0xc2132d05d31c914a87c6611c10748aeb04b58e8f
ADDR_API_SERVER=0x9f8fb0488de145e7467fded872098e1115d6ea4c
ADDR_MINT_RECEIVER=0x565897f5A092d754f5Eff148baF0Adefe7e4074D
ADDR_BONUS_POOL=0x525Dca17813e4d9b0b6c77FFB4F8F88748066Fa0
ADDR_BONUS_BURNED=0x4BccBC797a7f4041A5E4609bB98406582615984e
ADDR_BONUS_PLATFORM=0x46604a83103c7963dd0CD6e35434EB6C025A6913
ADDR_FEE_RECEIVER=0x46604a83103c7963dd0CD6e35434EB6C025A6913
// contracts/Box.sol // contracts/Box.sol
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.8.4; pragma solidity ^0.8.22;
contract Box { contract Box {
uint256 private value; uint256 private value;
......
// contracts/Box.sol // contracts/Box.sol
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.8.4; pragma solidity ^0.8.22;
contract BoxV2 { contract BoxV2 {
uint256 private value; uint256 private value;
......
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
interface IERC721Metadata {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function tokenURI(uint256 tokenId) external view returns (string memory);
}
interface IERC721 is IERC165 {
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;
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);
}
interface IERC721Token is IERC721, IERC721Metadata {
}
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4);
}
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address from, address to, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
interface IERC20Metadata {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
}
interface IERC20Token is IERC20, IERC20Metadata {
}
interface IERC20TokenMinable is IERC20Token {
function mint(address recipient, uint amount) external returns (bool);
}
interface IERC721TokenMinable is IERC721Token {
function mint(address to) external returns (uint256);
function mint(address to, bytes memory _data) external returns (uint256);
function mint(uint256 len, address to) external returns (uint256[] memory);
function mint(uint256 len, address to, bytes memory _data) external returns (uint256[] memory);
function mint(uint256 len, address to, bytes[] memory _data) external returns (uint256[] memory);
function mint(uint256 len, address[] memory to, bytes[] memory _data) external returns (uint256[] memory);
}
interface IERC721BeforeTransfer {
function beforeTransfer(address from, address to, uint256 tokenId) external returns (bool);
}
interface IERC721AfterTransfer {
function afterTransfer(address from, address to, uint256 tokenId) external returns (bool);
}
interface IRaceBonusDistribute {
function distribute(address _raceCourse, uint256[] memory _tokenIds, uint256 _money) external returns (uint256,address[] memory, uint256[] memory);
}
interface IRaceBonusPool {
function distribute(address _raceCourse, uint256[] memory _tokenIds, uint256 _money, uint256 count, address[] memory lstAddress, uint256[] memory lstAmount) external;
function claim(uint256 nft_id) external;
}
\ No newline at end of file
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
interface IArenaOpera {
function setHorseFactName(uint256 tokenId, string calldata name) external returns (bool);
function setCreateTime(uint256 tokenId, uint256 time) external returns (bool);
function setHorseFactTypes(uint256 tokenId, uint256 types) external returns (bool);
function setFactoryStatus(uint256 tokenId, uint256 status) external returns (bool);
function setRaceCount(uint256 tokenId, uint256 count) external returns (bool);
function uptTotalRaceCount(uint256 tokenId) external returns (bool);
function setLastRaceTime(uint256 tokenId, uint256 time) external returns (bool);
function setMortAmount(uint256 tokenId, uint256 amount) external returns (bool);
function getFactoryName(uint256 tokenId) external returns (string memory);
function getCreateTime(uint256 tokenId) external returns (uint256);
function getOwnerType(uint256 tokenId) external returns (uint256);
function getIsClose(uint256 tokenId) external returns (uint256);
function getRaceCount(uint256 tokenId) external returns (uint256);
function getLastRaceTime(uint256 tokenId) external returns (uint256);
function getTotalRaceCount(uint256 tokenId) external returns (uint256);
function getMortAmount(uint256 tokenId) external returns (uint256);
function setGameId(uint256 tokenId, uint256 gameId) external returns (bool);
function checkGameId(uint256 tokenId, uint256 gameId) external returns (bool);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
interface ICoin {
function safeTransferFrom(uint256 coin, address from, address to, uint256 value) external;
function safeTransferFrom1(uint256 coin, address from, address to, uint256 value) external;
function safeTransfer(uint256 coin, address to, uint256 value) external;
function safeTransfer1(uint256 coin, address to, uint256 value) external;
function safeTransferWei(uint256 _coinName, address to, uint256 value) external;
function balanceOf(uint256 _coinName, address account) external returns (uint256);
function decimals(uint256 _coinName) external returns (uint);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
interface ICoin721 {
function safeTransferFrom(address token, address from, address to, uint256 tokenId) external;
function balanceOf(address token, address account) external returns (uint256);
function ownerOf(address token, uint256 tokenId) external returns (address);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
interface IConstant {
function getMortAmount() external view returns (uint256);
function getMortToken() external view returns (uint256);
function getMinMortTime() external view returns (uint256);
function getGameCountLimit() external view returns (uint256);
function getMaxSpacing() external view returns (uint256);
function getApplyGameToken() external view returns (uint256);
function getApplyGameAmount() external view returns (uint256);
function getMinRaceUptTime() external view returns (uint256);
function getAwardToken() external view returns (uint256);
function getAwardAmount() external view returns (uint256);
function getExtraAwardToken() external view returns (uint256);
function getExtraAwardAmount() external view returns (uint256);
function getMaxScore() external view returns (uint256);
function getUseEnergy() external view returns (uint256);
function getResting() external view returns (uint256);
function getOnSale() external view returns (uint256);
function getBreeding() external view returns (uint256);
function getSigning() external view returns (uint256);
function getInGame() external view returns (uint256);
function getOnHold() external view returns (uint256);
function getOnSell() external view returns (uint256);
function getEquipped() external view returns (uint256);
function getFeeRateOfHorse() external view returns (uint256);
function getMinDiscountOfHorse() external view returns (uint256);
function getMaxRewardOfHorse() external view returns (uint256);
function getMinSellUptTime() external view returns (uint256);
function getFeeRateOfEquip() external view returns (uint256);
function getMinDiscountOfEquip() external view returns (uint256);
function getMaxRewardOfEquip() external view returns (uint256);
function getMinSpacing() external view returns (uint256);
function getMinTraValue() external view returns (uint256);
function getMaxTraValue() external view returns (uint256);
function getTraAddValue() external view returns (uint256);
function getTraTime() external view returns (uint256);
function getUntTime() external view returns (uint256);
function getTraToken() external view returns (uint256);
function getTraTokenAmount() external view returns (uint256);
function getBreDiscount() external view returns (uint256);
function getBreCoefficient() external view returns (uint256);
function getMinMareBrSpaTime() external view returns (uint256);
function getMinStaBrSpaTime() external view returns (uint256);
function getMinMatureTime() external view returns (uint256);
function getMinStudUptTime() external view returns (uint256);
function getBreCoin1() external view returns (uint256);
function getBreCoin1Amount() external view returns (uint256);
function getBreCoin2() external view returns (uint256);
function getBreCoin2Amount() external view returns (uint256);
function getWeekRankCount() external view returns (uint256);
function getMonthRankCount() external view returns (uint256);
function getYearRankCount() external view returns (uint256);
function getDate() external returns (uint32, uint32, uint32);
function isOfficialContract(address addr) external view returns (bool);
function getAccount() external view returns (address);
function getApplyGameAmountByDistance(uint256 distance) external view returns (uint256);
function getAwardAmountByDistance(uint256 distance) external view returns (uint256);
function getMaxApplyCount() external view returns (uint256);
function getTrackNumber() external view returns (uint256);
function getInitColorsCount() external view returns (uint32);
function getInitColors(uint8 index) external view returns (string memory);
function getInitGrade() external view returns (uint256);
function getInitIntegral() external view returns (uint256);
function getMaxEnergy() external view returns (uint256);
function getModifyNameTimes() external view returns (uint256);
function getEnergyRecoverCD() external view returns (uint256);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
interface IERC721Attr {
function setValues(address addr, uint256 tokenId, string calldata field, bytes calldata value) external returns (bool);
function getValue(address addr, uint256 tokenId, string calldata field) external view returns (bytes memory result);
function setFiled(address addr, string[] calldata field, uint256[] calldata types, uint256[] calldata auth) external returns (bool);
function setUniques(address addr, string calldata field, bytes calldata value) external returns (bool);
function clearUniques(address addr, string memory field, bytes memory value) external returns (bool);
function delFiled(address addr, string calldata field) external returns (bool);
function delValues(address addr, uint256 tokenId, string calldata field) external returns (bool);
function getAuth(address addr, string calldata field) external view returns (uint256);
function getType(address addr, string calldata field) external view returns (uint256);
function getUniques(address addr, string calldata field, bytes calldata value) external view returns (bool);
function setArrayValue(uint256 tokenId, string calldata field, bytes calldata value) external returns (bool);
function checkArrayValue(uint256 tokenId, string calldata field, bytes calldata value) external view returns (bool);
function delArrayValue(uint256 tokenId, string calldata field) external returns (bool);
function removeArrayValue(uint256 tokenId, string calldata field, bytes calldata value) external returns (bool);
function getArrayValue(uint256 tokenId, string calldata field) external view returns (uint256[] memory);
function getArrayCount(uint256 tokenId, string calldata field) external view returns (uint256);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
interface IERC721BeforeTransfer {
function beforeTransfer(address from, address to, uint256 tokenId) external returns (bool);
}
interface IERC721AfterTransfer {
function afterTransfer(address from, address to, uint256 tokenId) external returns (bool);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
interface IERC721Token {
/**
* @dev Returns the number of NFTs in `owner`'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the NFT specified by `tokenId`.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Transfers a specific NFT (`tokenId`) from one account (`from`) to
* another (`to`).
*
*
*
* Requirements:
* - `from`, `to` cannot be zero.
* - `tokenId` must be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this
* NFT by either {approve} or {setApprovalForAll}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers a specific NFT (`tokenId`) from one account (`from`) to
* another (`to`).
*
* Requirements:
* - If the caller is not `from`, it must be approved to move this NFT by
* either {approve} or {setApprovalForAll}.
*/
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;
function safeMint(address to) external returns (uint256);
function safeMint(address to, uint256 tokenId) external returns (uint256);
function exists(uint256 tokenId) external returns (bool);
function mint(address to) external returns (uint256);
function mint(address to, bytes memory _data) external returns (uint256);
function mint(uint256 len, address to) external returns (uint256[] memory);
function mint(uint256 len, address to, bytes memory _data) external returns (uint256[] memory);
function mint(uint256 len, address to, bytes[] memory _data) external returns (uint256[] memory);
function mint(uint256 len, address[] memory to, bytes[] memory _data) external returns (uint256[] memory);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
interface IHorseEquipOpera {
function setEquipStatus(uint256 tokenId, uint256 status) external returns (bool);
function setEquipStatusBatch(uint256[] calldata tokenIds, uint256 status) external returns (bool);
function setEquipTypes(uint256 tokenId, uint256 types) external returns (bool);
function setEquipStyle(uint256 tokenId, uint256 style) external returns (bool);
function setEquipPrice(uint256 tokenId, uint256 price) external returns (bool);
function setEquipOfHorseId(uint256 tokenId, uint256 horseId) external returns (bool);
function setEquipDis(uint256 tokenId, uint256 discount) external returns (bool);
function setEquipReward(uint256 tokenId, uint256 reward) external returns (bool);
function setEquipCoin(uint256 tokenId, uint256 coin) external returns (bool);
function setLastOperaTime1(uint256 tokenId, uint256 operaTime) external returns (bool);
function setLastOperaTime2(uint256 tokenId) external returns (bool);
function setEquipLastOwner(uint256 tokenId, address addr) external returns (bool);
function setEquipLastPrice(uint256 tokenId, uint256 price) external returns (bool);
function getLastOperaTime(uint256 tokenId) external returns (uint256);
function getHorseEquipLastOwner(uint256 tokenId) external returns (address);
function getHorseEquipStatus(uint256 tokenId) external returns (uint256);
function getHorseEquipCoin(uint256 tokenId) external returns (uint256);
function getHorseEquipPrice(uint256 tokenId) external returns (uint256);
function getHorseEquipDiscount(uint256 tokenId) external returns (uint256);
function getHorseEquipReward(uint256 tokenId) external returns (uint256);
function getHorseEquipTypes(uint256 tokenId) external returns (uint256);
function getHorseEquipStyle(uint256 tokenId) external returns (uint256);
function getHorseEquipLastPrice(uint256 tokenId) external returns (uint256);
function getEquipOfHorseId(uint256 tokenId) external returns (uint256);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
interface IHorseRaceOpera {
function setHorseStatus(uint256 tokenId, uint256 status) external returns (bool);
function setHorseStatusBatch(uint256[] calldata tokenId, uint256 status) external returns (bool);
function setHorseCount(uint256 tokenId, uint256 count) external returns (bool);
function setHorseName(uint256 tokenId, string calldata name) external returns (bool);
function setHorseNameUptCount(uint256 tokenId, uint256 count) external returns (bool);
function setHorseBirthDay(uint256 tokenId, uint256 birthDay) external returns (bool);
// horse mainGeneration
function setHorseMGene(uint256 tokenId, uint256 mainGeneration) external returns (bool);
function setHorseSGene(uint256 tokenId, uint256 slaveGeneration) external returns (bool);
// 迭代系数
function setHorseGeneSc(uint256 tokenId, uint256 generationScore) external returns (bool);
// 性别
function setHorseGender(uint256 tokenId, uint256 gender) external returns (bool);
// 皮肤颜色
function setHorseColor(uint256 tokenId, string calldata color) external returns (bool);
//基因综合评分
function setHorseGene(uint256 tokenId, string calldata gene) external returns (bool);
// 设置训练值
function setHorseTraValue(uint256 tokenId, uint256 trainingValue) external returns (bool);
// 设置训练时间
function setHorseTraTime(uint256 tokenId, uint256 trainingTime) external returns (bool);
// 设置能量
function setHorseEnergy(uint256 tokenId, uint256 energy) external returns (bool);
// 能量恢复时间
function setHorseEngTime(uint256 tokenId, uint256 energyUpdateTime) external returns (bool);
// 马匹评分
function setHorseGradeSc(uint256 tokenId, uint256 gradeScore) external returns (bool);
// 马匹积分
function setHorseIntegral(uint256 tokenId, uint256 integral) external returns (bool);
// 马匹积分正负值标记
function setHorseIntMark(uint256 tokenId, uint256 gradeScoreMark) external returns (bool);
//积分最后一次更新时间
function setHorseScUptTime(uint256 tokenId, uint256 raceScoreUpdateTime) external returns (bool);
function setHorseFatherId(uint256 tokenId, uint256 father) external returns (bool);
function setHorseMotherId(uint256 tokenId, uint256 mother) external returns (bool);
// 繁殖次数
function setHorseBreedCount(uint256 tokenId) external returns (bool);
// 繁殖时间
function setHorseBreedTime(uint256 tokenId, uint256 breedTime) external returns (bool);
function setHeadWearId(uint256 tokenId, uint256 headWearId) external returns (bool);
function setArmorId(uint256 tokenId, uint256 armorId) external returns (bool);
function setPonytailId(uint256 tokenId, uint256 ponytailId) external returns (bool);
function setHoofId(uint256 tokenId, uint256 hoofId) external returns (bool);
function setGrade(uint256 tokenId, uint256 grade) external returns (bool);
function setWinCount(uint256 tokenId, uint256 winCount) external returns (bool);
function setRacePrice(uint256 tokenId, uint256 price) external returns (bool);
function setRaceDis(uint256 tokenId, uint256 discount) external returns (bool);
function setRaceReward(uint256 tokenId, uint256 reward) external returns (bool);
function setRaceCoin(uint256 tokenId, uint256 coin) external returns (bool);
function setSellUpdateTime(uint256 tokenId) external returns (bool);
function setStudUpdateTime(uint256 tokenId) external returns (bool);
function setRaceLastOwner(uint256 tokenId, address addr) external returns (bool);
function setRaceLastPrice(uint256 tokenId, uint256 price) external returns (bool);
function setRaceId(uint256 tokenId, uint256 raceId) external returns (bool);
function setRaceType(uint256 tokenId, uint256 raceType) external returns (bool);
function setRacecourse(uint256 tokenId, uint256 racecourse) external returns (bool);
function setDistance(uint256 tokenId, uint256 distance) external returns (bool);
function setRaceUpdateTime(uint256 tokenId, uint256 raceUpdateTime) external returns (bool);
function getHorseName(uint256 tokenId) external returns (string memory);
function getNameUptCount(uint256 tokenId) external returns (uint256);
function getBirthDay(uint256 tokenId) external returns (uint256);
function getHorseMGene(uint256 tokenId) external returns (uint256);
function getHorseSGene(uint256 tokenId) external returns (uint256);
function getHorseGeneSC(uint256 tokenId) external returns (uint256);
function getHorseGender(uint256 tokenId) external returns (uint256);
function getHorseColor(uint256 tokenId) external returns (string memory);
function getHorseGene(uint256 tokenId) external returns (string memory);
function getTrainingTime(uint256 tokenId) external returns (uint256);
function getTrainingValue(uint256 tokenId) external returns (uint256);
function getEnergy(uint256 tokenId) external returns (uint256);
function getEnergyUpdateTime(uint256 tokenId) external returns (uint256);
function getGradeScore(uint256 tokenId) external returns (uint256);
function getGradeScoreMark(uint256 tokenId) external returns (uint256);
function getScoreUpdateTime(uint256 tokenId) external returns (uint256);
function getFather(uint256 tokenId) external view returns (uint256);
function getMother(uint256 tokenId) external view returns (uint256);
function getBreedCount(uint256 tokenId) external returns (uint256);
function getBreedTime(uint256 tokenId) external returns (uint256);
function getHeadWearId(uint256 tokenId) external returns (uint256);
function getArmorId(uint256 tokenId) external returns (uint256);
function getPonytailId(uint256 tokenId) external returns (uint256);
function getHoofId(uint256 tokenId) external returns (uint256);
function getGrade(uint256 tokenId) external returns (uint256);
function getRaceCount(uint256 tokenId) external returns (uint256);
function getWinCount(uint256 tokenId) external returns (uint256);
function getHorseRaceLastOwner(uint256 tokenId) external returns (address);
function getHorseRaceStatus(uint256 tokenId) external returns (uint256);
function getHorseRaceCoin(uint256 tokenId) external returns (uint256);
function getHorseRacePrice(uint256 tokenId) external returns (uint256);
function getHorseRaceDiscount(uint256 tokenId) external returns (uint256);
function getHorseRaceReward(uint256 tokenId) external returns (uint256);
function getHorseRaceLastPrice(uint256 tokenId) external returns (uint256);
function getSellUpdateTime(uint256 tokenId) external returns (uint256);
function getStudUpdateTime(uint256 tokenId) external returns (uint256);
function getRaceId(uint256 tokenId) external returns (uint256);
function getRaceType(uint256 tokenId) external returns (uint256);
function getRacecourse(uint256 tokenId) external returns (uint256);
function getDistance(uint256 tokenId) external returns (uint256);
function getRaceUpdateTime(uint256 tokenId) external returns (uint256);
function checkStatus(uint256[] calldata tokenIds, uint256 status) external returns (bool);
function checkGameInfo(uint256[] calldata tokenIds, uint256 types, uint256 raceId, uint256 racecourseId,
uint256 level, uint256 distance) external returns (bool);
function getUseTraTime(uint256 tokenId) external returns (uint256);
function setUseTraTime(uint256 tokenId, uint256 trainingTime) external returns (bool);
function setHorseGripGene(uint256 tokenId, string calldata gene) external returns (bool);
function setHorseAccGene(uint256 tokenId, string calldata gene) external returns (bool);
function setHorseEndGene(uint256 tokenId, string calldata gene) external returns (bool);
function setHorseSpdGene(uint256 tokenId, string calldata gene) external returns (bool);
function setHorseTurnGene(uint256 tokenId, string calldata gene) external returns (bool);
function setHorseContGene(uint256 tokenId, string calldata gene) external returns (bool);
function getHorseGripGene(uint256 tokenId) external returns (string memory);
function getHorseAccGene(uint256 tokenId) external returns (string memory);
function getHorseEndGene(uint256 tokenId) external returns (string memory);
function getHorseSpdGene(uint256 tokenId) external returns (string memory);
function getHorseTurnGene(uint256 tokenId) external returns (string memory);
function getHorseContGene(uint256 tokenId) external returns (string memory);
function getIntegral(uint256 tokenId) external returns (uint256);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
interface IRacecourseOpera {
function setCreateTime(uint256 tokenId, uint256 time) external returns (bool);
function setLever(uint256 tokenId, uint256 lever) external returns (bool);
function setRaceType(uint256 tokenId, uint256 raceType) external returns (bool);
function setDistance(uint256 tokenId, uint256 distance) external returns (bool);
function setStatus(uint256 tokenId, uint256 status) external returns (bool);
function getCreateTime(uint256 tokenId) external returns (uint256);
function getLever(uint256 tokenId) external returns (uint256);
function getRaceType(uint256 tokenId) external returns (uint256);
function getDistance(uint256 tokenId) external returns (uint256);
function getStatus(uint256 tokenId) external returns (uint256);
function delHorseId(uint256 tokenId) external returns (bool);
function delHorseIdBatch(uint256[] calldata tokenIds) external returns (bool);
function getHorseId(uint256 tokenId) external returns (uint256[] memory);
function checkHorseId(uint256 tokenId, uint256 horseId) external returns (bool);
}
// SPDX-License-Identifier: UNLICENSED // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.4; pragma solidity ^0.8.22;
// Uncomment this line to use console.log // Uncomment this line to use console.log
// import "hardhat/console.sol"; // import "hardhat/console.sol";
......
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
contract Admin is Initializable, OwnableUpgradeable {
mapping(address => bool) private _admins;
modifier onlyAdmin() {
require(_admins[msg.sender], "Only admin can call it");
_;
}
// constructor() {
// _disableInitializers();
// }
function admin_initialize() internal onlyInitializing {
__Ownable_init(msg.sender); // Initialize with the owner
_admins[msg.sender] = true; // Set the initial owner as admin
}
function addAdmin(address _admin) public onlyOwner {
_admins[_admin] = true;
}
function delAdmin(address _admin) public onlyOwner {
_admins[_admin] = false;
}
function isAdmin(address _addr) public view returns (bool) {
return _admins[_addr];
}
}
contract Program is Admin {
mapping(address => bool) private _programs;
modifier onlyProgram() {
require(_programs[msg.sender], "Only program can call it");
_;
}
function program_initialize() internal onlyInitializing {
admin_initialize();
}
function addProgram(address _program) public onlyOwner {
_programs[_program] = true;
}
function delProgram(address _program) public onlyOwner {
_programs[_program] = false;
}
function isProgram(address _program) public view returns (bool) {
return _programs[_program];
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import "@openzeppelin/contracts/utils/Address.sol";
import "./Auth.sol";
interface IERC20Token {
function decimals() external view returns (uint);
function totalSupply() external view returns (uint);
function balanceOf(address account) external view returns (uint);
function transfer(address recipient, uint amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint amount) external returns (bool);
function transferFrom(address sender, address recipient, uint amount) external returns (bool);
}
library SafeERC20Token {
using Address for address;
function safeTransfer(IERC20Token token, address to, uint256 value) internal {
callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(IERC20Token token, address from, address to, uint256 value) internal {
callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function callOptionalReturn(IERC20Token token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves.
// A Solidity high level call has three parts:
// 1. The target address is checked to verify it contains contract code
// 2. The call itself is made, and success asserted
// 3. The return value is decoded, which in turn checks the size of the returned data.
// solhint-disable-next-line max-line-length
// require(address(token).isContract(), "SafeERC20: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = address(token).call(data);
require(success, "SafeERC20: low-level call failed");
if (returndata.length > 0) {// Return data is optional
// solhint-disable-next-line max-line-length
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
contract Coin is Program {
using SafeERC20Token for IERC20Token;
mapping(uint256 => uint256) public priceOf;
mapping(uint256 => address) public addressOf;
mapping(address => bool) private minters;
function initialize() public initializer {
program_initialize();
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyMiner() {
require(minters[msg.sender], "!miner");
_;
}
function addMinter(address _minter) public onlyOwner {
minters[_minter] = true;
}
function removeMinter(address _minter) public onlyOwner {
minters[_minter] = false;
}
/**
* @dev Add supported token symbols, addresses and prices
*/
function add(uint256[] memory _coins, address[] memory _address, uint256[] memory _price) public onlyAdmin returns (bool) {
require(_coins.length == _address.length && _coins.length == _price.length && _coins.length <= 256, "Invalid parameters");
for (uint256 i = 0; i < _coins.length; i++) {
uint256 coin = _coins[i];
addressOf[coin] = _address[i];
priceOf[coin] = _price[i];
}
return true;
}
/**
* @dev Del supported token symbols, addresses and prices
*/
function del(uint256[] memory _coins) public onlyAdmin returns (bool) {
require(_coins.length > 0 && _coins.length <= 256, "Invalid parameters");
for (uint256 i = 0; i < _coins.length; i++) {
uint256 coin = _coins[i];
delete priceOf[coin];
delete addressOf[coin];
}
return true;
}
/**
* @dev update token prices
*/
function setPrice(uint256[] memory _coins, uint256[] memory _price) public onlyProgram returns (bool) {
require(_coins.length == _price.length && _coins.length <= 256, "Invalid parameters");
for (uint256 i = 0; i < _coins.length; i++) {
uint256 coin = _coins[i];
if (_price[i] != 0 && priceOf[coin] != 0) {
priceOf[coin] = _price[i];
}
}
return true;
}
/**
* @dev Price conversion
*/
function convert(uint256 _coinName, uint256 _usdAmount) public view returns (uint256) {
uint256 _decimals = 10 ** IERC20Token(addressOf[_coinName]).decimals();
return _decimals * _usdAmount / priceOf[_coinName];
}
function convert1(uint256 _coinName, uint256 _usdAmount) public view returns (uint256) {
uint256 _decimals = 10 ** IERC20Token(addressOf[_coinName]).decimals();
return _decimals * _usdAmount;
}
/**
* @dev Safe transfer from 'from' account to 'to' account
*/
function safeTransferFrom(uint256 _coinName, address from, address to, uint256 value) public onlyMiner {
require(addressOf[_coinName] != address(0), "Not supported coin!");
IERC20Token(addressOf[_coinName]).safeTransferFrom(from, to, convert(_coinName, value));
}
function safeTransferFrom1(uint256 _coinName, address from, address to, uint256 value) public onlyMiner {
require(addressOf[_coinName] != address(0), "Not supported coin!");
IERC20Token(addressOf[_coinName]).safeTransferFrom(from, to, convert1(_coinName, value));
}
/**
* @dev Safe transfer from 'this' account to 'to' account
*/
function safeTransfer(uint256 _coinName, address to, uint256 value) public onlyMiner {
require(addressOf[_coinName] != address(0), "Not supported coin!");
IERC20Token(addressOf[_coinName]).safeTransfer(to, convert(_coinName, value));
}
function safeTransfer1(uint256 _coinName, address to, uint256 value) public onlyMiner {
require(addressOf[_coinName] != address(0), "Not supported coin!");
IERC20Token(addressOf[_coinName]).safeTransfer(to, convert1(_coinName, value));
}
function safeTransferWei(uint256 _coinName, address to, uint256 value) public onlyMiner {
require(addressOf[_coinName] != address(0), "Not supported coin!");
IERC20Token(addressOf[_coinName]).safeTransfer(to, value);
}
function balanceOf(uint256 _coinName, address account) public view returns (uint256){
require(addressOf[_coinName] != address(0), "Not supported coin!");
uint256 balance = IERC20Token(addressOf[_coinName]).balanceOf(account);
return balance;
}
function decimals(uint256 _coinName) public view returns (uint) {
require(addressOf[_coinName] != address(0), "Not supported coin!");
uint d = IERC20Token(addressOf[_coinName]).decimals();
return d;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import "@openzeppelin/contracts/utils/Address.sol";
import "./Auth.sol";
interface IERC721Token {
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 safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
}
contract Coin721 is Program {
mapping(address => address) public addressOf;
mapping(address => bool) private minters;
function initialize() public initializer {
program_initialize();
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyMiner() {
require(minters[msg.sender], "!miner");
_;
}
function addMinter(address _minter) public onlyOwner {
minters[_minter] = true;
}
function removeMinter(address _minter) public onlyOwner {
minters[_minter] = false;
}
/**
* @dev Add supported token addresses
*/
function add(address[] memory _address) public onlyAdmin returns (bool) {
require(_address.length <= 256, "Invalid parameters");
for (uint256 i = 0; i < _address.length; i++) {
addressOf[_address[i]] = _address[i];
}
return true;
}
/**
* @dev Del supported addresses
*/
function del(address[] memory _coins) public onlyAdmin returns (bool) {
require(_coins.length > 0 && _coins.length <= 256, "Invalid parameters");
for (uint256 i = 0; i < _coins.length; i++) {
delete addressOf[_coins[i]];
}
return true;
}
/**
* @dev Safe transfer from 'from' account to 'to' account
*/
function safeTransferFrom(address token, address from, address to, uint256 tokenId) public onlyMiner {
require(addressOf[token] != address(0), "Not supported coin!");
IERC721Token(addressOf[token]).safeTransferFrom(from, to, tokenId);
}
function balanceOf(address token, address account) public view returns (uint256){
require(addressOf[token] != address(0), "Not supported coin!");
uint256 balance = IERC721Token(addressOf[token]).balanceOf(account);
return balance;
}
function ownerOf(address token, uint256 tokenId) public view returns (address) {
require(addressOf[token] != address(0), "Not supported coin!");
address owner = IERC721Token(addressOf[token]).ownerOf(tokenId);
return owner;
}
function onERC721Received(address, address, uint256, bytes calldata) external pure returns(bytes4) {
return bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"));
}
}
This diff is collapsed.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import "../library/Bytes.sol";
import "./Auth.sol";
import "../Interface/BaseInterface.sol";
contract ERC721Attr is Program {
using Bytes for bytes;
IERC721Token private tokenAddress;
// key => field => value.
// Record the fields and values corresponding to each contract
mapping(address => mapping(uint256 => mapping(string => bytes))) private values;
// field => types.
// Define fields and types
mapping(address => mapping(string => uint256)) private fieldsType;
// field => auth.
// Define the modification permissions of the field.
// 1 =>onlyAdmin, 2 => onlyProgram, 3 => owner
mapping(address => mapping(string => uint256)) private fieldsAuth;
// field => value => true.
// Record has only required fields
mapping(address => mapping(string => mapping(bytes => bool))) private uniques;
// 记录数组。
// tokenId ===> field ===> 索引
mapping(uint256 => mapping(string => uint256)) private index;
// tokenId ===> field ===> 索引 ===> 值
mapping(uint256 => mapping(string => mapping(uint256 => bytes))) private arrayValue;
modifier checkAuth(string memory fields, address addr, uint256 tokenId) {
uint256 auth = fieldsAuth[addr][fields];
if (auth == 1) {
require(isAdmin(msg.sender), "only admin");
} else if (auth == 2) {
require(isProgram(msg.sender), "only program");
} else if (auth == 3) {
tokenAddress = IERC721Token(addr);
require(tokenAddress.ownerOf(tokenId) == msg.sender, "only owner");
} else if (auth == 0) {
require(false, "Invalid field");
}
_;
}
function initialize() public initializer {
program_initialize();
}
// 初始化参数,参数名称、参数类型、参数修改权限(1 admin,2 program,3 拥有者)
function setFiled(address addr, string[] memory field, uint256[] memory types, uint256[] memory auth) public onlyAdmin returns (bool) {
require(field.length > 0 && field.length <= 256, "Invalid parameters");
require(field.length == types.length && field.length == auth.length, "Invalid parameters");
for (uint256 i = 0; i < field.length; i++) {
bool result = _setFiled(addr, field[i], types[i], auth[i]);
require(result, "setFiled error");
}
return true;
}
function setValues(address addr, uint256 tokenId, string memory field, bytes memory value) public checkAuth(field, addr, tokenId) returns (bool) {
bool result = _setValue(addr, tokenId, field, value);
return result;
}
function setUniques(address addr, string memory field, bytes memory value) public onlyProgram returns (bool) {
require(!uniques[addr][field][value], "Uniqueness verification failed");
bool result = _setUniques(addr, field, value, true);
return result;
}
function clearUniques(address addr, string memory field, bytes memory value) public onlyProgram returns (bool) {
require(uniques[addr][field][value], "Uniqueness verification failed");
bool result = _setUniques(addr, field, value, false);
delete uniques[addr][field][value];
return result;
}
function delFiled(address addr, string memory field) public onlyAdmin returns (bool) {
bool result = _delFiled(addr, field);
return result;
}
function delValues(address addr, uint256 tokenId, string memory field) public checkAuth(field, addr, tokenId) returns (bool) {
bool result = _delValue(addr, tokenId, field);
return result;
}
// function delUniques(address addr, string memory field) public onlyProgram returns (bool) {
// _delUniques(field);
// return true;
// }
function _setValue(address addr, uint256 tokenId, string memory field, bytes memory value) internal returns (bool){
values[addr][tokenId][field] = value;
return true;
}
function _setUniques(address addr, string memory field, bytes memory value, bool b) internal returns (bool){
uniques[addr][field][value] = b;
return true;
}
function _setFiled(address addr, string memory field, uint256 types, uint256 auth) internal returns (bool){
fieldsType[addr][field] = types;
fieldsAuth[addr][field] = auth;
return true;
}
function _delFiled(address addr, string memory field) internal returns (bool){
delete fieldsType[addr][field];
delete fieldsAuth[addr][field];
return true;
}
function _delValue(address addr, uint256 tokenId, string memory field) internal returns (bool){
delete values[addr][tokenId][field];
return true;
}
function getValue(address addr, uint256 tokenId, string memory field) public view returns (bytes memory result){
return values[addr][tokenId][field];
}
function getAuth(address addr, string memory field) public view returns (uint256){
return fieldsAuth[addr][field];
}
function getType(address addr, string memory field) public view returns (uint256){
return fieldsType[addr][field];
}
function getUniques(address addr, string memory field, bytes memory value) public view returns (bool){
return uniques[addr][field][value];
}
function setArrayValue(uint256 tokenId, string memory field, bytes memory value) public onlyProgram returns (bool){
uint256 count = index[tokenId][field];
arrayValue[tokenId][field][count] = value;
index[tokenId][field] = count + 1;
return true;
}
function delArrayValue(uint256 tokenId, string memory field) public onlyProgram returns (bool){
uint256 count = index[tokenId][field];
for (uint256 i = 0; i < count; i++) {
delete arrayValue[tokenId][field][i];
}
delete index[tokenId][field];
return true;
}
function removeArrayValue(uint256 tokenId, string memory field, bytes memory value) public onlyProgram returns (bool){
uint256 count = index[tokenId][field];
bool isOn;
for (uint256 i = 0; i < count; i++) {
if (keccak256(value) == keccak256(arrayValue[tokenId][field][i])) {
isOn = true;
continue;
}
if (isOn) {
bytes memory oldValue = arrayValue[tokenId][field][i];
arrayValue[tokenId][field][i - 1] = oldValue;
}
}
if (isOn) {
index[tokenId][field] = count - 1;
}
return true;
}
function checkArrayValue(uint256 tokenId, string memory field, bytes memory value) public view onlyProgram returns (bool){
uint256 count = index[tokenId][field];
for (uint256 i = 0; i < count; i++) {
if (keccak256(value) == keccak256(arrayValue[tokenId][field][i])) {
return true;
}
}
return false;
}
function getArrayValue(uint256 tokenId, string memory field) public view returns (uint256[] memory){
uint256 count = index[tokenId][field];
uint256[] memory arr = new uint256[](count);
for (uint256 i = 0; i < count; i++) {
bytes memory id = arrayValue[tokenId][field][i];
arr[i] = id.BytesToUint256();
}
return arr;
}
function getArrayCount(uint256 tokenId, string memory field) public view returns (uint256){
return index[tokenId][field];
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import "@openzeppelin/contracts/utils/math/Math.sol";
import "../Interface/IERC721Attr.sol";
import "../Interface/IERC721Token.sol";
import "../Interface/IConstant.sol";
import "../Interface/ICoin.sol";
import "./Auth.sol";
import "../library/Bytes.sol";
import "hardhat/console.sol";
interface IArenaOpera {
function setHorseFactName(uint256 tokenId, string calldata name) external returns (bool);
function setCreateTime(uint256 tokenId, uint256 time) external returns (bool);
function setHorseFactTypes(uint256 tokenId, uint256 types) external returns (bool);
function setFactoryStatus(uint256 tokenId, uint256 status) external returns (bool);
function setMortAmount(uint256 tokenId, uint256 amount) external returns (bool);
function getCreateTime(uint256 tokenId) external returns (uint256);
function getMortAmount(uint256 tokenId) external returns (uint256);
}
contract HorseArenaContract is Program {
using Math for uint256;
using Bytes for bytes;
ICoin private _coin; // 抵押token合约地址
IArenaOpera private _opera;
IERC721Token private _arenaTokenAddress;
IConstant private _constant; // 常量合约地址
event MintArena(address account, uint256 tokenId, uint256 time, uint256 types, uint256 mortAmount, string name, uint256 status);
event CloseArena(address account, uint256 tokenId, uint256 time, uint256 mortAmount, uint256 status);
event ArenaTransfer(address from, address to, uint256 tokenId, uint256 time);
modifier checkAuth(uint256 tokenId) {
require(_arenaTokenAddress.ownerOf(tokenId) == msg.sender, "only owner can do it!");
_;
}
modifier senderIsToken() {
require(msg.sender == address(_arenaTokenAddress), "only token contract can do it");
_;
}
function initialize() public initializer {
program_initialize();
}
function init(address operaAddr, address tokenAddr, address coinAddr, address consAddr) public onlyAdmin returns (bool){
_opera = IArenaOpera(operaAddr);
_arenaTokenAddress = IERC721Token(tokenAddr);
_coin = ICoin(coinAddr);
_constant = IConstant(consAddr);
return true;
}
// 生成马场:type : 0 官方的, 1 私人的
function _mintArena(string memory name, bytes memory sign, uint256 types) internal returns (uint256) {
require(sign.Decode(name) == _constant.getAccount(), "Signature verification failure");
require(types == 0 || types == 1, "invalid arena type");
_coin.safeTransferFrom1(_constant.getMortToken(), msg.sender, address(_coin), _constant.getMortAmount());
uint256 tokenId = _arenaTokenAddress.mint(msg.sender);
_opera.setHorseFactName(tokenId, name);
_opera.setCreateTime(tokenId, block.timestamp);
_opera.setHorseFactTypes(tokenId, types);
_opera.setFactoryStatus(tokenId, 1);
_opera.setMortAmount(tokenId, _constant.getMortAmount());
emit MintArena(msg.sender, tokenId, block.timestamp, types, _constant.getMortAmount(), name, 1);
return tokenId;
}
function mintOfficialArena(string memory name, bytes memory sign) public onlyAdmin() {
_mintArena(name, sign, 0);
}
// 抵押增发赛场
function mintArena(string memory name, bytes memory sign) public returns (uint256) {
return _mintArena(name, sign, 1);
}
// 关闭赛场
function closeArena(uint256 tokenId) public checkAuth(tokenId) returns (bool) {
uint256 current = block.timestamp;
uint256 spacing = current - (_opera.getCreateTime(tokenId));
require(spacing > _constant.getMinMortTime(), "Must not be less than the minimum mortgage time");
uint256 mortAmount = _opera.getMortAmount(tokenId);
_coin.safeTransfer1(_constant.getMortToken(), msg.sender, mortAmount);
_opera.setFactoryStatus(tokenId, 2);
_arenaTokenAddress.safeTransferFrom(msg.sender, address(_arenaTokenAddress), tokenId);
emit CloseArena(msg.sender, tokenId, block.timestamp, mortAmount, 2);
return true;
}
function beforeTransfer(address from, address to, uint256) public view senderIsToken returns (bool) {
// no need more handler.
if (_constant.isOfficialContract(from) || _constant.isOfficialContract(to)) {
//console.log("no need handler for arena extra contract transfer");
} else {
// nothing to do.
}
return true;
}
function afterTransfer(address from, address to, uint256 tokenId) public senderIsToken returns (bool) {
if (_constant.isOfficialContract(from) || _constant.isOfficialContract(to)) {
//console.log("no need handler for arena extra contract transfer");
} else {
console.log("emit event arenatransfer");
emit ArenaTransfer(from, to, tokenId,block.timestamp);
}
return true;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import "../Interface/IERC721Attr.sol";
import "../Interface/IERC721Token.sol";
import "../library/Bytes.sol";
import "../library/Uint256.sol";
import "../library/String.sol";
import "../library/Address.sol";
import "./Auth.sol";
contract HorseArenaAttrOperaContract is Program {
using Uint256 for uint256;
using String for string;
using Address for address;
using Bytes for bytes;
IERC721Attr private _horseFactoryAttrAddress;
IERC721Token private _horseFactoryTokenAddress;
string public _name; //名称
string public _createTime; //创建日期
string public _ownerType; //类型
string public _isClose; // 是否关闭
string public _raceCount; //当天开赛次数,私人赛场每天有次数限制
string public _lastRaceTime; //最后一次开赛时间
string public _totalRaceCount; //总开赛次数
string public _mortAmount; //抵押金额
string public _gameId; //比赛的id
string public _horseIds; //比赛的id
modifier checkOwnerTypeValue(uint256 ownerType) {
if (ownerType == 0 || ownerType == 1) {
require(true, "Legal field value");
} else {
require(false, "Invalid field value");
}
_;
}
modifier checkAuth(uint256 tokenId) {
require(_horseFactoryTokenAddress.ownerOf(tokenId) == msg.sender, "only owner can do it!");
_;
}
function initialize() public initializer {
program_initialize();
_name = "name";//名称
_createTime = "createTime";//创建日期
_ownerType = "ownerType";//类型
_isClose = "isClose"; // 是否关闭
_raceCount = "raceCount";//当天开赛次数,私人赛场每天有次数限制
_lastRaceTime = "lastRaceTime";//最后一次开赛时间
_totalRaceCount = "totalRaceCount";//总开赛次数
_mortAmount = "mortAmount";//抵押金额
_gameId = "gameId";//比赛的id
_horseIds = "horseIds";//比赛的id
}
function init(address factoryAttrAddress, address factoryToken) public onlyAdmin returns (bool) {
_horseFactoryAttrAddress = IERC721Attr(factoryAttrAddress);
_horseFactoryTokenAddress = IERC721Token(factoryToken);
return true;
}
function setHorseFactName(uint256 tokenId, string memory name) public onlyProgram returns (bool) {
bytes memory nameBytes = name.StringToBytes();
bool boo = _horseFactoryAttrAddress.getUniques(address(_horseFactoryTokenAddress), _name, nameBytes);
require(!boo, "Name already used");
bool result = _horseFactoryAttrAddress.setValues(address(_horseFactoryTokenAddress), tokenId, _name, nameBytes);
_horseFactoryAttrAddress.setUniques(address(_horseFactoryTokenAddress), _name, nameBytes);
return result;
}
function setCreateTime(uint256 tokenId, uint256 time) public onlyProgram returns (bool) {
bool result = _horseFactoryAttrAddress.setValues(address(_horseFactoryTokenAddress), tokenId, _createTime, time.Uint256ToBytes());
return result;
}
function setHorseFactTypes(uint256 tokenId, uint256 types) public onlyProgram returns (bool) {
bool result = _horseFactoryAttrAddress.setValues(address(_horseFactoryTokenAddress), tokenId, _ownerType, types.Uint256ToBytes());
return result;
}
function setFactoryStatus(uint256 tokenId, uint256 status) public onlyProgram returns (bool) {
bool result = _horseFactoryAttrAddress.setValues(address(_horseFactoryTokenAddress), tokenId, _isClose, status.Uint256ToBytes());
return result;
}
function setRaceCount(uint256 tokenId, uint256 count) public onlyProgram returns (bool) {
bool result = _horseFactoryAttrAddress.setValues(address(_horseFactoryTokenAddress), tokenId, _raceCount, count.Uint256ToBytes());
return result;
}
function uptTotalRaceCount(uint256 tokenId, uint256 count) public onlyProgram returns (bool) {
bool result = _horseFactoryAttrAddress.setValues(address(_horseFactoryTokenAddress), tokenId, _totalRaceCount, count.Uint256ToBytes());
return result;
}
function setLastRaceTime(uint256 tokenId, uint256 time) public onlyProgram returns (bool) {
bool result = _horseFactoryAttrAddress.setValues(address(_horseFactoryTokenAddress), tokenId, _lastRaceTime, time.Uint256ToBytes());
return result;
}
function setMortAmount(uint256 tokenId, uint256 amount) public onlyProgram returns (bool) {
bool result = _horseFactoryAttrAddress.setValues(address(_horseFactoryTokenAddress), tokenId, _mortAmount, amount.Uint256ToBytes());
return result;
}
function getFactoryName(uint256 tokenId) public view returns (string memory){
bytes memory bytesInfo = _horseFactoryAttrAddress.getValue(address(_horseFactoryTokenAddress), tokenId, _name);
return bytesInfo.BytesToString();
}
function getCreateTime(uint256 tokenId) public view returns (uint256){
bytes memory bytesInfo = _horseFactoryAttrAddress.getValue(address(_horseFactoryTokenAddress), tokenId, _createTime);
return bytesInfo.BytesToUint256();
}
function getOwnerType(uint256 tokenId) public view returns (uint256){
bytes memory bytesInfo = _horseFactoryAttrAddress.getValue(address(_horseFactoryTokenAddress), tokenId, _ownerType);
return bytesInfo.BytesToUint256();
}
function getIsClose(uint256 tokenId) public view returns (uint256){
bytes memory bytesInfo = _horseFactoryAttrAddress.getValue(address(_horseFactoryTokenAddress), tokenId, _isClose);
return bytesInfo.BytesToUint256();
}
function getRaceCount(uint256 tokenId) public view returns (uint256){
bytes memory bytesInfo = _horseFactoryAttrAddress.getValue(address(_horseFactoryTokenAddress), tokenId, _raceCount);
return bytesInfo.BytesToUint256();
}
function getLastRaceTime(uint256 tokenId) public view returns (uint256){
bytes memory bytesInfo = _horseFactoryAttrAddress.getValue(address(_horseFactoryTokenAddress), tokenId, _lastRaceTime);
return bytesInfo.BytesToUint256();
}
function getTotalRaceCount(uint256 tokenId) public view returns (uint256){
bytes memory bytesInfo = _horseFactoryAttrAddress.getValue(address(_horseFactoryTokenAddress), tokenId, _totalRaceCount);
return bytesInfo.BytesToUint256();
}
function getMortAmount(uint256 tokenId) public view returns (uint256){
bytes memory bytesInfo = _horseFactoryAttrAddress.getValue(address(_horseFactoryTokenAddress), tokenId, _mortAmount);
return bytesInfo.BytesToUint256();
}
function setGameId(uint256 tokenId, uint256 gameId) public onlyProgram returns (bool) {
bool result = _horseFactoryAttrAddress.setArrayValue(tokenId, _gameId, gameId.Uint256ToBytes());
return result;
}
function setHorseId(uint256 tokenId, uint256 horseId) public onlyProgram returns (bool) {
bool result = _horseFactoryAttrAddress.setArrayValue(tokenId, _horseIds, horseId.Uint256ToBytes());
return result;
}
function checkGameId(uint256 tokenId, uint256 gameId) public view returns (bool){
bool result = _horseFactoryAttrAddress.checkArrayValue(tokenId, _gameId, gameId.Uint256ToBytes());
return result;
}
function checkGameIdIsExit(uint256 gameId) public view returns (bool){
bytes memory idBytes = gameId.Uint256ToBytes();
bool boo = _horseFactoryAttrAddress.getUniques(address(_horseFactoryTokenAddress), _gameId, idBytes);
return boo;
}
function setGameIdUniques(uint256 gameId) public onlyProgram returns (bool) {
bytes memory idBytes = gameId.Uint256ToBytes();
bool boo = _horseFactoryAttrAddress.setUniques(address(_horseFactoryTokenAddress), _gameId, idBytes);
return boo;
}
function clearGameIdUniques(uint256 gameId) public onlyProgram returns (bool) {
bytes memory idBytes = gameId.Uint256ToBytes();
bool boo = _horseFactoryAttrAddress.setUniques(address(_horseFactoryTokenAddress), _gameId, idBytes);
return boo;
}
function checkHorseId(uint256 tokenId, uint256 horseId) public view returns (bool){
bool result = _horseFactoryAttrAddress.checkArrayValue(tokenId, _horseIds, horseId.Uint256ToBytes());
return result;
}
function getHorseIdCount(uint256 tokenId) public view returns (uint256){
uint256 count = _horseFactoryAttrAddress.getArrayCount(tokenId, _horseIds);
return count;
}
function delHorseIdOne(uint256 tokenId, uint256 horseId) public onlyProgram returns (bool) {
bool result = _horseFactoryAttrAddress.removeArrayValue(tokenId, _horseIds, horseId.Uint256ToBytes());
return result;
}
}
This diff is collapsed.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import "@openzeppelin/contracts/utils/math/Math.sol";
import "../Interface/ICoin.sol";
import "../Interface/IConstant.sol";
import "./Auth.sol";
interface IHorseRaceOpera {
function setHorseStatusBatch(uint256[] calldata tokenId, uint256 status) external returns (bool);
function setHorseStatus(uint256 tokenId, uint256 status) external returns (bool);
function setRaceUpdateTime(uint256 tokenId, uint256 raceUpdateTime) external returns (bool);
function getBirthDay(uint256 tokenId) external returns (uint256);
function getHorseRaceStatus(uint256 tokenId) external returns (uint256);
function getRaceUpdateTime(uint256 tokenId) external returns (uint256);
function setRaceId(uint256 tokenId, uint256 raceId) external returns (bool);
function setRaceIdBatch(uint256[] calldata tokenIds, uint256 raceId) external returns (bool);
function setRaceType(uint256 tokenId, uint256 raceType) external returns (bool);
function setRacecourse(uint256 tokenId, uint256 racecourse) external returns (bool);
function setDistance(uint256 tokenId, uint256 distance) external returns (bool);
function getGrade(uint256 tokenId) external returns (uint256);
function getRacecourse(uint256 tokenId) external returns (uint256);
function checkStatus(uint256[] calldata tokenIds, uint256 status) external returns (bool);
function checkGameInfo(uint256[] calldata tokenIds, uint256 types, uint256 racecourseId,
uint256 level, uint256 distance) external returns (bool);
function getDistance(uint256 tokenId) external returns (uint256);
}
interface IERC721Token {
function ownerOf(uint256 tokenId) external view returns (address owner);
}
interface IRacecourseOpera {
function setHorseId(uint256 tokenId, uint256 horseId) external returns (bool);
function getHorseId(uint256 tokenId) external returns (uint256[] memory);
function delHorseId(uint256 tokenId) external returns (bool);
}
interface IArenaOpera {
function getIsClose(uint256 tokenId) external returns (uint256);
function checkGameIdIsExit(uint256 gameId) external returns (bool);
function setGameIdUniques(uint256 gameId) external returns (bool);
function getHorseIdCount(uint256 tokenId) external returns (uint256);
function setHorseId(uint256 tokenId, uint256 horseId) external returns (bool);
function delHorseIdOne(uint256 tokenId, uint256 horseId) external returns (bool);
function checkGameId(uint256 tokenId, uint256 gameId) external returns (bool);
function checkHorseId(uint256 tokenId, uint256 gameId) external returns (bool);
function getRaceCount(uint256 tokenId) external returns (uint256);
function getTotalRaceCount(uint256 tokenId) external returns (uint256);
function getLastRaceTime(uint256 tokenId) external returns (uint256);
function getOwnerType(uint256 tokenId) external returns (uint256);
function setRaceCount(uint256 tokenId, uint256 count) external returns (bool);
function setGameId(uint256 tokenId, uint256 gameId) external returns (bool);
function uptTotalRaceCount(uint256 tokenId, uint256 count) external returns (bool);
function setLastRaceTime(uint256 tokenId, uint256 time) external returns (bool);
}
contract HorseArenaExtra2 is Program {
using Math for uint256;
ICoin private _coin; // 抵押token合约地址
IArenaOpera private _opera;
IHorseRaceOpera private _horseOpera1_1;
IHorseRaceOpera private _horseOpera2;
IHorseRaceOpera private _horseOpera2_1;
IConstant private _constant; // 常量合约地址
IERC721Token private _horseTokenAddress;
event ApplyGame(address account, uint256 horseId, uint256 arenaId, uint256 raceType, uint256 distance,
uint256 time, uint256 status);
event CancelApplyGame(address account, uint256 horseId, uint256 status, uint256 time, uint256 arenaId, uint256 gameId,
uint256 raceType, uint256 distance);
event WeekScoreRank(uint256[] horseId, uint256[] totalScore, address[] accounts, uint256[] rank);
event MonthScoreRank(uint256[] horseId, uint256[] totalScore, address[] accounts, uint256[] rank);
event YearsScoreRank(uint256[] horseId, uint256[] totalScore, address[] accounts, uint256[] rank);
modifier checkAuth(uint256 tokenId) {
require(_horseTokenAddress.ownerOf(tokenId) == msg.sender, "only owner can do it!");
_;
}
function initialize() public initializer {
program_initialize();
}
function init(address operaAddr, address coinAddr, address horseTokenAddress,
address horseOpera1_1, address horseOpera2, address horseOpera2_1, address consAddr) public onlyAdmin returns (bool){
_opera = IArenaOpera(operaAddr);
_coin = ICoin(coinAddr);
_horseOpera1_1 = IHorseRaceOpera(horseOpera1_1);
_horseOpera2 = IHorseRaceOpera(horseOpera2);
_horseOpera2_1 = IHorseRaceOpera(horseOpera2_1);
_constant = IConstant(consAddr);
_horseTokenAddress = IERC721Token(horseTokenAddress);
return true;
}
// 报名比赛。
function applyGame(uint256 tokenId, uint256 horseId,
uint256 raceType, uint256 distance, uint256 level) public checkAuth(horseId) {
require(_opera.getIsClose(tokenId) == 1, "The stadium is closed");
require(_horseOpera2_1.getHorseRaceStatus(horseId) == _constant.getResting(), "Abnormal state");
require(_horseOpera2_1.getGrade(horseId) == level, "Level mismatch");
require(_opera.getHorseIdCount(tokenId) <= _constant.getMaxApplyCount(), "The maximum number of apply game is exceeded");
require(level == 999 ? distance == 1200 : true, "unmatched horselevel and distance");
// 成长时间
uint256 spacing = block.timestamp - (_horseOpera2.getBirthDay(horseId));
require(spacing > _constant.getMinMatureTime(), "Immature horses");
// 多次操作冷却时间
uint256 raceSpacing = block.timestamp - (_horseOpera2_1.getRaceUpdateTime(horseId));
require(raceSpacing > _constant.getMinRaceUptTime(), "Cooling time");
// 大奖赛需要报名费
if (level != 999) {
_coin.safeTransferFrom1(_constant.getApplyGameToken(), msg.sender, address(_coin), _constant.getApplyGameAmountByDistance(distance));
}
_opera.setHorseId(tokenId, horseId);
// 修改马匹状态为报名中,记录马匹报名信息
_horseOpera1_1.setHorseStatus(horseId, _constant.getSigning());
_horseOpera1_1.setRaceType(horseId, raceType);
_horseOpera1_1.setRacecourse(horseId, tokenId);
_horseOpera1_1.setDistance(horseId, distance);
_horseOpera1_1.setRaceUpdateTime(horseId, block.timestamp);
emit ApplyGame(msg.sender, horseId, tokenId, raceType, distance, block.timestamp, _constant.getSigning());
}
// 取消报名
function cancelApplyGame(uint256 horseId) public checkAuth(horseId) {
require(_horseOpera2_1.getHorseRaceStatus(horseId) == 3, "Abnormal state");
// 多次操作冷却时间
uint256 raceSpacing = block.timestamp - (_horseOpera2_1.getRaceUpdateTime(horseId));
require(raceSpacing > _constant.getMinRaceUptTime(), "Cooling time");
// 大奖赛需要退还报名费
uint256 level = _horseOpera2_1.getGrade(horseId);
if (level != 999) {
uint256 distance = _horseOpera2_1.getDistance(horseId);
_coin.safeTransfer1(_constant.getApplyGameToken(), msg.sender, _constant.getApplyGameAmountByDistance(distance));
}
// 修改马匹状态为休息中,记录马匹报名信息,逻辑删除
_opera.delHorseIdOne(_horseOpera2_1.getRacecourse(horseId), horseId);
_horseOpera1_1.setHorseStatus(horseId, _constant.getResting());
_horseOpera1_1.setRaceId(horseId, 0);
_horseOpera1_1.setRaceType(horseId, 0);
_horseOpera1_1.setRacecourse(horseId, 0);
_horseOpera1_1.setDistance(horseId, 0);
_horseOpera1_1.setRaceUpdateTime(horseId, block.timestamp);
emit CancelApplyGame(msg.sender, horseId, _constant.getResting(), block.timestamp, 0, 0, 0, 0);
}
function _check(uint256 tokenId, uint256[] memory horseId) internal {
for (uint256 i = 0; i < horseId.length; i++) {
require(_opera.checkHorseId(tokenId, horseId[i]), "Abnormal state");
}
}
function weekRank(
uint256[] memory horseIds,
uint256[] memory totalScores,
address[] memory accounts,
uint256[] memory rank) public onlyProgram {
require(horseIds.length == totalScores.length || horseIds.length == accounts.length ||
horseIds.length == rank.length, "The parameter length is inconsistent");
emit WeekScoreRank(horseIds, totalScores, accounts, rank);
}
function monthRank(
uint256[] memory horseIds,
uint256[] memory totalScores,
address[] memory accounts,
uint256[] memory rank) public onlyProgram {
require(horseIds.length == totalScores.length || horseIds.length == accounts.length ||
horseIds.length == rank.length, "The parameter length is inconsistent");
emit MonthScoreRank(horseIds, totalScores, accounts, rank);
}
function yearsRank(
uint256[] memory horseIds,
uint256[] memory totalScores,
address[] memory accounts,
uint256[] memory rank) public onlyProgram {
require(horseIds.length == totalScores.length || horseIds.length == accounts.length ||
horseIds.length == rank.length, "The parameter length is inconsistent");
emit YearsScoreRank(horseIds, totalScores, accounts, rank);
}
}
This diff is collapsed.
This diff is collapsed.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import "../Interface/IERC721Attr.sol";
import "../Interface/IERC721Token.sol";
import "../library/Bytes.sol";
import "../library/Uint256.sol";
import "../library/String.sol";
import "../library/Address.sol";
import "./Auth.sol";
contract HorseEquipAttrOperaContract is Program {
using Uint256 for uint256;
using String for string;
using Address for address;
using Bytes for bytes;
IERC721Attr private _horseEquipAttrAddress;
IERC721Token private _horseEquipTokenAddress;
string public _horseEquipTypes;
string public _horseEquipStyle;
string public _horseEquipStatus;
string public _horseEquipPrice; // 出售价格
string public _horseEquipOfUid;
string public _horseEquipOfHorseId;
string public _horseEquipDiscount;
string public _horseEquipReward;
string public _horseEquipCoin;
string public _horseEquipLastOwner; // 最后一次操作者
string public _horseEquipLastPrice; // 最后一次成交价格
string public _lastOperaTime; // 最后操作时间
modifier checkEquipTypesValue(uint256 equip_types) {
if (equip_types == 1 || equip_types == 2 || equip_types == 3 || equip_types == 4) {
require(true, "Legal field value");
} else {
require(false, "Invalid field value");
}
_;
}
modifier checkEquipStyleValue(uint256 equip_style) {
if (equip_style == 1 || equip_style == 2 || equip_style == 3 || equip_style == 4 || equip_style == 5) {
require(true, "Legal field value");
} else {
require(false, "Invalid field value");
}
_;
}
modifier checkSellAuth(uint256 tokenId) {
require(_horseEquipTokenAddress.ownerOf(tokenId) == msg.sender, "only owner can do it!");
_;
}
function initialize() public initializer {
program_initialize();
_horseEquipTypes = "horseEquipTypes";
_horseEquipStyle = "horseEquipStyle";
_horseEquipStatus = "horseEquipStatus";
_horseEquipPrice = "horseEquipPrice"; // 出售价格
_horseEquipOfUid = "horseEquipOfUid";
_horseEquipOfHorseId = "horseEquipOfHorseId";
_horseEquipDiscount = "horseEquipDiscount";
_horseEquipReward = "horseEquipReward";
_horseEquipCoin = "horseEquipCoin";
_horseEquipLastOwner = "horseEquipLastOwner"; // 最后一次操作者
_horseEquipLastPrice = "horseEquipLastPrice"; // 最后一次成交价格
_lastOperaTime = "lastOperaTime"; // 最后操作时间
}
function init(address equipAttrAddress, address horseEquipToken) public onlyAdmin returns (bool) {
_horseEquipAttrAddress = IERC721Attr(equipAttrAddress);
_horseEquipTokenAddress = IERC721Token(horseEquipToken);
return true;
}
function setEquipStatus(uint256 tokenId, uint256 status) public onlyProgram returns (bool) {
bool result = _horseEquipAttrAddress.setValues(address(_horseEquipTokenAddress), tokenId, _horseEquipStatus, status.Uint256ToBytes());
return result;
}
function setEquipStatusBatch(uint256[] memory tokenIds, uint256 status) public onlyProgram returns (bool) {
require(tokenIds.length <= 256, "Invalid parameters");
for (uint256 i = 0; i < tokenIds.length; i++) {
bool result = _horseEquipAttrAddress.setValues(address(_horseEquipTokenAddress), tokenIds[i], _horseEquipStatus, status.Uint256ToBytes());
require(result, "setEquipStatus error");
}
return true;
}
function setEquipTypes(uint256 tokenId, uint256 types) public onlyProgram returns (bool) {
bool result = _horseEquipAttrAddress.setValues(address(_horseEquipTokenAddress), tokenId, _horseEquipTypes, types.Uint256ToBytes());
return result;
}
function setEquipStyle(uint256 tokenId, uint256 style) public onlyProgram returns (bool) {
bool result = _horseEquipAttrAddress.setValues(address(_horseEquipTokenAddress), tokenId, _horseEquipStyle, style.Uint256ToBytes());
return result;
}
function setEquipPrice(uint256 tokenId, uint256 price) public onlyProgram returns (bool) {
bool result = _horseEquipAttrAddress.setValues(address(_horseEquipTokenAddress), tokenId, _horseEquipPrice, price.Uint256ToBytes());
return result;
}
function setEquipOfHorseId(uint256 tokenId, uint256 horseId) public onlyProgram returns (bool) {
bool result = _horseEquipAttrAddress.setValues(address(_horseEquipTokenAddress), tokenId, _horseEquipOfHorseId, horseId.Uint256ToBytes());
return result;
}
function setEquipDis(uint256 tokenId, uint256 discount) public onlyProgram returns (bool) {
bool result = _horseEquipAttrAddress.setValues(address(_horseEquipTokenAddress), tokenId, _horseEquipDiscount, discount.Uint256ToBytes());
return result;
}
function setEquipReward(uint256 tokenId, uint256 reward) public onlyProgram returns (bool) {
bool result = _horseEquipAttrAddress.setValues(address(_horseEquipTokenAddress), tokenId, _horseEquipReward, reward.Uint256ToBytes());
return result;
}
function setEquipCoin(uint256 tokenId, uint256 coin) public onlyProgram returns (bool) {
bool result = _horseEquipAttrAddress.setValues(address(_horseEquipTokenAddress), tokenId, _horseEquipCoin, coin.Uint256ToBytes());
return result;
}
function setLastOperaTime1(uint256 tokenId, uint256 operaTime) public onlyProgram returns (bool) {
bool result = _horseEquipAttrAddress.setValues(address(_horseEquipTokenAddress), tokenId, _lastOperaTime, operaTime.Uint256ToBytes());
return result;
}
function setLastOperaTime2(uint256 tokenId) public onlyProgram returns (bool) {
bool result = _horseEquipAttrAddress.setValues(address(_horseEquipTokenAddress), tokenId, _lastOperaTime, block.timestamp.Uint256ToBytes());
return result;
}
function setEquipLastOwner(uint256 tokenId, address addr) public onlyProgram returns (bool) {
bool result = _horseEquipAttrAddress.setValues(address(_horseEquipTokenAddress), tokenId, _horseEquipLastOwner, addr.AddressToBytes());
return result;
}
function setEquipLastPrice(uint256 tokenId, uint256 price) public onlyProgram returns (bool) {
bool result = _horseEquipAttrAddress.setValues(address(_horseEquipTokenAddress), tokenId, _horseEquipLastPrice, price.Uint256ToBytes());
return result;
}
function getLastOperaTime(uint256 tokenId) public view returns (uint256){
bytes memory timeBytes = _horseEquipAttrAddress.getValue(address(_horseEquipTokenAddress), tokenId, _lastOperaTime);
return timeBytes.BytesToUint256();
}
function getHorseEquipLastOwner(uint256 tokenId) public view returns (address){
bytes memory ownerBytes = _horseEquipAttrAddress.getValue(address(_horseEquipTokenAddress), tokenId, _horseEquipLastOwner);
return ownerBytes.BytesToAddress();
}
function getHorseEquipStatus(uint256 tokenId) public view returns (uint256){
bytes memory statusBytes = _horseEquipAttrAddress.getValue(address(_horseEquipTokenAddress), tokenId, _horseEquipStatus);
return statusBytes.BytesToUint256();
}
function getHorseEquipCoin(uint256 tokenId) public view returns (uint256){
bytes memory coinBytes = _horseEquipAttrAddress.getValue(address(_horseEquipTokenAddress), tokenId, _horseEquipCoin);
return coinBytes.BytesToUint256();
}
function getHorseEquipPrice(uint256 tokenId) public view returns (uint256){
bytes memory priceBytes = _horseEquipAttrAddress.getValue(address(_horseEquipTokenAddress), tokenId, _horseEquipPrice);
return priceBytes.BytesToUint256();
}
function getHorseEquipDiscount(uint256 tokenId) public view returns (uint256){
bytes memory DisBytes = _horseEquipAttrAddress.getValue(address(_horseEquipTokenAddress), tokenId, _horseEquipDiscount);
return DisBytes.BytesToUint256();
}
function getHorseEquipReward(uint256 tokenId) public view returns (uint256){
bytes memory rewBytes = _horseEquipAttrAddress.getValue(address(_horseEquipTokenAddress), tokenId, _horseEquipReward);
return rewBytes.BytesToUint256();
}
function getHorseEquipTypes(uint256 tokenId) public view returns (uint256){
bytes memory typesBytes = _horseEquipAttrAddress.getValue(address(_horseEquipTokenAddress), tokenId, _horseEquipTypes);
return typesBytes.BytesToUint256();
}
function getHorseEquipStyle(uint256 tokenId) public view returns (uint256){
bytes memory styleBytes = _horseEquipAttrAddress.getValue(address(_horseEquipTokenAddress), tokenId, _horseEquipStyle);
return styleBytes.BytesToUint256();
}
function getHorseEquipLastPrice(uint256 tokenId) public view returns (uint256){
bytes memory priceBytes = _horseEquipAttrAddress.getValue(address(_horseEquipTokenAddress), tokenId, _horseEquipLastPrice);
return priceBytes.BytesToUint256();
}
function getEquipOfHorseId(uint256 tokenId) public view returns (uint256){
bytes memory idBytes = _horseEquipAttrAddress.getValue(address(_horseEquipTokenAddress), tokenId, _horseEquipOfHorseId);
return idBytes.BytesToUint256();
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import "../Interface/IERC721Attr.sol";
import "../Interface/IERC721Token.sol";
import "../library/Bytes.sol";
import "../library/Uint256.sol";
import "./Auth.sol";
contract RacecourseAttrOperaContract is Program {
using Uint256 for uint256;
using Bytes for bytes;
IERC721Attr private _attrAddress;
string public _horseId;//报名的马匹id
function initialize() public initializer {
program_initialize();
_horseId = "horseId";//报名的马匹id
}
function init(address attrAddress) public onlyAdmin returns (bool) {
_attrAddress = IERC721Attr(attrAddress);
return true;
}
function setHorseId(uint256 tokenId, uint256 horseId) public onlyProgram returns (bool) {
bool result = _attrAddress.setArrayValue(tokenId, _horseId, horseId.Uint256ToBytes());
return result;
}
// 取消比赛后,清除已经报名的马匹信息
function delHorseId(uint256 tokenId) public onlyProgram returns (bool) {
bool result = _attrAddress.delArrayValue(tokenId, _horseId);
return result;
}
// 取消报名后,清除对应的马匹信息
function delHorseIdOne(uint256 tokenId, uint256 horseId) public onlyProgram returns (bool) {
bool result = _attrAddress.removeArrayValue(tokenId, _horseId, horseId.Uint256ToBytes());
return result;
}
function delHorseIdBatch(uint256[] memory tokenIds) public onlyProgram returns (bool) {
require(tokenIds.length > 0 && tokenIds.length <= 256, "Cannot del 0 and must be less than 256");
for (uint256 i = 0; i < tokenIds.length; i++) {
_attrAddress.delArrayValue(tokenIds[i], _horseId);
}
return true;
}
function getHorseId(uint256 tokenId) public view returns (uint256[] memory) {
return _attrAddress.getArrayValue(tokenId, _horseId);
}
function checkHorseId(uint256 tokenId, uint256 horseId) external view returns (bool){
bool result = _attrAddress.checkArrayValue(tokenId, _horseId, horseId.Uint256ToBytes());
return result;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import "./Auth.sol";
contract UserLoginContract is Admin {
mapping(address => mapping(string => bool)) private _token;
mapping(address => mapping(string => uint256)) private _tokenExpTime;
function initialize() public initializer {
admin_initialize();
}
function reg(string memory token, uint256 time) public {
_token[msg.sender][token] = true;
_tokenExpTime[msg.sender][token] = block.timestamp + (time);
}
function logout(string memory token) public {
_token[msg.sender][token] = false;
_tokenExpTime[msg.sender][token] = block.timestamp;
}
function checkToken(address account, string memory token) public view returns (bool){
if (_token[account][token] && _tokenExpTime[account][token] > block.timestamp) {
return true;
}
return false;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
library Address {
function AddressToBytes(address source) internal pure returns (bytes memory) {
return abi.encodePacked(source);
}
function ToAsciiString(address x) internal pure returns (string memory) {
bytes memory s = new bytes(40);
for (uint i = 0; i < 20; i++) {
bytes1 b = bytes1(uint8(uint(uint160(x)) / (2 ** (8 * (19 - i)))));
bytes1 hi = bytes1(uint8(b) / 16);
bytes1 lo = bytes1(uint8(b) - 16 * uint8(hi));
s[2 * i] = char(hi);
s[2 * i + 1] = char(lo);
}
return string(s);
}
function char(bytes1 b) internal pure returns (bytes1 c) {
if (uint8(b) < 10) return bytes1(uint8(b) + 0x30);
else return bytes1(uint8(b) + 0x57);
}
}
This diff is collapsed.
This diff is collapsed.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
library Bytes {
function BytesToUint256(bytes memory b) internal pure returns (uint256){
uint256 number;
for (uint i = 0; i < b.length; i++) {
number = number + uint8(b[i]) * (2 ** (8 * (b.length - (i + 1))));
}
return number;
}
function BytesToString(bytes memory source) internal pure returns (string memory result) {
return string(source);
}
function BytesToAddress(bytes memory bys) internal pure returns (address addr){
assembly {
addr := mload(add(bys, 20))
}
}
function Decode(bytes memory signedString, string memory d) internal pure returns (address){
bytes32 r = bytesToBytes32(slice(signedString, 0, 32));
bytes32 s = bytesToBytes32(slice(signedString, 32, 32));
uint8 v = uint8(signedString[64]);
bytes32 dd = keccak256(abi.encodePacked(d));
return ecrecoverDecode(r, s, v, dd);
}
function slice(bytes memory data, uint start, uint len) internal pure returns (bytes memory){
bytes memory b = new bytes(len);
for (uint i = 0; i < len; i++) {
b[i] = data[i + start];
}
return b;
}
function ecrecoverDecode(bytes32 r, bytes32 s, uint8 v1, bytes32 d) internal pure returns (address addr){
uint8 v = uint8(v1);
if (v == 0 || v == 1) {
v = v+27;
}
addr = ecrecover(d, v, r, s);
}
function bytesToBytes32(bytes memory source) internal pure returns (bytes32 result){
assembly{
result := mload(add(source, 32))
}
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
library Uint256 {
function Uint256ToBytes(uint256 x) internal pure returns (bytes memory b) {
b = new bytes(32);
assembly {mstore(add(b, 32), x)}
}
function BytesToUint256(bytes memory b) internal pure returns (uint256){
uint256 number;
for (uint i = 0; i < b.length; i++) {
number = number + uint8(b[i]) * (2 ** (8 * (b.length - (i + 1))));
}
return number;
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment