-
Notifications
You must be signed in to change notification settings - Fork 0
/
RandomWeatherOracle.sol
70 lines (55 loc) · 1.55 KB
/
RandomWeatherOracle.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
pragma solidity ^0.5.2;
import "github.com/starkware-libs/veedo/blob/master/contracts/BeaconContract.sol";
contract Beacon{
function getLatestRandomness()external view returns(uint256,bytes32){}
}
contract WeatherOracle {
address public oracleAddress;
address public BeaconContractAddress=0x79474439753C7c70011C3b00e06e559378bAD040;
constructor (address _oracleAddress) public {
oracleAddress = _oracleAddress;
}
function setBeaconContractAddress(address _address) public {
BeaconContractAddress=_address;
}
function generateRandomNumber() public view returns(bytes32){
uint blockNumber;
bytes32 randomNumber;
Beacon beacon=Beacon(BeaconContractAddress);
(blockNumber,randomNumber)=beacon.getLatestRandomness();
return randomNumber;
}
event WeatherUpdate (
string weatherDescription,
string temperature,
string humidity,
string visibility,
string windSpeed,
string windDirection,
string windGust
);
function updateWeather (
string memory weatherDescription,
string memory temperature,
string memory humidity,
string memory visibility,
string memory windSpeed,
string memory windDirection,
string memory windGust
)
public
{
require(msg.sender == oracleAddress);
if ((bytes32(block.number))> generateRandomNumber()) {
emit WeatherUpdate (
weatherDescription,
temperature,
humidity,
visibility,
windSpeed,
windDirection,
windGust
);
}
}
}