Skip to content

Commit

Permalink
Merged relevant parts of WorkAgreement into WorkDispatcher.
Browse files Browse the repository at this point in the history
  • Loading branch information
raksooo committed May 12, 2015
1 parent 08f8a3a commit a51803d
Showing 1 changed file with 21 additions and 51 deletions.
72 changes: 21 additions & 51 deletions contracts/WorkerDispatcher.sol
Original file line number Diff line number Diff line change
@@ -1,67 +1,23 @@
contract WorkAgreement {
address client;
address worker;
mapping (address => bool) testers;
uint public price;
uint public end;
// port for docker transfer
uint public dtport;
// port for hosting
uint public port;

function WorkAgreement(address _client, address _worker, uint _price,
uint length) {
client = _client;
worker = _worker;
price = _price;
end = length;
}

function addTester(address tester) {
testers[tester] = true;
}

function setWorkerDtPort(uint _dtport) {
if (msg.sender == worker) {
dtport = _dtport;
}
}

function setWorkerPort(uint _port) {
if (msg.sender == worker) {
port = _port;
}
}
}

contract WorkerDispatcher {
struct Worker {
bytes32 name;
bytes32 ip;
uint maxLength;
uint price;
address agreement;
bool activeAgreement;
uint dtport;
uint port;
}
mapping (address => Worker) public workersInfo;
uint public numWorkers;
mapping (uint => address) public workerList;

function buyContract(address worker, uint redundancy, uint length)
function buyContract(address worker, uint length)
returns (address addr) {
if (workersInfo[worker].name == "" &&
workersInfo[worker].maxLength < length) return msg.sender;
WorkAgreement wa = new WorkAgreement(msg.sender, worker,
workersInfo[worker].price,
length);
workersInfo[worker].agreement = wa;
// TODO - create better way to asign testers
/*
for (uint i = 1; i < 3; i++) {
uint n = uint(block.blockhash(block.number - i)) % numWorkers;
if (workerList[n] == worker) continue;
wa.addTester(workerList[n]);
}*/
return wa;
workersInfo[worker].activeAgreement = true;
return worker;
}

function registerWorker(uint maxLength, uint price,
Expand All @@ -74,11 +30,25 @@ contract WorkerDispatcher {
w.ip = ip;
w.maxLength = maxLength;
w.price = price;
w.agreement = 0;
w.activeAgreement = false;
w.dtport = 0;
w.port = 0;
}

function changeWorkerPrice(uint newPrice) {
workersInfo[msg.sender].price = newPrice;
}

function setWorkerDtPort(uint _dtport) {
if (workersInfo[msg.sender].activeAgreement) {
workersInfo[msg.sender].dtport = _dtport;
}
}

function setWorkerPort(uint _port) {
if (workersInfo[msg.sender].activeAgreement) {
workersInfo[msg.sender].port = _port;
}
}
}

0 comments on commit a51803d

Please sign in to comment.