-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOracle.sol
95 lines (72 loc) · 2.35 KB
/
Oracle.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
pragma solidity ^0.4.16;
contract Admin {
address public owner;
function Admin() {
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
}
contract Oracle is Admin{
string constant configKey = "configKey";
string constant priceKey = "priceKey";
Config public config;
mapping (string => uint) configMapping; //config
mapping (string => uint128) priceMapping; //prices
mapping (address => bool) public auths; //auths
event OracleOperated(address indexed from,string opType,uint256 opValue);
function Oracle() public {
}
// 实现所有权转移
function transferOwnership(address newOwner) onlyOwner {
owner = newOwner;
}
function flush() public onlyOwner{
config = Config(getConfig("liquidate_line_rate_c"),
getConfig("liquidate_dis_rate_c"),
getConfig("fee_rate_c"),
getConfig("liquidate_top_rate_c"),
getConfig("liquidate_line_rateT_c"),
getConfig("issuing_fee_c"),
getConfig("debt_top_c"));
}
function setAuth(address addr) public onlyOwner returns(bool success){
auths[addr] = true;
return true;
}
function releaseAuth(address addr) public onlyOwner returns(bool success){
auths[addr] = false;
return true;
}
function setConfig(string key,uint set) public returns(bool success){
require(auths[msg.sender]);
configMapping[key] = set;
OracleOperated(msg.sender,key,set);
return true;
}
function getConfig(string key) public view returns(uint value){
return configMapping[key];
}
function setPrice(string key,uint128 set) public returns(bool success){
require(auths[msg.sender]);
priceMapping[key]=set;
OracleOperated(msg.sender,key,set);
return true;
}
function getPrice(string key) public view returns(uint128 value){
return priceMapping[key];
}
//Oracle config
struct Config
{
uint liquidate_line_rate_c;
uint liquidate_dis_rate_c;
uint fee_rate_c;
uint liquidate_top_rate_c;
uint liquidate_line_rateT_c;
uint issuing_fee_c;
uint debt_top_c;
}
}