高速公路防逃费智能合约案例

// SPDX-License-Identifier: MIT
pragma solidity ^0.6.10;
pragma experimental ABIEncoderV2;
import "./HighwayStations.sol";
import "./CertGeneration.sol";

contract VehicleRegister {
    address public owner;

    HighwayStations public highwayStations;
    
    CertGeneration public certGeneration;

    struct Registration {
        uint256 etcID;
        string carNumber;
        string carImage;
        uint256 carCoding;
        uint256 timeStamp;
        uint256 stationID;
        HighwayStations.Type _type;
    }
    
    struct StationTraffic {
        uint256 stationID;
        string[] vehicles;
    }

    struct ExitRegistration {
        uint256 stationInletID;
        uint256 stationRoadID;
        uint256 etcID;
        string carNumber;
        string carImage;
        uint256 carCoding;
        uint256 timeStamp;
        uint256 stationExportID;
        uint256 expenses;
        HighwayStations.Type _type;
        uint256 registerCounter;
    }
    
    uint256 public etcID;
    
    uint256 public stationInletID;
    
    uint256 public stationRoadID;
    
    uint256 public stationExportID;

    uint256 public registerCounter;

    uint256 public exitNumber;

    uint256 public carNumber;

    uint256 public carRouteNumber;

    uint256 public nowTime;

    string public carImage;

    uint256 public carCoding;

    uint256 public timeStamp;

    uint256 public expenses;

    uint256 public totalExpenses;

    uint256[] public routeRegister;

    uint256[][] public routeRegisterArr;

    mapping (uint256 => Registration) public entranceRegistrations;
    mapping (uint256 => Registration) public routeRegistrations;
    mapping (uint256 => ExitRegistration) public exitRegistrations;
    mapping (uint256 => uint256[][]) public routeRegisterArrMapper;
    mapping (uint256 => StationTraffic) public stationTraffic;
    mapping (string => uint256[]) public vehicleRoutes;

    constructor(address _stationAddress, address _certGeneration) public{
        owner = msg.sender;
        highwayStations = HighwayStations(_stationAddress);
        certGeneration = CertGeneration(_certGeneration);
    }

    modifier onlyOwner() {
        require(msg.sender == owner, "您没有权限");
        _;
    }

    function registerEntrance(uint256 _etcID, string memory _carNumber, string memory _carImage, uint256 _carCoding, uint256 _stationID) public onlyOwner {
        // require(highwayStations.stations(_stationID).stationID != 0, "无效的站点");
        entranceRegistrations[registerCounter] = Registration({
            etcID: _etcID,
            carNumber: _carNumber,
            carImage: _carImage,
            carCoding: _carCoding,
            timeStamp: block.timestamp,
            stationID: _stationID,
            _type: HighwayStations.Type.inlet
        });
        registerCounter++;
        vehiclePassedStation(_stationID, _carNumber);
        vehicleRoutes[_carNumber].push(_stationID);
    }

    function registerRoute(uint256 _etcID, string memory _carNumber, string memory _carImage, uint256 _carCoding, uint256 _stationID) public onlyOwner {
        // require(highwayStations.stations(_stationID).stationID != 0, "无效的站点");
        routeRegistrations[registerCounter] = Registration({
            etcID: _etcID,
            carNumber: _carNumber,
            carImage: _carImage,
            carCoding: _carCoding,
            timeStamp: block.timestamp,
            stationID: _stationID,
            _type: HighwayStations.Type.road
        });
        registerCounter++;
        vehiclePassedStation(_stationID, _carNumber);
        vehicleRoutes[_carNumber].push(_stationID);
    }

    function registerExit(uint256 _etcID, string memory _carNumber, string memory _carImage, uint256 _carCoding, uint256 _stationExportID, uint256 _expenses) public onlyOwner {
        // require(highwayStations.stations(_stationID).stationID != 0, "无效的站点");
        //计费方法

        nowTime = block.timestamp;

        certGeneration.generateCert(_carNumber, nowTime);
        registerCounter++;
        uint256 s;
        for(uint i = 0; i < exitNumber; i++){
            s = carNumber + s;
            carNumber = routeRegister.length;
        }
        carRouteNumber = registerCounter - s;
        uint256[] storage routeRegisters;
        for(uint256 i = 0; i <= carRouteNumber; i++){
            
            routeRegisters[i] = routeRegister[i+s];
        }

        routeRegisterArr.push(routeRegisters);
        exitNumber++;

        stationInletID = s + 1;
        stationExportID = routeRegisters[carRouteNumber];
        
        exitRegistrations[registerCounter] = ExitRegistration({
            registerCounter: registerCounter,
            etcID: _etcID,
            carNumber: _carNumber,
            carImage: _carImage,
            carCoding: _carCoding,
            timeStamp: block.timestamp,
            stationInletID: stationInletID,
            stationRoadID: stationRoadID,
            stationExportID: _stationExportID,
            expenses: _expenses,
            _type: HighwayStations.Type.export
        });

        routeRegisterArrMapper[nowTime] = routeRegisterArr;
        vehiclePassedStation(_stationExportID, _carNumber);
        vehicleRoutes[_carNumber].push(_stationExportID);
    }

    function vehiclePassedStation(uint256 stationID, string memory vehicleID) internal onlyOwner {
        uint256 stationCounters = highwayStations.getStations();
        require(stationID < stationCounters, "无效的站点ID");
        stationTraffic[stationID].vehicles.push(vehicleID);
    }

    function getNowRegisterCounter() view external returns(uint256){
        return registerCounter;
    }

    function getCarAllRoutes(string memory _carNumber) public view returns(uint256[] memory) {
        return vehicleRoutes[_carNumber];
    }

    function getStateCars(uint256 stationID) public view returns(string[] memory) {
        require(stationID < highwayStations.stationCounter(), "无效的站点ID");
        return stationTraffic[stationID].vehicles;
    }

}

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

contract HighwayStations {
    address public owner;

    uint256 public stationCounter;

    enum Type { 
        inlet,
        road,
        export
    }

    struct Station {
        uint256 stationID;
        string name;
        Type types;
    }

    mapping(uint256 => Station) public stations;
    mapping(string => uint256) public stationNameToID;

    constructor() public{
        owner = msg.sender;
    }

    modifier onlyOwner() {
        require(msg.sender == owner, "您没有权限");
        _;
    }

    function addStation(string memory _name, Type _type) public onlyOwner {
        stations[stationCounter] = Station({
            stationID: stationCounter,
            name: _name,
            types: _type
        });
        stationNameToID[_name] = stationCounter;
        stationCounter++;
    }

    function getStations() public view returns(uint256) {
        return stationCounter;
    }

    function getStationName(uint256 stationID) public view returns(string memory) {
        require(stationID < stationCounter, "站点ID不存在");
        return stations[stationID].name;
    }

    function getStationIDByName(string memory _name) public view returns (uint256) {
        return stationNameToID[_name];
    }

}

// SPDX-License-Identifier: MIT
pragma solidity ^0.6.10;
pragma experimental ABIEncoderV2;

import "./HighwayStations.sol";
import "./VehicleRegister.sol";

contract CertGeneration {
    HighwayStations public highwayStations;
    VehicleRegister public vehicleRegister;
    
    struct VehicleData {
        uint256 stationInletID;
        uint256 stationRoadID;
        uint256 stationExportID;
        string carNumber;
        uint256 time;
        string carImage;
        uint256 carCoding;
        uint256 etcID;
        uint256 totalExpenses;
    }

    struct Certificate {
        VehicleData[] data;
    }

    mapping (string => Certificate) carCertificates;

    constructor(address _stationAddress, address _vehicleRegister) public {
        highwayStations = HighwayStations(_stationAddress);
        vehicleRegister = VehicleRegister(_vehicleRegister);
    }

    function generateCert(string memory _carNumber, uint256 _timeStamp) external {
        Certificate storage cert = carCertificates[_carNumber];
        // uint256 registerCounters = vehicleRegister.getNowRegisterCounter();
        VehicleData memory newVehicleData = VehicleData({
            stationInletID: vehicleRegister.stationInletID(),
            stationRoadID: vehicleRegister.stationRoadID(),
            stationExportID: vehicleRegister.stationExportID(),
            carNumber: _carNumber,
            time: _timeStamp,
            carImage: vehicleRegister.carImage(),
            carCoding: vehicleRegister.carCoding(),
            etcID: vehicleRegister.etcID(),
            totalExpenses: vehicleRegister.totalExpenses()
        });

        cert.data.push(newVehicleData);
    }

    function getVehicleData(string memory _carNumber, uint256 index) public view returns (VehicleData memory) {
        Certificate storage cert = carCertificates[_carNumber];
        require(index < cert.data.length, "Index out of bounds");
        return cert.data[index];
    }
}

weixin151云匹面粉直供微信小程序+springboot后端毕业源码案例设计 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值