-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWeatherData.sol
38 lines (30 loc) · 1.01 KB
/
WeatherData.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
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.16;
contract WeatherData {
uint[] public weatherData;
address public owner;
event Update(uint[] dataArray);
// owner can update weather data
function updateData(uint temperature, uint humidity, uint luminosity, uint pressure) public {
require(msg.sender == owner);
weatherData = [temperature, humidity, luminosity, pressure];
emit Update(weatherData);
}
// owner can withdraw
function withdraw() public {
require(msg.sender == owner);
payable(msg.sender).transfer(address(this).balance);
}
// sets owner
constructor() payable {
owner = 0x06f4DB783097c632B888669032B2905F70e08105;
}
// to support receiving ETH by default
receive() external payable {}
fallback() external payable {}
// owner can set new owner if needed
function setOwner(address newOwner) external {
require(msg.sender == owner);
owner = newOwner;
}
}