-
Notifications
You must be signed in to change notification settings - Fork 0
/
surveillance-cameraV3.sol
51 lines (42 loc) · 1.6 KB
/
surveillance-cameraV3.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
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
contract CameraControl {
address public cameraOwner;
string public cameraName;
uint public lastOnTime;
uint public turnOnCount;
uint public turnOffCount;
event CameraTurnedOn(uint timestamp);
event CameraTurnedOff(uint timestamp);
constructor(address _cameraOwner, string memory _name) {
cameraOwner = _cameraOwner;
cameraName = _name;
}
function setCameraOwner(address _newOwner) public {
require(msg.sender == cameraOwner, "Only camera owner can change the camera owner.");
cameraOwner = _newOwner;
}
function getCameraOwner() public view returns (address) {
return cameraOwner;
}
function getCameraName() public view returns (string memory) {
return cameraName;
}
function turnOn() public {
require(msg.sender == cameraOwner, "Only camera owner can turn on the camera.");
require(turnOnCount == turnOffCount, "Cannot turn on the camera as it is already on.");
lastOnTime = block.timestamp;
turnOnCount++;
emit CameraTurnedOn(lastOnTime);
}
function turnOff() public {
require(msg.sender == cameraOwner, "Only camera owner can turn off the camera.");
require(turnOnCount > turnOffCount, "Cannot turn off the camera as it is already off.");
turnOffCount++;
emit CameraTurnedOff(block.timestamp);
}
function getLastOnTime() public view returns (uint) {
require(turnOnCount > turnOffCount, "Camera is currently off.");
return lastOnTime;
}
}