Created
November 25, 2016 22:09
-
-
Save 3esmit/eb9cd848489a995babdb9e3e9de2a0d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.0; | |
contract ExampleCounter { | |
uint counter; | |
uint max; | |
uint amount; | |
address device; | |
address owner; | |
address reciever; | |
function ExampleCounter(uint _max,uint _amount,address _device,address _reciever){ //constructor | |
max = _max; | |
amount = _amount; | |
device = _device; | |
reciever = _reciever; | |
} | |
function addCount(uint count) onlyAllowed{ | |
counter += count; | |
if(this.balance >= amount){ //if contract have balance | |
if(counter >= max){ //if passed max... | |
counter-=max; | |
reciever.send(amount); | |
if(counter >= max){ //if still more to pay... | |
this.addCount(0); | |
} | |
} | |
} | |
} | |
function resetCounter() onlyAllowed{ | |
counter = 0; | |
} | |
modifier onlyAllowed() { //just owner or device can do this | |
if (msg.sender != device && msg.sender != owner) throw; | |
_; | |
} | |
function setDevice(address _device) onlyOwner{ | |
device = _device; | |
} | |
function setMax(uint _max) onlyOwner{ | |
max = _max; | |
} | |
function setAmount(uint _amount) onlyOwner{ | |
amount = _amount; | |
} | |
function setReciever(address _reciever) onlyOwner{ | |
reciever = _reciever; | |
} | |
modifier onlyOwner() { | |
if (msg.sender != owner) throw; | |
_; | |
} | |
function setOwner(address _owner) onlyOwner{ | |
owner = _owner; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment