André Mello posted an update

`solidity pragma solidity ^0.4.0;

contract TimeTracker { uint public rate; address public admin; enum UserState { Neutral, Detected, Attached, Missing }

// Mapping from addresses to timestamps
mapping (address => uint) public startTimes;
mapping (address => UserState) public userStates;
mapping (address => mapping (address => bool)) public bound;
mapping (address => bool) public validPoles;

event Detected(address user, address pole);
event Undetected(address user, address pole);
event Attached(address user, address pole);
event Detached(address user, address pole);
event Found(address user, address pole);
event Lost(address user, address pole);

function TimeTracker(uint initialRate) {
    admin = msg.sender;
    rate = initialRate;
}

function changeRate(uint newRate) {
    require(msg.sender == admin);
    rate = newRate;
}

function setPole(address pole, bool enable) {
    require(msg.sender == admin);
    validPoles[pole] = enable;
}

function userDetect(address user, bool isDetected) {
    address pole = msg.sender;
    require(validPoles[pole]);
    if (isDetected) {
        if (userStates[user] == UserState.Neutral) {
            userStates[user] = UserState.Detected;
            bound[pole][user] = true;
            Detected(user, pole);
        } else if (userStates[user] == UserState.Missing) {
            Found(user, pole);
        }
    } else {
        if (userStates[user] == UserState.Detected) {
            userStates[user] = UserState.Neutral;
            bound[pole][user] = false;
            Undetected(user, pole);
        } else if (userStates[user] == UserState.Attached) {
            userStates[user] = UserState.Missing;
            bound[pole][user] = false;
            Lost(user, pole);
        }
    }
}

function userAttach(address pole) {
    address user = msg.sender;
    require(bound[pole][user]);
    require(userStates[user] == UserState.Detected);
    startTimes[user] = now;
    userStates[user] = UserState.Attached;
    Attached(user, pole);
}

function userDetach(address pole) payable {
    address user = msg.sender;
    require(bound[pole][user]);
    require((userStates[user] == UserState.Missing)
         || (userStates[user] == UserState.Attached));
    uint delta = now - startTimes[user];
    pole.transfer(delta * rate);
    userStates[user] = UserState.Neutral;
    Detached(user, pole);
}

} `

Log in or sign up for Devpost to join the conversation.