Skip to content

Commit 5cc78ae

Browse files
committed
Added a simpler implementation of a payer/payee escrow
1 parent 8a75067 commit 5cc78ae

File tree

7 files changed

+119
-22
lines changed

7 files changed

+119
-22
lines changed

contracts/market/Job.sol

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
pragma solidity ^0.4.18;
2+
3+
contract Job {
4+
uint256 public status = 0;
5+
bytes32 public jobDescriptor;
6+
bytes32 public jobResult;
7+
8+
uint256 public start;
9+
uint256 public end;
10+
11+
address public payer;
12+
address public payee;
13+
14+
event JobStarted(address indexed payer, address indexed payee, bytes32 jobDescriptor, address jobAddress);
15+
event JobCompleted(bytes32 jobResult, address jobAddress);
16+
17+
function setJobStarted(address _payer, address _payee, bytes32 _jobDescriptor) public {
18+
require(status < 1);
19+
payer = _payer;
20+
payee = _payee;
21+
jobDescriptor = _jobDescriptor;
22+
status = 1;
23+
start = now;
24+
25+
JobStarted(payer, payee, jobDescriptor, address(this));
26+
}
27+
28+
function setJobCompleted(bytes32 _jobResult) public {
29+
require(msg.sender == payee);
30+
require(status < 2);
31+
status = 2;
32+
jobResult = _jobResult;
33+
end = now;
34+
35+
JobCompleted(jobResult, address(this));
36+
37+
}
38+
39+
}

contracts/market/Market.sol

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* pragma solidity ^0.4.18;
2+
3+
4+
contract Market {
5+
6+
address public owner;
7+
mapping (address => uint256) public jobs;
8+
9+
function Market() public {
10+
owner = msg.sender;
11+
}
12+
13+
function ask() public {
14+
15+
}
16+
17+
function sell() public {
18+
19+
}
20+
21+
function stake() pure {
22+
23+
}
24+
25+
} */

migrations/2_deploy_contracts.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
const fs = require('fs')
22

3-
const AgentFactory = artifacts.require('agent/AgentFactory.sol')
43
const AgentRegistry = artifacts.require('registries/AgentRegistry.sol')
4+
const Job = artifacts.require('market/Job.sol')
5+
/* const AgentFactory = artifacts.require('agent/AgentFactory.sol')
56
const MarketJobFactory = artifacts.require('market/MarketJobFactory.sol')
67
const SingularityNetToken = artifacts.require('tokens/SingularityNetToken.sol')
7-
const TokenVestingFactory = artifacts.require('tokens/TokenVestingFactory.sol')
8+
const TokenVestingFactory = artifacts.require('tokens/TokenVestingFactory.sol') */
89

910
module.exports = function(deployer, network, accounts) {
1011
deployer.deploy([
11-
AgentFactory,
12-
AgentRegistry,
13-
MarketJobFactory,
14-
SingularityNetToken,
15-
TokenVestingFactory
12+
Job,
13+
AgentRegistry
1614
]).then(() => {
1715
const fileName = "addresses.json"
1816
const content = {
19-
AgentFactory: AgentFactory.address,
17+
//AgentFactory: AgentFactory.address,
18+
Job: Job.address,
2019
AgentRegistry: AgentRegistry.address,
21-
MarketJobFactory: MarketJobFactory.address,
22-
SingularityNetToken: SingularityNetToken.address,
23-
TokenVestingFactory: TokenVestingFactory.address
20+
//MarketJobFactory: MarketJobFactory.address,
21+
//SingularityNetToken: SingularityNetToken.address,
22+
//TokenVestingFactory: TokenVestingFactory.address
2423
}
2524

2625
fs.writeFile(fileName, JSON.stringify(content), 'utf-8', (err) => {

migrations/3_deploy_crowdsale_contract.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const duration = {
1616
}
1717

1818
module.exports = function(deployer, network, accounts) {
19+
if (network!=='live') return;
1920
const startTime = latestTime() + duration.minutes(5)
2021
const endTime = startTime + duration.days(20)
2122
const rate = new web3.BigNumber(1000)

migrations/4_deploy_tokenvesting_contract.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ const SingularityNetToken = artifacts.require("token/SingularityNetToken.sol")
33

44

55
module.exports = function (deployer, network, accounts) {
6-
const beneficiary = accounts[0]
7-
8-
const start = 1450656000
9-
const cliff = 31536000 // ~1 yr
10-
const duration = 126144000 // ~4yrs
11-
12-
const amount = 5000 * 1e18
13-
14-
deployer.deploy(TokenVesting,beneficiary,start,cliff,duration,true)
6+
if (network !== 'live') return;
7+
const beneficiary = accounts[0]
8+
9+
const start = 1450656000
10+
const cliff = 31536000 // ~1 yr
11+
const duration = 126144000 // ~4yrs
12+
13+
const amount = 5000 * 1e18
14+
15+
deployer.deploy(TokenVesting, beneficiary, start, cliff, duration, true)
1516
};

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@
77
"test": "test"
88
},
99
"scripts": {
10+
"compile": "node_modules/.bin/truffle compile",
11+
"deploy": "node_modules/.bin/truffle migrate",
1012
"test": "node_modules/.bin/truffle test"
1113
},
1214
"author": "tiero",
1315
"license": "MIT",
1416
"dependencies": {
1517
"truffle": "4.0.1",
16-
"truffle-hdwallet-provider": "0.0.3",
1718
"zeppelin-solidity": "1.4.0"
1819
},
1920
"devDependencies": {
2021
"chai": "^4.1.2",
2122
"chai-as-promised": "^7.1.1",
22-
"chai-bignumber": "^2.0.2"
23+
"chai-bignumber": "^2.0.2",
24+
"truffle-hdwallet-provider": "^0.0.3"
2325
}
2426
}

test/TestJob.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const Job = artifacts.require('market/Job.sol')
2+
3+
4+
contract('Job', function ([payer, payee]) {
5+
6+
beforeEach(async () => {
7+
this.job = await Job.new()
8+
})
9+
10+
it('JOB STARTED', async () => {
11+
const jobDescriptor = "0x0"
12+
13+
const { logs } = await this.job.setJobStarted(payer, payee, jobDescriptor)
14+
const found = logs.find(e => e.event === 'JobStarted')
15+
assert.strictEqual(found.event, 'JobStarted', 'Job not started')
16+
})
17+
18+
it('JOB COMPLETED', async () => {
19+
const jobDescriptor = "0x0"
20+
const jobResult = "0x0102"
21+
22+
await this.job.setJobStarted(payer, payee, jobDescriptor)
23+
//Complete jobs
24+
const { logs } = await this.job.setJobCompleted(jobResult, {from:payee})
25+
const found = logs.find(e => e.event === 'JobCompleted')
26+
assert.strictEqual(found.event, 'JobCompleted', 'Job not completed')
27+
})
28+
29+
30+
})

0 commit comments

Comments
 (0)