@@ -3,17 +3,18 @@ pragma solidity ^0.4.18;
3
3
import "./Job.sol " ;
4
4
import "zeppelin-solidity/contracts/token/ERC20.sol " ;
5
5
6
+
6
7
contract Escrow is Job {
7
8
/**
8
- * @dev Kovan AGI token.
9
+ * @dev Kovan token.
9
10
* https://kovan.etherscan.io/token/0x3b226ff6aad7851d3263e53cb7688d13a07f6e81#readContract
10
11
*/
11
- ERC20 public constant AGI = ERC20 ( 0x3b226ff6aad7851d3263e53cb7688d13a07f6e81 ) ;
12
-
12
+ ERC20 public token ;
13
+
13
14
/**
14
- * @dev Vault mapping
15
+ * @dev Fund Timelock in milliseconds
15
16
*/
16
- mapping ( address => mapping ( address => uint256 )) public vault ;
17
+ uint256 public timelock ;
17
18
18
19
/**
19
20
* @dev Deposited event
@@ -25,44 +26,73 @@ contract Escrow is Job {
25
26
*/
26
27
event Withdrew (address payee , uint256 amount );
27
28
28
- /**
29
+ /**
29
30
* @dev Escrow constructor.
30
31
* @param _payer An agent who pays the job.
31
32
* @param _payee An agent to whom the job is paid.
32
- * @param _cost Cost in AGI
33
+ * @param _timelock how many seconds after end should be the window for rejections
34
+ * @param _validator who should check if rejected
33
35
* @param _reward reward for validator
34
36
*/
35
37
function Escrow (
38
+ address _token ,
36
39
address _payer ,
37
- address _payee ,
38
- bytes32 _descriptor ,
39
- uint256 _cost ,
40
+ address _payee ,
41
+ uint256 _timelock ,
42
+ address _validator ,
40
43
uint256 _reward ) public
41
44
{
45
+ token = ERC20 (_token);
42
46
payer = _payer;
43
47
payee = _payee;
44
- descriptor = _descriptor;
45
- cost = _cost;
48
+
49
+ timelock = _timelock;
50
+ //Reward for the validator in case of dispute
51
+ validator = _validator;
46
52
reward = _reward;
47
53
54
+ //Who actually should deliver the job, capable of setResult and close the job
55
+ //Beaware that who can withdraw money is still the payee, not the provider
48
56
provider = payee;
49
- start = now ;
50
57
51
- Started (payer, payee, descriptor, address (this ));
52
58
}
53
59
60
+ /**
61
+ * @dev Deposit function.
62
+ * @param _amount Token amount to fill the price
63
+ * @param _descriptor bytes hash that represent the input for the job
64
+ */
65
+ function deposit (uint256 _amount , bytes32 _descriptor ) public {
66
+ require (msg .sender == payer);
67
+ require (token.transferFrom (msg .sender , this , _amount));
68
+ Deposited (msg .sender , _amount);
69
+
70
+ descriptor = _descriptor;
71
+ price = _amount;
72
+ start = now ;
54
73
55
- function deposit (uint256 amount ) public {
56
- require (AGI.transferFrom (msg .sender , this , amount));
57
-
58
- Deposited (msg .sender ,amount);
74
+ Started (payer, payee, descriptor, address (this ));
59
75
}
60
76
77
+ /**
78
+ * @dev withdraw all funds from escrow
79
+ */
61
80
function withdraw () public {
62
81
require (msg .sender == payee);
63
- require (status == 1 );
64
- uint256 balance = AGI.balanceOf (this );
65
- require (AGI.transfer (msg .sender , balance));
82
+ require (timelockExpired ());
83
+ require (! isRejected);
84
+
85
+ uint256 balance = token.balanceOf (this );
86
+ require (balance > 0 );
87
+
88
+ require (token.transfer (msg .sender , balance));
66
89
Withdrew (msg .sender , balance);
67
90
}
91
+
92
+ function timelockExpired () internal constant returns (bool ) {
93
+ bool isExpired = (end + timelock) <= block .timestamp ;
94
+ return isCompleted && isExpired ;
95
+ }
96
+
97
+
68
98
}
0 commit comments