Skip to content

Commit 1dbbfee

Browse files
committed
Refactor MarketJob to more lightweight contract with acceptance and rejection mechanism
1 parent 6b63f72 commit 1dbbfee

File tree

8 files changed

+152
-225
lines changed

8 files changed

+152
-225
lines changed

contracts/market/Escrow.sol

Lines changed: 0 additions & 27 deletions
This file was deleted.

contracts/market/Job.sol

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,66 @@
11
pragma solidity ^0.4.18;
22

3-
contract Job {
4-
uint256 public status = 0;
5-
bytes32 public jobDescriptor;
6-
bytes32 public jobResult;
3+
import './JobValidator.sol';
4+
/**
5+
* @title The wrapped Job contract
6+
*/
7+
contract Job is JobValidator {
78

8-
uint256 public start;
9-
uint256 public end;
9+
/**
10+
* @dev Kovan AGI token.
11+
* https://kovan.etherscan.io/token/0x3b226ff6aad7851d3263e53cb7688d13a07f6e81#readContract
12+
* ERC20Basic public constant AGI = ERC20Basic(0x3b226ff6aad7851d3263e53cb7688d13a07f6e81);
13+
*/
1014

11-
address public payer;
12-
address public payee;
15+
/**
16+
* @dev Cost in AGI for the exection of the job
17+
* (10**8 cogs === 1 AGI)
18+
*/
19+
uint256 public cost;
1320

14-
event JobStarted(address indexed payer, address indexed payee, bytes32 jobDescriptor, address jobAddress);
15-
event JobCompleted(bytes32 jobResult, address jobAddress);
21+
/**
22+
* @dev Started event
23+
*/
24+
event Started(address indexed payer, address indexed payee, bytes32 descriptor, address job);
25+
26+
/**
27+
* @dev Job constructor.
28+
* @param _payer An agent who pays the job.
29+
* @param _payee An agent to whom the job is paid.
30+
* @param _cost Cost in AGI
31+
*/
32+
function Job(address _payer, address _payee, bytes32 _descriptor, uint256 _cost, uint256 _reward) public {
1633

17-
function setJobStarted(address _payer, address _payee, bytes32 _jobDescriptor) public {
18-
require(status < 1);
1934
payer = _payer;
2035
payee = _payee;
21-
jobDescriptor = _jobDescriptor;
22-
status = 1;
36+
descriptor = _descriptor;
37+
cost = _cost;
38+
reward = _reward;
39+
2340
start = now;
2441

25-
JobStarted(payer, payee, jobDescriptor, address(this));
42+
Started(payer, payee, descriptor, address(this));
2643
}
2744

28-
function setJobCompleted(bytes32 _jobResult) public {
45+
/**
46+
* @dev Set result of this Job
47+
* @param _result Result data hash
48+
*/
49+
function setResult(bytes32 _result) public returns (bool) {
2950
require(msg.sender == payee);
30-
require(status < 2);
31-
status = 2;
32-
jobResult = _jobResult;
51+
require(descriptor.length > 0);
52+
require(result.length == 0);
53+
3354
end = now;
55+
56+
Result(_result);
57+
result = _result;
3458

35-
JobCompleted(jobResult, address(this));
59+
Completed();
3660

61+
return true;
3762
}
3863

64+
65+
3966
}

contracts/market/JobInterface.sol

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
pragma solidity ^0.4.18;
2+
3+
/**
4+
* @title The Job Interface contract
5+
*/
6+
7+
contract JobInterface {
8+
/**
9+
* @dev Starting hash of the job
10+
*/
11+
bytes32 public descriptor;
12+
13+
/**
14+
* @dev Result hash of the job
15+
*/
16+
bytes32 public result;
17+
18+
/**
19+
* @dev Start time timestamp
20+
*/
21+
uint256 public start;
22+
23+
/**
24+
* @dev End time timestamp
25+
*/
26+
uint256 public end;
27+
28+
/**
29+
* @dev An agent who pays the job.
30+
*/
31+
address public payer;
32+
33+
/**
34+
* @dev An agent to whom the job is paid.
35+
*/
36+
address public payee;
37+
38+
/**
39+
* @dev Broadcast new hash as job result.
40+
*/
41+
event Result(bytes32 result);
42+
}

contracts/market/JobValidator.sol

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
pragma solidity ^0.4.18;
2+
3+
import './JobInterface.sol';
4+
5+
/**
6+
* @title The Job Validator contract
7+
*/
8+
9+
contract JobValidator is JobInterface {
10+
11+
/**
12+
* @dev Reward for validator in AGI.
13+
*/
14+
address public validator;
15+
16+
/**
17+
* @dev Validation status
18+
* 0 == pending && 1 == accepted && 2 == rejected
19+
*/
20+
address public status = 0;
21+
22+
/**
23+
* @dev Reward for validator in AGI.
24+
*/
25+
uint256 public reward;
26+
27+
/**
28+
* @dev Completed event to notice the validators pool
29+
*/
30+
event Completed();
31+
32+
/**
33+
* @dev Approved event to notice the parties
34+
*/
35+
event Accepted();
36+
37+
/**
38+
* @dev Rejected event to notice the parties
39+
*/
40+
event Rejected();
41+
42+
43+
/**
44+
* @dev Confirm job result
45+
*/
46+
function accept() public {
47+
validator = msg.sender;
48+
status = 1;
49+
50+
Accepted();
51+
}
52+
53+
/**
54+
* @dev Reject job result
55+
*/
56+
function reject() public {
57+
validator = msg.sender;
58+
status = 2;
59+
60+
Rejected();
61+
}
62+
63+
}

contracts/market/Market.sol

Lines changed: 0 additions & 45 deletions
This file was deleted.

contracts/market/MarketJobFactory.sol

Lines changed: 0 additions & 31 deletions
This file was deleted.

contracts/market/MarketJobInterface.sol

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)