forked from GX-Coin/SmartContract
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GxTraders.sol
145 lines (112 loc) · 5.07 KB
/
GxTraders.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
pragma solidity ^0.4.2;
import './libraries.sol';
import './GxTradersInterface.sol';
import './GxAccountsInterface.sol';
contract GxTradersPrevious {
function iterateStart() public constant returns (uint);
function iterateValid(uint keyIndex) public constant returns (bool);
function iterateGet(uint keyIndex) public constant returns (address);
function coinBalance(address mappedAddress) public constant returns (uint32);
function dollarBalance(address mappedAddress) public constant returns (int160);
}
contract GxCoinInterfaceForTraders {
GxAccountsInterface public admins;
GxAccountsInterface public deploymentAdmins;
}
contract GxTraders is GxTradersInterface {
using IterableAddressBalanceMapping for IterableAddressBalanceMapping.iterableAddressBalanceMap;
IterableAddressBalanceMapping.iterableAddressBalanceMap traders;
bool public isEditable = true;
address public gxOrdersContract;
GxCoinInterfaceForTraders public greatCoinContract;
// required for constructor signature
function GxTraders(address greatCoinAddress) {
greatCoinContract = GxCoinInterfaceForTraders(greatCoinAddress);
isEditable = true;
}
modifier callableByDeploymentAdmin {
if (isDeploymentAdmin(tx.origin)) {
_;
}
}
modifier callableByGreatCoin {
if (msg.sender == address(greatCoinContract)) {
_;
}
}
function isDeploymentAdmin(address accountAddress) public constant returns (bool _i) {
return greatCoinContract.deploymentAdmins().contains(accountAddress);
}
function setEditable(bool editable) callableByDeploymentAdmin {
isEditable = editable;
}
// Function to recover the funds on the contract
function kill() callableByDeploymentAdmin { suicide(tx.origin); }
function upgrade(GxTradersPrevious gxTradersToUpgrade, uint256 keyIndexStart, uint256 keyIndexEnd) callableByDeploymentAdmin public {
// Deep upgrade, via copying previous data
uint iterationNumber = gxTradersToUpgrade.iterateStart();
if (keyIndexStart > iterationNumber) {
iterationNumber = keyIndexStart;
}
address iterationCurrent;
while (keyIndexEnd >= iterationNumber && gxTradersToUpgrade.iterateValid(iterationNumber)) {
iterationCurrent = gxTradersToUpgrade.iterateGet(iterationNumber);
traders.add(iterationCurrent, gxTradersToUpgrade.coinBalance(iterationCurrent), gxTradersToUpgrade.dollarBalance(iterationCurrent));
iterationNumber++;
}
}
function addOrderContract(address gxOrdersAddress) public callableByDeploymentAdmin {
gxOrdersContract = gxOrdersAddress;
}
function upgradeGreatCoin(address greatCoinAddress) public callableByDeploymentAdmin {
greatCoinContract = GxCoinInterfaceForTraders(greatCoinAddress);
}
modifier callableByGreatCoinOrGxOrders {
if (msg.sender == address(greatCoinContract) || msg.sender == gxOrdersContract) {
_;
}
}
function add(address newAddress) callableByGreatCoin public {
traders.add(newAddress, 0, 0);
}
function remove(address removedAddress) callableByGreatCoin public {
traders.remove(removedAddress);
}
function contains(address lookupAddress) public constant returns (bool _c){
return traders.contains(lookupAddress);
}
function iterateStart() public constant returns (uint keyIndex) {
return iterateNext(0);
}
function iterateValid(uint keyIndex) public constant returns (bool) {
return traders.iterateValid(keyIndex);
}
function iterateNext(uint keyIndex) public constant returns (uint r_keyIndex) {
return traders.iterateNext(keyIndex);
}
function iterateGet(uint keyIndex) public constant returns (address mappedAddress) {
return traders.iterateGet(keyIndex);
}
function coinBalance(address mappedAddress) public constant returns (uint32 coinBalance) {
return traders.valueOfCoinBalance(mappedAddress);
}
function dollarBalance(address mappedAddress) public constant returns (int160 dollarBalance) {
return traders.valueOfDollarBalance(mappedAddress);
}
function setCoinBalance(address mappedAddress, uint32 coinBalance) public callableByGreatCoinOrGxOrders {
traders.setCoinBalance(mappedAddress, coinBalance);
}
function setDollarBalance(address mappedAddress, int160 dollarBalance) public callableByGreatCoinOrGxOrders {
traders.setDollarBalance(mappedAddress, dollarBalance);
}
function addCoinAmount(address mappedAddress, uint32 coinAmount) public callableByGreatCoinOrGxOrders {
traders.addCoinAmount(mappedAddress, coinAmount);
}
function addDollarAmount(address mappedAddress, int160 dollarAmount) public callableByGreatCoinOrGxOrders {
traders.addDollarAmount(mappedAddress, dollarAmount);
}
function length() public constant returns (uint) {
// get the length of the trader list to help with next contract upgrade
return traders.length();
}
}