Waste Management Transparency

What it does:
Tracks the collection, transportation, treatment, and disposal of waste on-chain to ensure transparency, accountability, and compliance across the entire waste management lifecycle.

Why it matters:
Prevents illegal dumping and falsified reports, improves regulatory oversight, increases public trust, and enables data-driven waste reduction and recycling policies.

How it works:

  • Waste generators (households, businesses) register waste sources

  • Waste batches are created with metadata (type, weight, origin)

  • Licensed collectors pick up waste and log transfers on-chain

  • Treatment facilities report processing methods (recycling, landfill, incineration)

  • Oracles verify weights, locations, and processing outcomes

  • Full waste lifecycle remains traceable and auditable

  • Data can power incentives, penalties, and ESG reporting

      // SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/access/Ownable.sol";

/**
 * @title WasteManagementTransparency
 * @author Nam
 * @notice Provides end-to-end traceability of waste management processes
 */
contract WasteManagementTransparency is Ownable {

    enum WasteStatus {
        Created,
        Collected,
        InTransit,
        Processed,
        Disposed
    }

    struct WasteBatch {
        address generator;
        string wasteType;      // plastic, organic, e-waste, etc.
        uint256 weight;        // kg
        WasteStatus status;
        string metadataURI;    // IPFS: photos, documents
        address lastHandler;
    }

    uint256 public batchCount;
    mapping(uint256 => WasteBatch) public wasteBatches;
    mapping(address => bool) public authorizedHandlers;
    mapping(address => bool) public approvedOracles;

    // -------------------- EVENTS --------------------

    event WasteBatchCreated(uint256 indexed batchId, address indexed generator, uint256 weight);
    event WasteStatusUpdated(uint256 indexed batchId, WasteStatus status, address handler);

    // -------------------- HANDLER & ORACLE MANAGEMENT --------------------

    function authorizeHandler(address _handler) external onlyOwner {
        authorizedHandlers[_handler] = true;
    }

    function revokeHandler(address _handler) external onlyOwner {
        authorizedHandlers[_handler] = false;
    }

    function approveOracle(address _oracle) external onlyOwner {
        approvedOracles[_oracle] = true;
    }

    // -------------------- WASTE CREATION --------------------

    function createWasteBatch(
        string calldata _wasteType,
        uint256 _weight,
        string calldata _metadataURI
    ) external {
        require(_weight > 0, "Invalid weight");

        batchCount += 1;
        wasteBatches[batchCount] = WasteBatch({
            generator: msg.sender,
            wasteType: _wasteType,
            weight: _weight,
            status: WasteStatus.Created,
            metadataURI: _metadataURI,
            lastHandler: msg.sender
        });

        emit WasteBatchCreated(batchCount, msg.sender, _weight);
    }

    // -------------------- STATUS UPDATES --------------------

    function updateWasteStatus(uint256 _batchId, WasteStatus _status) external {
        WasteBatch storage w = wasteBatches[_batchId];
        require(authorizedHandlers[msg.sender] || approvedOracles[msg.sender], "Not authorized");

        w.status = _status;
        w.lastHandler = msg.sender;

        emit WasteStatusUpdated(_batchId, _status, msg.sender);
    }
}