diff --git "a/\347\254\254\344\270\200\350\257\276\344\273\243\347\240\201" "b/\347\254\254\344\270\200\350\257\276\344\273\243\347\240\201" new file mode 100644 index 0000000..b5b0f4d --- /dev/null +++ "b/\347\254\254\344\270\200\350\257\276\344\273\243\347\240\201" @@ -0,0 +1,32 @@ +pragma solidity ^0.4.14; + +contract Payroll{ + uint salary = 1 ether; + address frank = 0xca35b7d915458ef540ade6068dfe2f44e8fa733c; + uint constant payDuration = 10 seconds; + uint lastPayday = now; + + function addFund() payable returns (uint) { + return this.balance; + } + + function calculateRunaway() returns(uint) { + return this.balance / salary; + } + + function hasEnoughFund() returns(bool) { + return calculateRunaway() > 0; + } + + function getPaid() { + if (msg.sender != frank) { + revert(); + } + uint nextPayDay = lastPayday + payDuration; + if (nextPayDay > now) { + revert(); + } + lastPayday = nextPayDay; + frank.transfer(salary); + } +} diff --git "a/\347\254\254\344\270\200\350\257\276\344\275\234\344\270\232" "b/\347\254\254\344\270\200\350\257\276\344\275\234\344\270\232" new file mode 100644 index 0000000..41333c6 --- /dev/null +++ "b/\347\254\254\344\270\200\350\257\276\344\275\234\344\270\232" @@ -0,0 +1,41 @@ +pragma solidity ^0.4.14; + +contract Payroll{ + uint salary = 1 ether; + address Lisaï¼› + address Employee; + uint constant payDuration = 8 seconds; + uint lastPayday = now; + + function set(uint new salary) { + salary = newsalary * 200 wei; + } + + function set(address Employee) { + Lisa = Employee; + } + + function addFund() payable returns (uint) { + return this.balance; + } + + function calculateRunaway() returns(uint) { + return this.balance / salary; + } + + function hasEnoughFund() returns(bool) { + return calculateRunaway() > 0; + } + + function getPaid() { + if (msg.sender != frank) { + revert(); + } + uint nextPayDay = lastPayday + payDuration; + if (nextPayDay > now) { + revert(); + } + lastPayday = nextPayDay; + frank.transfer(salary); + } +} diff --git "a/\347\254\254\344\270\211\350\257\276\344\275\234\344\270\232" "b/\347\254\254\344\270\211\350\257\276\344\275\234\344\270\232" new file mode 100644 index 0000000..58d9a7e --- /dev/null +++ "b/\347\254\254\344\270\211\350\257\276\344\275\234\344\270\232" @@ -0,0 +1,95 @@ +pragma solidity ^0.4.14; + +contract Payroll { + + struct Employee { + address id; + uint salary; + uint lastPayday; + } + + uint constant payDuration = 10 seconds; + uint totalSalary; + address owner; + mapping(address => Employee) public employees; + + function Payroll() { + owner = msg.sender; + } + + modifier onlyOwener { + require(msg.sender == owner); + _; + } + + modifier employeeExist(address employeeId) { + var employee = employees[employeeId]; + assert(employee.id == 0x0); + _; + + } + function _partialPaid(Employee employee) private { + uint payment = employee.salary * (now - employee.lastPayday) / payDuration; + employee.id.transfer(payment); + } + + function addEmployee(address employeeId, uint salary) onlyOwener { + var employee = employees[employeeId]; + assert(employee.id == 0x0); + + employees[employeeId] = Employee(employeeId, salary * 1 ether, now); + totalSalary += employees[employeeId].salary; + } + + function removeEmployee(address employeeId) onlyOwener employeeExist(employeeId) { + var employee = employees[employeeId]; + + _partialPaid(employee); + totalSalary -= employees[employeeId].salary; + delete employees[employeeId]; + } + + function updateEmployee(address employeeId, uint salary)onlyOwener employeeExist(employeeId) { + var employee = employees[employeeId]; + + _partialPaid(employee); + totalSalary -= employees[employeeId].salary; + employees[employeeId].salary = salary * 1 ether; + totalSalary += employees[employeeId].salary; + employees[employeeId].lastPayday = now; + } + + function changePaymentaddress(address employeeId) onlyOwener employeeExist(employeeId) { + var employee = employees[employeeId]; + + _partialPaid(employee); + totalSalary -= employees[employeeId].salary; + delete employees[employeeId]; + assert(employee.id == 0x0); + + employees[employeeId] = Employee(employeeId, salary * 1 ether, now); + totalSalary += employees[employeeId].salary; + + } + function addFund() payable returns (uint) { + return this.balance; + } + + function calculateRunway() returns (uint) { + return this.balance / totalSalary; + } + + function hasEnoughFund() returns (bool) { + return calculateRunway() > 0; + } + + function getPaid() employeeExist(msg.sender) { + var employee = employees[msg.sender]; + + uint nextPayday = employee.lastPayday + payDuration; + assert(nextPayday < now); + + employees[msg.sender].lastPayday = nextPayday; + employee.id.transfer(employee.salary); + } +}