"Building Security" Solidity Example

Solidity contract to track Building Entries


pragma solidity ^0.4.0;
contract BuildingSecurity {

    struct Visitor {
        string name;
        string information;
        string VisitorID;
        uint8 ID;
        string fbID;
        string opencv;
        address delegate;
    } //visitor structure for name and information
    struct TempVisitor{
        string name;
        string id;
    }
    Visitor[] EmployeePermanent; //list of permanent entries
    enum State {
        ENTRY,
        EXIT,
        IN,
        NON
    } //building state for visitors
    struct BuildingDoors {
        string DoorName;
        string fullname;
        string cardnumber;
    }
    State public state = State.NON; // initialize on create
    address buildName;
    string buildingNameDisplay;
    mapping(address => TempVisitor) visitors;
    BuildingDoors[] AllDoors;

    function BuildingSecurity(uint8 _numEntryLimit, string _buildingDisplay) public {
        buildName = msg.sender;
        buildingNameDisplay = _buildingDisplay;
        AllDoors.length = _numEntryLimit;
    }
    function registerVisitor(string _fullname, string _cardnumber, string _door) public 
    returns (uint256){
        TempVisitor storage sender = visitors[msg.sender];
        sender.name = _fullname;
        sender.id=_cardnumber;
        AllDoors.push(
            BuildingDoors({
                DoorName: _door,
                fullname: _fullname,
                cardnumber:_cardnumber
                }) // use array, so can iterate
            );
        return AllDoors.length - 1; // return id
    }
    modifier inState(State _state) {
        if (state != _state) revert();
        _;
    }
    function registerEmployee() public
    inState(State.NON) payable returns (uint256)
    {
       
        return EmployeePermanent.length - 1; // return id
    }

}

Comments

Popular posts from this blog

Is Making the Crypto Space Legally Compliant Paving the Road to Mass (Blockchain) Adoption?

Crypto-Currency "Coin Contract" Example

Solidity Hash of Structs (Testing hash uniqueness)