Description:
Smart contract deployed on Ethereum with Factory features.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"contracts/token/PData.sol": {
"content": "// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.7;
import {ManagerRole} from "../common/ManagerRole.sol";
import {Ownable} from "../common/Ownable.sol";
import {IPData} from "./interfaces/IPData.sol";
contract PData is IPData, Ownable, ManagerRole {
bool public initialed = false;
mapping(bytes12 => DataStore) private _dataInfos;
mapping(bytes12 => bytes12[]) private _pRids;
bytes12[] private _rids;
constructor(){}
function initial() external {
require(!initialed, "10");
initialed = true;
_transferOwnership(msg.sender);
_addManager(msg.sender);
}
function addManager(address account) public virtual override {
if (msg.sender == owner) {
_addManager(account);
emit ManagerAdded(account);
} else {
super.addManager(account);
}
}
function storeReqData(bytes12 reqId, bytes12 pid, string memory url, string memory hash, string memory ext) external onlyManager {
require(reqId != bytes12(0), "20");
require(pid != bytes12(0), "21");
DataStore storage _dataInfo = _dataInfos[reqId];
require(_dataInfo.reqId == bytes12(0), "30");
_dataInfo.pid = pid;
_dataInfo.url = url;
_dataInfo.hash = hash;
_dataInfo.ext = ext;
_dataInfo.createTime = block.timestamp;
_dataInfo.reqId = reqId;
_pRids[pid].push(reqId);
_rids.push(reqId);
emit DataSave(reqId, pid, hash);
}
function verifyHashData(bytes12 reqId, string memory hash) external view returns (bool result){
DataStore memory _dataInfo = _dataInfos[reqId];
result = (reqId != bytes12(0) && _dataInfo.reqId == reqId && keccak256(bytes(_dataInfo.hash)) == keccak256(bytes(hash)));
}
function getDataByReqId(bytes12 reqId) external view returns (bool success, DataStore memory data) {
data = _dataInfos[reqId];
success = (reqId != bytes12(0) && reqId == data.reqId);
}
}
"
},
"contracts/token/interfaces/IPData.sol": {
"content": "// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.7;
interface IPData {
struct DataStore {
bytes12 pid;
bytes12 reqId;
uint256 createTime;
string url;
string hash;
string ext;
}
event DataSave(bytes12 reqId, bytes12 pid, string hash);
}
"
},
"contracts/common/Ownable.sol": {
"content": "// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address public owner;
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
constructor() {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
if (newOwner != address(0)) {
owner = newOwner;
}
}
function _transferOwnership(address newOwner) internal virtual {
// address oldOwner = owner;
owner = newOwner;
}
}
"
},
"contracts/common/ManagerRole.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0
/*
* This code has not been reviewed.
* Do not use or deploy this code before reviewing it personally first.
*/
pragma solidity ^0.8.0;
import "./Roles.sol";
/**
* @title ManagerRole
* @dev Minters are responsible for minting new tokens.
*/
abstract contract ManagerRole {
using Roles for Roles.Role;
event ManagerAdded(address indexed account);
event ManagerRemoved(address indexed account);
Roles.Role private _managers;
constructor() {
_addManager(msg.sender);
}
modifier onlyManager() virtual {
require(isManager(msg.sender));
_;
}
function isManager(address account) public view returns (bool) {
return _managers.has(account);
}
function addManager(address account) public virtual onlyManager {
_addManager(account);
emit ManagerAdded(account);
}
function removeManager(address account) public onlyManager {
_removeManager(account);
}
function renounceManager() public {
_removeManager(msg.sender);
}
function _addManager(address account) internal {
_managers.add(account);
}
function _removeManager(address account) internal {
_managers.remove(account);
emit ManagerRemoved(account);
}
}"
},
"contracts/common/Roles.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0
/*
* This code has not been reviewed.
* Do not use or deploy this code before reviewing it personally first.
*/
pragma solidity ^0.8.0;
/**
* @title Roles
* @dev Library for managing addresses assigned to a Role.
*/
library Roles {
struct Role {
mapping (address => bool) bearer;
}
/**
* @dev Give an account access to this role.
*/
function add(Role storage role, address account) internal {
require(!has(role, account), "Roles: account already has role");
role.bearer[account] = true;
}
/**
* @dev Remove an account's access to this role.
*/
function remove(Role storage role, address account) internal {
require(has(role, account), "Roles: account does not have role");
role.bearer[account] = false;
}
/**
* @dev Check if an account has this role.
* @return bool
*/
function has(Role storage role, address account) internal view returns (bool) {
require(account != address(0), "Roles: account is the zero address");
return role.bearer[account];
}
}"
}
},
"settings": {
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"remappings": []
}
}}
Submitted on: 2025-10-29 16:32:31
Comments
Log in to comment.
No comments yet.