-
Notifications
You must be signed in to change notification settings - Fork 4
/
device.sol
53 lines (38 loc) · 1.13 KB
/
device.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// -*- javascript -*-
pragma solidity ^0.4.16;
contract Device {
// store the value in 100th of kelvins, e.g. 0C is 27315
uint private temperature;
// actuator value
uint private actuator;
// owner of the contract, they are the one only able to set() the
// temperature value
address private owner;
// payment required for setting the actuator
uint constant price = 1000000; // 1 Mwei
function Device() public {
owner = msg.sender;
temperature = 0;
}
event Measured(uint temperature);
function set(uint t) public {
require(msg.sender == owner);
temperature = t;
Measured(temperature);
}
function get() public view returns (uint) {
return temperature;
}
event Actuated(uint actuation);
function actuate(uint value) public payable {
require(msg.value >= price);
uint excess = msg.value - price;
if (excess > 0)
msg.sender.transfer(excess);
actuator = value;
Actuated(actuator);
}
function actuation() public view returns (uint) {
return actuator;
}
}