Описание изменений

This commit is contained in:
2025-03-19 17:18:03 +03:00
parent 04d027054d
commit 55e4d81c95
75 changed files with 2103 additions and 4861 deletions

View File

@@ -1,61 +0,0 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
contract AccessToken is ERC721, Ownable {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
// Роли для токенов
enum Role { USER, ADMIN }
// Маппинг токен ID => роль
mapping(uint256 => Role) public tokenRoles;
// Маппинг адрес => активный токен
mapping(address => uint256) public activeTokens;
constructor() ERC721("DApp Access Token", "DAT") Ownable() {
// Инициализация владельца происходит в Ownable()
}
// Создание нового токена доступа
function mintAccessToken(address to, Role role) public onlyOwner {
require(role == Role.USER || role == Role.ADMIN, "Invalid role");
_tokenIds.increment();
uint256 newTokenId = _tokenIds.current();
_safeMint(to, newTokenId);
tokenRoles[newTokenId] = role;
activeTokens[to] = newTokenId;
}
// Проверка роли по адресу
function checkRole(address user) public view returns (Role) {
uint256 tokenId = activeTokens[user];
require(tokenId != 0, "No active token");
require(ownerOf(tokenId) == user, "Token not owned");
return tokenRoles[tokenId];
}
// Отзыв токена
function revokeToken(uint256 tokenId) public onlyOwner {
address tokenOwner = ownerOf(tokenId);
activeTokens[tokenOwner] = 0;
_burn(tokenId);
}
// Передача токена запрещена
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal override {
require(from == address(0) || to == address(0), "Token transfer not allowed");
super._beforeTokenTransfer(from, to, tokenId);
}
}

View File

@@ -1,38 +0,0 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
contract MyContract is Ownable, ReentrancyGuard {
// Явно объявляем функцию owner
function owner() public view override returns (address) {
return super.owner();
}
uint256 public price;
event Purchase(address buyer, uint256 amount);
constructor() {
price = 0.01 ether; // Начальная цена 0.01 ETH
}
function setPrice(uint256 newPrice) public onlyOwner {
price = newPrice;
}
function getPrice() public view returns (uint256) {
return price;
}
function purchase(uint256 amount) public payable nonReentrant {
require(msg.value == price * amount, "Incorrect payment amount");
emit Purchase(msg.sender, amount);
}
function withdraw() public onlyOwner nonReentrant {
(bool success, ) = owner().call{value: address(this).balance}("");
require(success, "Transfer failed");
}
}