Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
madvas committed Jan 28, 2017
1 parent 043eede commit 26b3991
Show file tree
Hide file tree
Showing 28 changed files with 1,257 additions and 1,304 deletions.
25 changes: 3 additions & 22 deletions README.md
@@ -1,26 +1,7 @@
# ethlance

A [re-frame](https://github.com/Day8/re-frame) application designed to ... well, that part is up to you.
Repository for [ethlance.com](http://ethlance.com)

## Development Mode
Ethlance is first job market platform working completely on Ethereum blockchain with 0% service fees

### Run application:

```
lein clean
lein figwheel dev
```

Figwheel will automatically push cljs changes to the browser.

Wait a bit, then browse to [http://localhost:3449](http://localhost:3449).

## Production Build


To compile clojurescript to javascript:

```
lein clean
lein cljsbuild once min
```
Ethereum Smart Contracts are at `/resources/public/contracts/src`
5 changes: 0 additions & 5 deletions resources/public/contracts/src/categoryLibrary.sol
Expand Up @@ -6,11 +6,6 @@ import "sharedLibrary.sol";

library CategoryLibrary {

function addCategory(address db, bytes32 name) internal {
var idx = SharedLibrary.createNext(db, "category/count");
EthlanceDB(db).setBytes32Value(sha3("category/name", idx), name);
}

function addJob(address db, uint categoryId, uint jobId) internal {
SharedLibrary.addArrayItem(db, categoryId, "category/jobs", "category/jobs-count", jobId);
}
Expand Down
37 changes: 20 additions & 17 deletions resources/public/contracts/src/contractLibrary.sol
Expand Up @@ -25,8 +25,8 @@ library ContractLibrary {
if (employerId == freelancerId) throw;
if (getContract(db, freelancerId, jobId) != 0) throw;
if (JobLibrary.getStatus(db, jobId) != 1) throw;
if (!UserLibrary.isFreelancerAvailable(db, freelancerId))
throw;
if (!UserLibrary.isFreelancerAvailable(db, freelancerId)) throw;
if (!UserLibrary.hasStatus(db, freelancerId, 1)) throw;
var contractId = SharedLibrary.createNext(db, "contract/count");
setFreelancerJobIndex(db, contractId, freelancerId, jobId);

Expand All @@ -50,7 +50,6 @@ library ContractLibrary {
var employerId = JobLibrary.getEmployer(db, jobId);
if (employerId == 0) throw;
if (freelancerId == employerId) throw;
if (freelancerId == 0) throw;
if (JobLibrary.getStatus(db, jobId) != 1) throw;
contractId = getContract(db, freelancerId, jobId);
if (contractId == 0) {
Expand Down Expand Up @@ -112,34 +111,38 @@ library ContractLibrary {
if (senderId == freelancerId) {
if (getFreelancerFeedbackOn(db, contractId) != 0) throw;
EthlanceDB(db).setBooleanValue(sha3("contract/done-by-freelancer?", contractId), true);
addFreelancerFeedback(db, contractId, feedback, rating);
addFreelancerFeedback(db, contractId, employerId, feedback, rating);
} else {
if (getEmployerFeedbackOn(db, contractId) != 0) throw;
addEmployerFeedback(db, contractId, feedback, rating);
addEmployerFeedback(db, contractId, freelancerId, feedback, rating);
}
}

function addUserFeedback(address db, uint contractId, uint userId, string feedbackKey,
function addUserFeedback(address db, uint contractId, uint receiverId, string feedbackKey,
string ratingKey, string dateKey, string ratingsCountKey, string avgRatingKey, string description,
uint8 rating) internal {
EthlanceDB(db).setStringValue(sha3(feedbackKey, contractId), description);
EthlanceDB(db).setUInt8Value(sha3(ratingKey, contractId), rating);
EthlanceDB(db).setUIntValue(sha3(dateKey, contractId), now);
UserLibrary.addToAvgRating(db, userId, ratingsCountKey, avgRatingKey, rating);
UserLibrary.addToAvgRating(db, receiverId, ratingsCountKey, avgRatingKey, rating);
}

function addFreelancerFeedback(address db, uint contractId, string description, uint8 rating) internal {
var userId = getFreelancer(db, contractId);
addUserFeedback(db, contractId, userId, "contract/freelancer-feedback",
"contract/freelancer-feedback-rating", "contract/freelancer-feedback-on", "freelancer/ratings-count",
"freelancer/avg-rating", description, rating);
function addFreelancerFeedback(address db, uint contractId, uint receiverId, string description, uint8 rating
)
internal
{
addUserFeedback(db, contractId, receiverId, "contract/freelancer-feedback",
"contract/freelancer-feedback-rating", "contract/freelancer-feedback-on", "employer/ratings-count",
"employer/avg-rating", description, rating);
}

function addEmployerFeedback(address db, uint contractId, string description, uint8 rating) internal {
var userId = getEmployer(db, contractId);
addUserFeedback(db, contractId, userId, "contract/employer-feedback",
"contract/employer-feedback-rating", "contract/employer-feedback-on", "employer/ratings-count",
"employer/avg-rating", description, rating);
function addEmployerFeedback(address db, uint contractId, uint receiverId, string description, uint8 rating
)
internal
{
addUserFeedback(db, contractId, receiverId, "contract/employer-feedback",
"contract/employer-feedback-rating", "contract/employer-feedback-on", "freelancer/ratings-count",
"freelancer/avg-rating", description, rating);
}

function addTotalInvoiced(address db, uint contractId, uint amount) internal {
Expand Down
62 changes: 0 additions & 62 deletions resources/public/contracts/src/ethlanceDB.sol
Expand Up @@ -210,68 +210,6 @@ contract EthlanceDB is Ownable {
delete IntStorage[record];
}

function getTypesCounts(uint8[] types) constant returns(uint[]) {
var counts = new uint[](7);
for (uint i = 0; i < types.length ; i++) {
counts[types[i] - 1]++;
}
return counts;
}

function getEntity(bytes32[] records, uint8[] types)
public constant returns
(
bool[] bools,
uint8[] uint8s,
uint[] uints,
address[] addresses,
bytes32[] bytes32s,
int[] ints,
string str
)
{
var counts = getTypesCounts(types);
bools = new bool[](counts[0]);
uint8s = new uint8[](counts[1]);
uints = new uint[](counts[2]);
addresses = new address[](counts[3]);
bytes32s = new bytes32[](counts[4]);
ints = new int[](counts[5]);
counts = new uint[](7);

for (uint i = 0; i < records.length; i++) {
var recordType = types[i];
var record = records[i];
if (recordType == 1) {
bools[counts[0]] = getBooleanValue(record);
counts[0]++;
} else if (recordType == 2) {
uint8s[counts[1]] = getUInt8Value(record);
counts[1]++;
} else if (recordType == 3) {
uints[counts[2]] = getUIntValue(record);
counts[2]++;

} else if (recordType == 4) {
addresses[counts[3]] = getAddressValue(record);
counts[3]++;

} else if (recordType == 5) {
bytes32s[counts[4]] = getBytes32Value(record);
counts[4]++;

} else if (recordType == 6) {
ints[counts[5]] = getIntValue(record);
counts[5]++;

} else if (recordType == 7) {
str = str.toSlice().concat(getStringValue(record).toSlice());
str = str.toSlice().concat("99--DELIMITER--11".toSlice());
}
}
return (bools, uint8s, uints, addresses, bytes32s, ints, str);
}

function booleanToUInt(bool x) constant returns (uint) {
if (x) {
return 1;
Expand Down
8 changes: 4 additions & 4 deletions resources/public/contracts/src/ethlanceUser.sol
Expand Up @@ -60,7 +60,6 @@ contract EthlanceUser is EthlanceSetter {
skills, description);
}


function registerEmployer(string name, bytes32 gravatar, uint country, uint state, uint[] languages,
string description
)
Expand All @@ -70,9 +69,10 @@ contract EthlanceUser is EthlanceSetter {
setEmployer(description);
}

function setEmployer(string description)
onlyActiveSmartContract
onlyActiveUser
function setEmployer(string description
)
onlyActiveSmartContract
onlyActiveUser
{
if (description.toSlice().len() > getConfig("max-user-description")) throw;
UserLibrary.setEmployer(ethlanceDB, getSenderUserId(), description);
Expand Down
1 change: 1 addition & 0 deletions resources/public/contracts/src/invoiceLibrary.sol
Expand Up @@ -68,6 +68,7 @@ library InvoiceLibrary {
if (getStatus(db, invoiceId) != 1) throw;
if (employerId != senderId) throw;
if (amount != sentAmount) throw;
if (!UserLibrary.hasStatus(db, freelancerId, 1)) throw;

EthlanceDB(db).setUInt8Value(sha3("invoice/status", invoiceId), 2);
EthlanceDB(db).setUIntValue(sha3("invoice/paid-on", invoiceId), now);
Expand Down
17 changes: 4 additions & 13 deletions resources/public/contracts/src/userLibrary.sol
Expand Up @@ -51,17 +51,16 @@ library UserLibrary {
userId = existingUserId;
} else {
userId = SharedLibrary.createNext(db, "user/count");
EthlanceDB(db).setUIntValue(sha3("user/created-on", userId), now);
EthlanceDB(db).setUIntValue(sha3("user/ids", userAddress), userId);
EthlanceDB(db).setAddressValue(sha3("user/address", userId), userAddress);
EthlanceDB(db).setUInt8Value(sha3("user/status", userId), 1);
}
EthlanceDB(db).setAddressValue(sha3("user/address", userId), userAddress);
EthlanceDB(db).setStringValue(sha3("user/name", userId), name);
EthlanceDB(db).setBytes32Value(sha3("user/gravatar", userId), gravatar);

if (country == 0) throw;
EthlanceDB(db).setUIntValue(sha3("user/country", userId), country);
EthlanceDB(db).setUIntValue(sha3("user/state", userId), state);
EthlanceDB(db).setUInt8Value(sha3("user/status", userId), 1);
EthlanceDB(db).setUIntValue(sha3("user/created-on", userId), now);
EthlanceDB(db).setUIntValue(sha3("user/ids", userAddress), userId);
setUserLanguages(db, userId, languages);
return userId;
}
Expand Down Expand Up @@ -111,14 +110,6 @@ library UserLibrary {
SkillLibrary.addFreelancer(db, added, userId);
SkillLibrary.removeFreelancer(db, removed, userId);

if (currentSkills.length == 3 && removed.length == 3 && skills.length == 6 && added.length != 6 &&
(currentSkills[0] == 10 || currentSkills[0] == 11 || currentSkills[0] == 12) &&
(currentSkills[1] == 10 || currentSkills[1] == 11 || currentSkills[1] == 12) &&
(currentSkills[2] == 10 || currentSkills[2] == 11 || currentSkills[2] == 12)
) {
throw;
}

if (added.length > 0 || removed.length > 0) {
SharedLibrary.setUIntArray(db, userId, "freelancer/skills", "freelancer/skills-count", skills);
}
Expand Down
2 changes: 1 addition & 1 deletion resources/public/css/ethlance.css

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions resources/public/css/ethlance.main.css.map

Large diffs are not rendered by default.

0 comments on commit 26b3991

Please sign in to comment.