Skip to content

Commit f5406f3

Browse files
authored
Merge pull request #2 from semperai/jorge
Updates added, job states and dashboard
2 parents c8def9f + c16e311 commit f5406f3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+6308
-23617
lines changed

contract/contracts/MarketplaceDataV1.sol

+163-47
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
77
import "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol";
88

99
struct JobEventData {
10-
uint8 type_; // 1 byte / type of object
11-
bytes address_; // empty or context dependent address data, either who sent it or whom it targets
12-
bytes data_; // extra event data, e.g. 34 bytes for CID
10+
uint8 type_; // 1 byte / type of object
11+
bytes address_; // empty or context dependent address data, either who sent it or whom it targets
12+
bytes data_; // extra event data, e.g. 34 bytes for CID
1313
uint32 timestamp_; // 4 bytes
1414
}
1515

@@ -74,10 +74,33 @@ struct Review {
7474
contract MarketplaceDataV1 is OwnableUpgradeable {
7575
event JobEvent(uint256 indexed jobId, JobEventData eventData);
7676
event PublicKeyRegistered(address indexed addr, bytes pubkey);
77-
event UserRegistered(address indexed addr, bytes pubkey, string name, string bio, string avatar);
78-
event UserUpdated(address indexed addr, string name, string bio, string avatar);
79-
event ArbitratorRegistered(address indexed addr, bytes pubkey, string name, string bio, string avatar, uint16 fee);
80-
event ArbitratorUpdated(address indexed addr, string name, string bio, string avatar);
77+
event UserRegistered(
78+
address indexed addr,
79+
bytes pubkey,
80+
string name,
81+
string bio,
82+
string avatar
83+
);
84+
event UserUpdated(
85+
address indexed addr,
86+
string name,
87+
string bio,
88+
string avatar
89+
);
90+
event ArbitratorRegistered(
91+
address indexed addr,
92+
bytes pubkey,
93+
string name,
94+
string bio,
95+
string avatar,
96+
uint16 fee
97+
);
98+
event ArbitratorUpdated(
99+
address indexed addr,
100+
string name,
101+
string bio,
102+
string avatar
103+
);
81104

82105
MarketplaceV1 public marketplace;
83106

@@ -115,9 +138,7 @@ contract MarketplaceDataV1 is OwnableUpgradeable {
115138
/// @notice Initialize contract
116139
/// @dev For upgradeable contracts this function necessary
117140
/// @param marketplace_ Address of marketplace
118-
function initialize(
119-
address marketplace_
120-
) public initializer {
141+
function initialize(address marketplace_) public initializer {
121142
__Ownable_init(msg.sender);
122143

123144
marketplace = MarketplaceV1(marketplace_);
@@ -132,7 +153,10 @@ contract MarketplaceDataV1 is OwnableUpgradeable {
132153
meceTags["NDO"] = "NON_DIGITAL_OTHERS";
133154
}
134155

135-
function publishJobEvent(uint256 jobId_, JobEventData memory event_) public onlyMarketplace {
156+
function publishJobEvent(
157+
uint256 jobId_,
158+
JobEventData memory event_
159+
) public onlyMarketplace {
136160
event_.timestamp_ = uint32(block.timestamp);
137161
jobEvents[jobId_].push(event_);
138162
emit JobEvent(jobId_, event_);
@@ -146,7 +170,10 @@ contract MarketplaceDataV1 is OwnableUpgradeable {
146170
return marketplace.jobsLength();
147171
}
148172

149-
function getJobs(uint256 index_, uint256 limit_) public view returns (JobPost[] memory) {
173+
function getJobs(
174+
uint256 index_,
175+
uint256 limit_
176+
) public view returns (JobPost[] memory) {
150177
uint256 jobsLength_ = marketplace.jobsLength();
151178
require(index_ < jobsLength_, "index out of bounds");
152179

@@ -168,7 +195,11 @@ contract MarketplaceDataV1 is OwnableUpgradeable {
168195
}
169196

170197
// Function to get past job events starting from a specific index
171-
function getEvents(uint256 jobId_, uint256 index_, uint256 limit_) public view returns (JobEventData[] memory) {
198+
function getEvents(
199+
uint256 jobId_,
200+
uint256 index_,
201+
uint256 limit_
202+
) public view returns (JobEventData[] memory) {
172203
uint256 eventsLength_ = jobEvents[jobId_].length;
173204
require(index_ < eventsLength_, "index out of bounds");
174205

@@ -185,19 +216,34 @@ contract MarketplaceDataV1 is OwnableUpgradeable {
185216
return result;
186217
}
187218

188-
function checkUserParams(string calldata name_, string calldata bio_, string calldata avatar_) internal {
189-
require(bytes(name_).length > 0 && bytes(name_).length < 20, "name too short or long");
219+
function checkUserParams(
220+
string calldata name_,
221+
string calldata bio_,
222+
string calldata avatar_
223+
) internal {
224+
require(
225+
bytes(name_).length > 0 && bytes(name_).length < 20,
226+
"name too short or long"
227+
);
190228
require(bytes(bio_).length < 255, "bio too long");
191229
require(bytes(avatar_).length < 150, "avatar too long");
192230
}
193231

194232
// allow users to register their *message encryption* public key
195233
// this is used to allow others to message you securely
196234
// we do not do verification here because we want to allow contracts to register
197-
function registerUser(bytes calldata pubkey_, string calldata name_, string calldata bio_, string calldata avatar_) public {
235+
function registerUser(
236+
bytes calldata pubkey_,
237+
string calldata name_,
238+
string calldata bio_,
239+
string calldata avatar_
240+
) public {
198241
// presently we do not allow to update the public keys otherwise the decryption of old messages will become impossible
199242
require(users[msg.sender].publicKey.length == 0, "already registered");
200-
require(pubkey_.length == 33, "invalid pubkey length, must be compressed, 33 bytes");
243+
require(
244+
pubkey_.length == 33,
245+
"invalid pubkey length, must be compressed, 33 bytes"
246+
);
201247
checkUserParams(name_, bio_, avatar_);
202248
users[msg.sender] = User(
203249
msg.sender,
@@ -214,7 +260,11 @@ contract MarketplaceDataV1 is OwnableUpgradeable {
214260
emit UserRegistered(msg.sender, pubkey_, name_, bio_, avatar_);
215261
}
216262

217-
function updateUser(string calldata name_, string calldata bio_, string calldata avatar_) public {
263+
function updateUser(
264+
string calldata name_,
265+
string calldata bio_,
266+
string calldata avatar_
267+
) public {
218268
require(users[msg.sender].publicKey.length > 0, "not registered");
219269
checkUserParams(name_, bio_, avatar_);
220270

@@ -229,19 +279,22 @@ contract MarketplaceDataV1 is OwnableUpgradeable {
229279
return users[address_].publicKey.length > 0;
230280
}
231281

232-
function userRefunded(address address_) public onlyMarketplace() {
282+
function userRefunded(address address_) public onlyMarketplace {
233283
users[address_].reputationDown += 1;
234284
}
235285

236-
function userDelivered(address address_) public onlyMarketplace() {
286+
function userDelivered(address address_) public onlyMarketplace {
237287
users[address_].reputationUp += 1;
238288
}
239289

240290
function usersLength() public view returns (uint256) {
241291
return userAddresses.length;
242292
}
243293

244-
function getUsers(uint256 index_, uint256 limit_) public view returns (User[] memory) {
294+
function getUsers(
295+
uint256 index_,
296+
uint256 limit_
297+
) public view returns (User[] memory) {
245298
uint256 usersLength_ = userAddresses.length;
246299
require(index_ < usersLength_, "index out of bounds");
247300

@@ -257,7 +310,9 @@ contract MarketplaceDataV1 is OwnableUpgradeable {
257310
return result;
258311
}
259312

260-
function publicKeys(address userAddress_) public view returns (bytes memory) {
313+
function publicKeys(
314+
address userAddress_
315+
) public view returns (bytes memory) {
261316
return users[userAddress_].publicKey;
262317
}
263318

@@ -266,10 +321,22 @@ contract MarketplaceDataV1 is OwnableUpgradeable {
266321
}
267322

268323
// registers an arbitrator with their *message encryption* public key, name and fee they charge
269-
function registerArbitrator(bytes calldata pubkey_, string calldata name_, string calldata bio_, string calldata avatar_, uint16 fee_) public {
324+
function registerArbitrator(
325+
bytes calldata pubkey_,
326+
string calldata name_,
327+
string calldata bio_,
328+
string calldata avatar_,
329+
uint16 fee_
330+
) public {
270331
// presently we do not allow to update the public keys otherwise the decryption of old messages will become impossible
271-
require(arbitrators[msg.sender].publicKey.length == 0, "already registered");
272-
require(pubkey_.length == 33, "invalid pubkey length, must be compressed, 33 bytes");
332+
require(
333+
arbitrators[msg.sender].publicKey.length == 0,
334+
"already registered"
335+
);
336+
require(
337+
pubkey_.length == 33,
338+
"invalid pubkey length, must be compressed, 33 bytes"
339+
);
273340
checkUserParams(name_, bio_, avatar_);
274341
arbitrators[msg.sender] = JobArbitrator(
275342
msg.sender,
@@ -284,10 +351,21 @@ contract MarketplaceDataV1 is OwnableUpgradeable {
284351

285352
arbitratorAddresses.push(msg.sender);
286353

287-
emit ArbitratorRegistered(msg.sender, pubkey_, name_, bio_, avatar_, fee_);
354+
emit ArbitratorRegistered(
355+
msg.sender,
356+
pubkey_,
357+
name_,
358+
bio_,
359+
avatar_,
360+
fee_
361+
);
288362
}
289363

290-
function updateArbitrator(string calldata name_, string calldata bio_, string calldata avatar_) public {
364+
function updateArbitrator(
365+
string calldata name_,
366+
string calldata bio_,
367+
string calldata avatar_
368+
) public {
291369
require(arbitrators[msg.sender].publicKey.length > 0, "not registered");
292370
checkUserParams(name_, bio_, avatar_);
293371

@@ -298,11 +376,11 @@ contract MarketplaceDataV1 is OwnableUpgradeable {
298376
emit ArbitratorUpdated(msg.sender, name_, bio_, avatar_);
299377
}
300378

301-
function arbitratorRefused(address address_) public onlyMarketplace() {
379+
function arbitratorRefused(address address_) public onlyMarketplace {
302380
arbitrators[address_].refusedCount += 1;
303381
}
304382

305-
function arbitratorSettled(address address_) public onlyMarketplace() {
383+
function arbitratorSettled(address address_) public onlyMarketplace {
306384
arbitrators[address_].settledCount += 1;
307385
}
308386

@@ -318,7 +396,10 @@ contract MarketplaceDataV1 is OwnableUpgradeable {
318396
return arbitratorAddresses.length;
319397
}
320398

321-
function getArbitrators(uint256 index_, uint256 limit_) public view returns (JobArbitrator[] memory) {
399+
function getArbitrators(
400+
uint256 index_,
401+
uint256 limit_
402+
) public view returns (JobArbitrator[] memory) {
322403
uint256 arbitratorsLength_ = arbitratorAddresses.length;
323404
require(index_ < arbitratorsLength_, "index out of bounds");
324405

@@ -334,49 +415,84 @@ contract MarketplaceDataV1 is OwnableUpgradeable {
334415
return result;
335416
}
336417

337-
function getArbitrator(address arbitratorAddress_) public view returns (JobArbitrator memory) {
418+
function getArbitrator(
419+
address arbitratorAddress_
420+
) public view returns (JobArbitrator memory) {
338421
return arbitrators[arbitratorAddress_];
339422
}
340423

341-
function updateUserRating(address userAddress_, uint8 reviewRating_) public onlyMarketplace() {
424+
function updateUserRating(
425+
address userAddress_,
426+
uint8 reviewRating_
427+
) public onlyMarketplace {
342428
UserRating storage rating = userRatings[userAddress_];
343429

344-
rating.averageRating = uint16((rating.averageRating * rating.numberOfReviews + reviewRating_ * 10000) / (rating.numberOfReviews + 1));
430+
rating.averageRating = uint16(
431+
(rating.averageRating *
432+
rating.numberOfReviews +
433+
reviewRating_ *
434+
10000) / (rating.numberOfReviews + 1)
435+
);
345436
rating.numberOfReviews++;
346437
}
347438

348-
function getUserRating(address userAddress_) public view returns (UserRating memory) {
439+
function getUserRating(
440+
address userAddress_
441+
) public view returns (UserRating memory) {
349442
return userRatings[userAddress_];
350443
}
351444

352445
// Function to read MECE tag's long form given the short form
353-
function readMeceTag(string memory shortForm) public view returns (string memory) {
446+
function readMeceTag(
447+
string memory shortForm
448+
) public view returns (string memory) {
354449
require(bytes(meceTags[shortForm]).length != 0, "Invalid MECE tag");
355450
return meceTags[shortForm];
356451
}
357452

358453
// Governance function to add or update MECE tags
359-
function updateMeceTag(string memory shortForm, string memory longForm) public onlyOwner {
360-
require(bytes(shortForm).length > 0 && bytes(longForm).length > 0, "Invalid tag data");
454+
function updateMeceTag(
455+
string memory shortForm,
456+
string memory longForm
457+
) public onlyOwner {
458+
require(
459+
bytes(shortForm).length > 0 && bytes(longForm).length > 0,
460+
"Invalid tag data"
461+
);
361462
meceTags[shortForm] = longForm;
362463
}
363464

364465
function removeMeceTag(string memory shortForm) public onlyOwner {
365-
require(bytes(meceTags[shortForm]).length != 0, "MECE tag does not exist");
466+
require(
467+
bytes(meceTags[shortForm]).length != 0,
468+
"MECE tag does not exist"
469+
);
366470
delete meceTags[shortForm];
367471
}
368472

369-
function addReview(address target_, address reviewer_, uint256 jobId_, uint8 rating_, string memory text_) public onlyMarketplace {
370-
userReviews[target_].push(Review({
371-
reviewer: reviewer_,
372-
jobId: jobId_,
373-
rating: rating_,
374-
text: text_,
375-
timestamp: uint32(block.timestamp)
376-
}));
473+
function addReview(
474+
address target_,
475+
address reviewer_,
476+
uint256 jobId_,
477+
uint8 rating_,
478+
string memory text_
479+
) public onlyMarketplace {
480+
userReviews[target_].push(
481+
Review({
482+
reviewer: reviewer_,
483+
jobId: jobId_,
484+
rating: rating_,
485+
text: text_,
486+
timestamp: uint32(block.timestamp)
487+
})
488+
);
377489
}
378490

379-
function getReviews(address target_, uint256 index_, uint256 limit_) public view returns (Review[] memory) {
491+
function getReviews(
492+
address target_,
493+
uint256 index_,
494+
uint256 limit_
495+
) public view returns (Review[] memory) {
380496
uint256 reviewsLength_ = userReviews[target_].length;
381497
require(index_ < reviewsLength_, "index out of bounds");
382498

0 commit comments

Comments
 (0)