-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoraclizePractice.sol
More file actions
28 lines (23 loc) · 849 Bytes
/
Copy pathoraclizePractice.sol
File metadata and controls
28 lines (23 loc) · 849 Bytes
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
pragma solidity ^0.4.9;
import "github.com/oraclize/ethereum-api/oraclizeAPI.sol";
contract guessExchangeRate is usingOraclize {
string public EURUSD;
event updatedPrice(string price);
event testOraclizeQuery(string description);
function guessExchangeRate() payable {
updatePrice();
}
function __callback(bytes32 myid, string result) {
if (msg.sender != oraclize_cbAddress()) throw;
EURUSD = result;
updatedPrice(result);
}
function fetchExchangeRate() payable {
if (oraclize_getPrice("URL") > this.balance) {
testOraclizeQuery("Oraclize fee not covered, query failed");
} else {
testOraclizeQuery("Oraclize query passed");
oraclize_query("URL", "json(http://api.fixer.io/latest?symbols=USD,EUR).rates.USD");
}
}
}