-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCounter.sol
32 lines (32 loc) · 897 Bytes
/
Counter.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
pragma solidity ^0.5.1;
contract Counter {
uint productCount = 0;
uint boxCount = 0;
address owner;
event BoxProduced(uint);
constructor() public {
owner = msg.sender;
}
function produce() external {
require(owner == msg.sender);
productCount++;
if ((productCount % 12) == 0) {
boxCount ++;
emit BoxProduced(boxCount);
}
}
function multiProduce(uint p) external {
require(p > 0);
require(owner == msg.sender);
productCount += p;
if ((productCount / 12) > boxCount) {
uint oldBoxCount = boxCount ;
boxCount = productCount / 12;
for (uint i = oldBoxCount + 1; i <= boxCount; i++)
emit BoxProduced(i);
}
}
function getProductCount() external view returns(uint) {
return(productCount);
}
}