pragma solidity ^0.4.21; contract EthSalaryPay { event SalaryPay(address _employee); event Deposit(address indexed _sender, uint _value); event Execution(address _employee); event ExecutionFailure(address _employee); address private owner; uint private ownerBalance; uint transactionCount = 0; struct Transaction { address destination; uint value; bool executed; } mapping(address => uint256) private employees; mapping(address => bool) private employeeIndex; mapping(address => Transaction[]) public transactions; modifier onlyOwner() { require(msg.sender == owner); _; } modifier modifIsEmployee(address _employee) { require(employeeIndex[_employee] == true); _; } /// @dev Fallback function allows to deposit ether. function() public payable { if (msg.value > 0) emit Deposit(msg.sender, msg.value); ownerBalance += msg.value; } constructor() public payable { require(owner == address(0)); owner = msg.sender; //@modexParam("_ownerAddress","Owner address","Address"); employees[owner] = 100000; //@modexParam("_ownerBalance","Owner initial salary","Address"); employeeIndex[owner] = true; } function addEmployee(address _employee,uint _salary) public onlyOwner { employees[_employee] = _salary; employeeIndex[_employee] = true; } function getEmployeeSalary(address _employee) public view onlyOwner modifIsEmployee(_employee) returns(uint) { return employees[_employee]; } function setEmployeeSalary(address _employee,uint _salary) public onlyOwner modifIsEmployee(_employee) { employees[_employee] = _salary; } function getIsEmployee(address _employee) public view onlyOwner returns (bool){ return employeeIndex[_employee]; } function disableEmployee(address _employee) public onlyOwner modifIsEmployee(_employee) { employeeIndex[_employee] = false; } function enableEmployee(address _employee) public onlyOwner { employeeIndex[_employee] = true; } function employeePaySalary(address _employee) payable public onlyOwner { require(ownerBalance >= employees[_employee]); ownerBalance = ownerBalance - employees[_employee]; Transaction memory ttx; ttx.destination = _employee; ttx.value = employees[_employee]; ttx.executed = false; if (_employee.call.value(employees[_employee])()){ ttx.executed = true; transactions[_employee].push(ttx); emit Execution(_employee); } else { transactions[_employee].push(ttx); emit ExecutionFailure(_employee); } emit SalaryPay(_employee); transactionCount += 1; } function getTxCount() public view onlyOwner returns(uint) { return transactionCount; } function getOwnerBalance() public view onlyOwner returns(uint) { return ownerBalance; } }
0.4.18