Skip to content

Instantly share code, notes, and snippets.

@3esmit
Created November 25, 2016 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3esmit/eb9cd848489a995babdb9e3e9de2a0d4 to your computer and use it in GitHub Desktop.
Save 3esmit/eb9cd848489a995babdb9e3e9de2a0d4 to your computer and use it in GitHub Desktop.
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