Verified contractPartialMIT
RecyReportAttributes
Address0xca5f41d24e7ecb633a162f15a0bca0d8db4e0a75
- Balance
0 ETH
- Transactions
2
- Compiler
solc 0.8.30
- Same code
Only this contract
Details
- Compiler
- solc 0.8.30+commit.73712a01
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- Via IR
- yes
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,474,984
- Creation transaction
- 0x926370ad43…0ebc717360
- Libraries
- src/lib/RecyTraceabilityMetadata.sol:RecyTraceabilityMetadata0xc9b0…b86ec3
src/RecyReportAttributes.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";
contract RecyReportAttributes is Ownable2Step {
string private constant DEFAULT_MATERIAL_SVG =
"M264.4 95.01c-35.6-.06-80.2 11.19-124.2 34.09C96.27 152 61.45 182 41.01 211.3c-20.45 ";
// Preserved original indices (0..10) for frontend/API compatibility
string[] public material = [
"Undefined",
"Plastic",
"Glass",
"Metal",
"Paper",
"Glass",
"E-Waste",
"Organic",
"Textile",
"Hazardous",
"Chemical"
];
// Stores custom SVGs only for newly added or overridden material indices (saves >1M deploy gas)
mapping(uint256 => string) private _customMaterialSvg;
string[] public recycleType = [
"Undefined",
"Composting",
"Incineration",
"Mechanical Recycling",
"Pyrolysis",
"Refuse-Derived Fuel",
"Thermal Recycling"
];
string[] public recycleShape = ["Undefined", "Pellets", "Bricks"];
string[] public disposalMethod = [
"Undefined",
"Landfill",
"Incineration",
"Recycling",
"Composting",
"Anaerobic Digestion",
"Waste-to-Energy",
"Plasma Gasification"
];
event MaterialAdded(uint256 indexed index, string name);
event RecycleTypeAdded(uint256 indexed index, string name);
event DisposalMethodAdded(uint256 indexed index, string name);
event RecycleShapeAdded(uint256 indexed index, string name);
constructor() Ownable(msg.sender) {}
function materialCount() external view returns (uint256) {
return material.length;
}
function disposalMethodCount() external view returns (uint256) {
return disposalMethod.length;
}
function getMaterial(uint256 index) public view returns (string memory) {
require(index < material.length, "RecyReportAttributes.getMaterial: Invalid index");
return material[index];
}
/// @notice ABI-compatible getter replacing the redundant storage array.
function materialSvg(uint256 index) public view returns (string memory) {
return getMaterialSvg(index);
}
function getMaterialSvg(uint256 index) public view returns (string memory) {
require(index < material.length, "RecyReportAttributes.getMaterialSvg: Invalid index");
string memory custom = _customMaterialSvg[index];
return bytes(custom).length > 0 ? custom : DEFAULT_MATERIAL_SVG;
}
function getRecycleType(uint256 index) public view returns (string memory) {
require(index < recycleType.length, "RecyReportAttributes.getRecycleType: Invalid index");
return recycleType[index];
}
function getDisposalMethod(uint256 index) public view returns (string memory) {
require(index < disposalMethod.length, "RecyReportAttributes.getDisposalMethod: Invalid index");
return disposalMethod[index];
}
function getRecycleShape(uint256 index) public view returns (string memory) {
require(index < recycleShape.length, "RecyReportAttributes.getRecycleShape: Invalid index");
return recycleShape[index];
}
function getMaterials() public view returns (string[] memory) {
return material;
}
function getMaterialSvgs() public view returns (string[] memory svgs) {
uint256 len = material.length;
svgs = new string[](len);
for (uint256 i = 0; i < len; i++) {
string memory custom = _customMaterialSvg[i];
svgs[i] = bytes(custom).length > 0 ? custom : DEFAULT_MATERIAL_SVG;
}
}
function getRecycleTypes() public view returns (string[] memory) {
return recycleType;
}
function getDisposalMethods() public view returns (string[] memory) {
return disposalMethod;
}
function getRecycleShapes() public view returns (string[] memory) {
return recycleShape;
}
function addMaterial(string calldata newMaterial, string calldata newMaterialSvg) external onlyOwner {
require(bytes(newMaterial).length > 0, "RecyReportAttributes.addMaterial: Material name cannot be empty");
require(bytes(newMaterialSvg).length > 0, "RecyReportAttributes.addMaterial: Material SVG cannot be empty");
uint256 idx = material.length;
material.push(newMaterial);
_customMaterialSvg[idx] = newMaterialSvg;
emit MaterialAdded(idx, newMaterial);
}
function addRecycleType(string calldata newRecycleType) external onlyOwner {
require(bytes(newRecycleType).length > 0, "RecyReportAttributes.addRecycleType: Empty value");
uint256 idx = recycleType.length;
recycleType.push(newRecycleType);
emit RecycleTypeAdded(idx, newRecycleType);
}
function addDisposalMethod(string calldata newDisposalMethod) external onlyOwner {
require(bytes(newDisposalMethod).length > 0, "RecyReportAttributes.addDisposalMethod: Empty value");
uint256 idx = disposalMethod.length;
disposalMethod.push(newDisposalMethod);
emit DisposalMethodAdded(idx, newDisposalMethod);
}
function addRecycleShape(string calldata newRecycleShape) external onlyOwner {
require(bytes(newRecycleShape).length > 0, "RecyReportAttributes.addRecycleShape: Empty value");
uint256 idx = recycleShape.length;
recycleShape.push(newRecycleShape);
emit RecycleShapeAdded(idx, newRecycleShape);
}
}
lib/openzeppelin-contracts/contracts/access/Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
lib/openzeppelin-contracts/contracts/access/Ownable2Step.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.20;
import {Ownable} from "./Ownable.sol";
/**
* @dev Contract module which provides access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is specified at deployment time in the constructor for `Ownable`. This
* can later be changed with {transferOwnership} and {acceptOwnership}.
*
* This module is used through inheritance. It will make available all functions
* from parent (Ownable).
*/
abstract contract Ownable2Step is Ownable {
address private _pendingOwner;
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view virtual returns (address) {
return _pendingOwner;
}
/**
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual override onlyOwner {
_pendingOwner = newOwner;
emit OwnershipTransferStarted(owner(), newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual override {
delete _pendingOwner;
super._transferOwnership(newOwner);
}
/**
* @dev The new owner accepts the ownership transfer.
*/
function acceptOwnership() public virtual {
address sender = _msgSender();
if (pendingOwner() != sender) {
revert OwnableUnauthorizedAccount(sender);
}
_transferOwnership(sender);
}
}
lib/openzeppelin-contracts/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {
"src/lib/RecyTraceabilityMetadata.sol": {
"RecyTraceabilityMetadata": "0xC9b00fdb031438bcF3cF8C9D6d42513337B86Ec3"
}
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"forge-std/=lib/forge-std/src/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.