Skip to content

Commit 6fe2c6a

Browse files
committed
Solution proposal for #28 #29 #30 & #31
1 parent fc40a5d commit 6fe2c6a

File tree

5 files changed

+67
-146
lines changed

5 files changed

+67
-146
lines changed

contracts/IexecAPI.sol

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@ contract IexecAPI is OwnableOZ, IexecHubAccessor, IexecCallbackInterface
1414
event WithdrawRLCFromIexecHub(address iexecHub, uint256 amount);
1515

1616
address public m_callbackProofAddress;
17-
address public m_rlcAddress;
1817

1918
// Constructor
20-
function IexecAPI(address _iexecHubAddress,address _callbackProofAddress, address _rlcAddress)
19+
function IexecAPI(address _iexecHubAddress, address _callbackProofAddress)
2120
IexecHubAccessor(_iexecHubAddress)
2221
public
2322
{
24-
m_callbackProofAddress=_callbackProofAddress;
25-
m_rlcAddress =_rlcAddress;
23+
m_callbackProofAddress = _callbackProofAddress;
2624
}
2725

2826
function buyForWorkOrder(
@@ -53,15 +51,15 @@ contract IexecAPI is OwnableOZ, IexecHubAccessor, IexecCallbackInterface
5351

5452
function approveIexecHub(uint256 amount) public onlyOwner returns (bool)
5553
{
56-
RLC rlc = RLC(m_rlcAddress);
57-
require(rlc.approve(iexecHubAddress, amount));
58-
emit ApproveIexecHub(iexecHubAddress, amount);
54+
RLC rlc = iexecHubInterface.rlc();
55+
require(rlc.approve(address(iexecHubInterface), amount));
56+
emit ApproveIexecHub(address(iexecHubInterface), amount);
5957
return true;
6058
}
6159

6260
function withdrawRLCFromIexecAPI(uint256 amount) public onlyOwner returns (bool)
6361
{
64-
RLC rlc = RLC(m_rlcAddress);
62+
RLC rlc = iexecHubInterface.rlc();
6563
require(rlc.transfer(msg.sender, amount));
6664
emit WithdrawRLCFromIexecAPI(msg.sender, amount);
6765
return true;
@@ -70,15 +68,15 @@ contract IexecAPI is OwnableOZ, IexecHubAccessor, IexecCallbackInterface
7068
function depositRLCOnIexecHub(uint256 amount) public onlyOwner returns (bool)
7169
{
7270
require(iexecHubInterface.deposit(amount));
73-
emit DepositRLCOnIexecHub(iexecHubAddress, amount);
71+
emit DepositRLCOnIexecHub(address(iexecHubInterface), amount);
7472
return true;
7573
}
7674

7775
function withdrawRLCFromIexecHub(uint256 amount) public onlyOwner returns (bool)
7876
{
7977
require(iexecHubInterface.withdraw(amount));
8078
require(withdrawRLCFromIexecAPI(amount));
81-
emit WithdrawRLCFromIexecHub(iexecHubAddress, amount);
79+
emit WithdrawRLCFromIexecHub(address(iexecHubInterface), amount);
8280
return true;
8381
}
8482

contracts/IexecHub.sol

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ contract IexecHub
2222
/**
2323
* RLC contract for token transfers.
2424
*/
25-
RLC public rlc;
26-
address public tokenAddress;
25+
RLC public rlc;
2726

28-
uint256 public constant STAKE_BONUS_RATIO = 10;
27+
uint256 public constant STAKE_BONUS_RATIO = 10;
2928
uint256 public constant STAKE_BONUS_MIN_THRESHOLD = 1000;
30-
31-
uint256 public constant SCORE_UNITARY_SLASH = 50;
29+
uint256 public constant SCORE_UNITARY_SLASH = 50;
3230

3331
/**
3432
* Slaves contracts
@@ -41,10 +39,9 @@ contract IexecHub
4139
* Market place
4240
*/
4341
Marketplace marketplace;
44-
address public marketplaceAddress;
4542
modifier onlyMarketplace()
4643
{
47-
require(msg.sender == marketplaceAddress);
44+
require(msg.sender == address(marketplace));
4845
_;
4946
}
5047
/**
@@ -96,34 +93,33 @@ contract IexecHub
9693
/**
9794
* Constructor
9895
*/
99-
function IexecHub(
100-
)
96+
function IexecHub()
10197
public
10298
{
103-
99+
m_categoriesCreator = msg.sender;
104100
}
105101

106-
107-
function attachContracts(address _tokenAddress,address _marketplaceAddress, address _workerPoolHubAddress, address _appHubAddress, address _datasetHubAddress) public
102+
function attachContracts(
103+
address _tokenAddress,
104+
address _marketplaceAddress,
105+
address _workerPoolHubAddress,
106+
address _appHubAddress,
107+
address _datasetHubAddress)
108+
public onlyCategoriesCreator
108109
{
109-
require(tokenAddress == address(0));
110-
tokenAddress = _tokenAddress;
111-
rlc = RLC(_tokenAddress);
112-
113-
marketplaceAddress = _marketplaceAddress;
114-
marketplace = Marketplace(_marketplaceAddress);
115-
110+
require(address(rlc) == address(0));
111+
rlc = RLC (_tokenAddress );
112+
marketplace = Marketplace (_marketplaceAddress );
116113
workerPoolHub = WorkerPoolHub(_workerPoolHubAddress);
117114
appHub = AppHub (_appHubAddress );
118115
datasetHub = DatasetHub (_datasetHubAddress );
119116
}
120117

121-
function setCategoriesCreator(address _categoriesCreator) public
118+
function setCategoriesCreator(address _categoriesCreator)
119+
public onlyCategoriesCreator
122120
{
123-
require(m_categoriesCreator == address(0) || (m_categoriesCreator != address(0) && msg.sender == m_categoriesCreator));
124121
m_categoriesCreator = _categoriesCreator;
125122
}
126-
127123
/**
128124
* Factory
129125
*/
@@ -156,7 +152,7 @@ contract IexecHub
156152
_subscriptionLockStakePolicy,
157153
_subscriptionMinimumStakePolicy,
158154
_subscriptionMinimumScorePolicy,
159-
marketplaceAddress
155+
address(marketplace)
160156
);
161157
emit CreateWorkerPool(tx.origin, newWorkerPool, _description);
162158
return newWorkerPool;

contracts/IexecHubAccessor.sol

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@ import './IexecHubInterface.sol';
44

55
contract IexecHubAccessor
66
{
7-
address internal iexecHubAddress;
87
IexecHubInterface internal iexecHubInterface;
98

109
modifier onlyIexecHub()
1110
{
12-
require(msg.sender == iexecHubAddress);
11+
require(msg.sender == address(iexecHubInterface));
1312
_;
1413
}
1514

1615
function IexecHubAccessor(address _iexecHubAddress) public
1716
{
1817
require(_iexecHubAddress != address(0));
19-
iexecHubAddress = _iexecHubAddress;
2018
iexecHubInterface = IexecHubInterface(_iexecHubAddress);
2119
}
2220

contracts/IexecHubInterface.sol

Lines changed: 33 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
pragma solidity ^0.4.21;
2-
import './IexecLib.sol';
2+
3+
import "rlc-token/contracts/RLC.sol";
4+
35
contract IexecHubInterface
46
{
5-
function attachMarketplace(
6-
address _marketplaceAddress)
7-
public;
7+
RLC public rlc;
8+
9+
function attachContracts(
10+
address _tokenAddress,
11+
address _marketplaceAddress,
12+
address _workerPoolHubAddress,
13+
address _appHubAddress,
14+
address _datasetHubAddress)
15+
public;
816

917
function setCategoriesCreator(
1018
address _categoriesCreator)
1119
public;
1220

13-
14-
1521
function createCategory(
1622
string _name,
1723
string _description,
1824
uint256 _workClockTimeRef)
19-
public /* onlyCategoriesCreator */ returns (uint256 catid);
25+
public returns (uint256 catid);
2026

2127
function createWorkerPool(
22-
string _name,
28+
string _description,
2329
uint256 _subscriptionLockStakePolicy,
2430
uint256 _subscriptionMinimumStakePolicy,
2531
uint256 _subscriptionMinimumScorePolicy)
@@ -47,32 +53,13 @@ contract IexecHubInterface
4753
address _beneficiary)
4854
external returns (address);
4955

50-
function emitWorkOrder(
51-
uint256 _marketorderIdx,
52-
address _requester,
53-
address _workerpool, // Address of a smartcontract
54-
address _app, // Address of a smartcontract
55-
address _dataset, // Address of a smartcontract
56-
string _params,
57-
address _callback,
58-
address _beneficiary)
59-
internal returns (address);
60-
6156
function lockWorkOrderCost(
6257
address _requester,
6358
address _workerpool, // Address of a smartcontract
6459
address _app, // Address of a smartcontract
6560
address _dataset) // Address of a smartcontract
6661
internal returns (uint256);
6762

68-
function startRevealingPhase(
69-
address _woid)
70-
public returns (bool);
71-
72-
function reActivate(
73-
address _woid)
74-
public returns (bool);
75-
7663
function claimFailedConsensus(
7764
address _woid)
7865
public returns (bool);
@@ -94,103 +81,45 @@ contract IexecHubInterface
9481

9582
function getCategory(
9683
uint256 _catId)
97-
public view returns (uint256 catid, string name, string description, uint256 workClockTimeRef);
84+
public view returns (uint256 catid, string name, string description, uint256 workClockTimeRef);
9885

9986
function getWorkerStatus(
10087
address _worker)
10188
public view returns (address workerPool, uint256 workerScore);
10289

103-
function getWorkerScore(
104-
address _worker)
105-
public view returns (uint256 workerScore);
90+
function getWorkerScore(address _worker) public view returns (uint256 workerScore);
10691

107-
function registerToPool(address _worker)
108-
public returns (bool subscribed);
92+
function registerToPool(address _worker) public returns (bool subscribed);
10993

110-
function unregisterFromPool(address _worker)
111-
public returns (bool unsubscribed);
94+
function unregisterFromPool(address _worker) public returns (bool unsubscribed);
11295

113-
function evictWorker(
114-
address _worker)
115-
public returns (bool unsubscribed);
116-
117-
function lockForOrder(
118-
address _user,
119-
uint256 _amount)
120-
public /* onlyMarketplace */ returns (bool);
96+
function evictWorker(address _worker) public returns (bool unsubscribed);
12197

122-
function unlockForOrder(
123-
address _user,
124-
uint256 _amount)
125-
public /* onlyMarketplace */ returns (bool);
98+
function removeWorker(address _workerpool, address _worker) internal returns (bool unsubscribed);
12699

127-
function seizeForOrder(
128-
address _user,
129-
uint256 _amount)
130-
public /* onlyMarketplace */ returns (bool);
100+
function lockForOrder(address _user, uint256 _amount) public returns (bool);
131101

132-
function rewardForOrder(
133-
address _user,
134-
uint256 _amount)
135-
public /* onlyMarketplace */ returns (bool);
102+
function unlockForOrder(address _user, uint256 _amount) public returns (bool);
136103

137-
function lockForWork(
138-
address _woid,
139-
address _user,
140-
uint256 _amount)
141-
public returns (bool);
104+
function lockForWork(address _woid, address _user, uint256 _amount) public returns (bool);
142105

143-
function unlockForWork(
144-
address _woid,
145-
address _user,
146-
uint256 _amount)
147-
public returns (bool);
148-
149-
function rewardForWork(
150-
address _woid,
151-
address _worker,
152-
uint256 _amount,
153-
bool _reputation)
154-
public returns (bool);
155-
156-
function seizeForWork(
157-
address _woid,
158-
address _worker,
159-
uint256 _amount,
160-
bool _reputation)
161-
public returns (bool);
106+
function unlockForWork(address _woid, address _user, uint256 _amount) public returns (bool);
162107

163-
function deposit(
164-
uint256 _amount)
165-
external returns (bool);
108+
function rewardForWork(address _woid, address _worker, uint256 _amount, bool _reputation) public returns (bool);
166109

167-
function withdraw(
168-
uint256 _amount)
169-
external returns (bool);
110+
function seizeForWork(address _woid, address _worker, uint256 _amount, bool _reputation) public returns (bool);
170111

171-
function checkBalance(
172-
address _owner)
173-
public view returns (uint256 stake, uint256 locked);
112+
function deposit(uint256 _amount) external returns (bool);
174113

175-
function reward(
176-
address _user,
177-
uint256 _amount)
178-
internal returns (bool);
114+
function withdraw(uint256 _amount) external returns (bool);
179115

180-
function seize(
181-
address _user,
182-
uint256 _amount)
183-
internal returns (bool);
116+
function checkBalance(address _owner) public view returns (uint256 stake, uint256 locked);
184117

185-
function lock(
186-
address _user,
187-
uint256 _amount)
188-
internal returns (bool);
118+
function reward(address _user, uint256 _amount) internal returns (bool);
189119

190-
function unlock(
191-
address _user,
192-
uint256 _amount)
193-
internal returns (bool);
120+
function seize(address _user, uint256 _amount) internal returns (bool);
194121

122+
function lock(address _user, uint256 _amount) internal returns (bool);
195123

124+
function unlock(address _user, uint256 _amount) internal returns (bool);
196125
}

contracts/OwnableOZ.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pragma solidity ^0.4.21;
88
contract OwnableOZ
99
{
1010
address public m_owner;
11-
bool public changeable;
11+
bool public m_changeable;
1212

1313
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
1414

@@ -27,8 +27,8 @@ contract OwnableOZ
2727
*/
2828
function OwnableOZ() public
2929
{
30-
m_owner = msg.sender;
31-
changeable =true;
30+
m_owner = msg.sender;
31+
m_changeable = true;
3232
}
3333

3434
/**
@@ -37,11 +37,11 @@ contract OwnableOZ
3737
*/
3838
function setImmutableOwnership(address _newOwner) public onlyOwner
3939
{
40-
require(changeable);
40+
require(m_changeable);
4141
require(_newOwner != address(0));
42-
m_owner = _newOwner;
43-
changeable = false;
4442
emit OwnershipTransferred(m_owner, _newOwner);
43+
m_owner = _newOwner;
44+
m_changeable = false;
4545
}
4646

4747
}

0 commit comments

Comments
 (0)