-
Notifications
You must be signed in to change notification settings - Fork 1
/
ExchangeRates.sol
35 lines (29 loc) · 987 Bytes
/
ExchangeRates.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
pragma solidity ^0.4.18;
contract ExchangeRates {
address goldSource;
address cashSource;
mapping (string => uint256) cashRates;
mapping (string => bool) cashReady;
uint256 public goldPrice;
bool public goldReady;
function ExchangeRates(address goldSource_, address cashSource_) public {
goldSource = goldSource_;
cashSource = cashSource_;
}
function setGoldPrice(uint newPrice) public {
require(msg.sender == goldSource);
goldPrice = newPrice;
goldReady = true;
}
function setCashRate(string currency, uint256 rate) public {
require(msg.sender == cashSource);
cashRates[currency] = rate;
cashReady[currency] = true;
}
function getGoldPrice(string currency) public view returns (uint256 price, bool ok) {
if (!cashReady[currency]) return;
if (!goldReady) return;
price = cashRates[currency] * goldPrice / 1 ether;
ok = true;
}
}