@@ -7,9 +7,9 @@ import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
7
7
import "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol " ;
8
8
9
9
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
13
13
uint32 timestamp_; // 4 bytes
14
14
}
15
15
@@ -74,10 +74,33 @@ struct Review {
74
74
contract MarketplaceDataV1 is OwnableUpgradeable {
75
75
event JobEvent (uint256 indexed jobId , JobEventData eventData );
76
76
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
+ );
81
104
82
105
MarketplaceV1 public marketplace;
83
106
@@ -115,9 +138,7 @@ contract MarketplaceDataV1 is OwnableUpgradeable {
115
138
/// @notice Initialize contract
116
139
/// @dev For upgradeable contracts this function necessary
117
140
/// @param marketplace_ Address of marketplace
118
- function initialize (
119
- address marketplace_
120
- ) public initializer {
141
+ function initialize (address marketplace_ ) public initializer {
121
142
__Ownable_init (msg .sender );
122
143
123
144
marketplace = MarketplaceV1 (marketplace_);
@@ -132,7 +153,10 @@ contract MarketplaceDataV1 is OwnableUpgradeable {
132
153
meceTags["NDO " ] = "NON_DIGITAL_OTHERS " ;
133
154
}
134
155
135
- function publishJobEvent (uint256 jobId_ , JobEventData memory event_ ) public onlyMarketplace {
156
+ function publishJobEvent (
157
+ uint256 jobId_ ,
158
+ JobEventData memory event_
159
+ ) public onlyMarketplace {
136
160
event_.timestamp_ = uint32 (block .timestamp );
137
161
jobEvents[jobId_].push (event_);
138
162
emit JobEvent (jobId_, event_);
@@ -146,7 +170,10 @@ contract MarketplaceDataV1 is OwnableUpgradeable {
146
170
return marketplace.jobsLength ();
147
171
}
148
172
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 ) {
150
177
uint256 jobsLength_ = marketplace.jobsLength ();
151
178
require (index_ < jobsLength_, "index out of bounds " );
152
179
@@ -168,7 +195,11 @@ contract MarketplaceDataV1 is OwnableUpgradeable {
168
195
}
169
196
170
197
// 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 ) {
172
203
uint256 eventsLength_ = jobEvents[jobId_].length ;
173
204
require (index_ < eventsLength_, "index out of bounds " );
174
205
@@ -185,19 +216,34 @@ contract MarketplaceDataV1 is OwnableUpgradeable {
185
216
return result;
186
217
}
187
218
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
+ );
190
228
require (bytes (bio_).length < 255 , "bio too long " );
191
229
require (bytes (avatar_).length < 150 , "avatar too long " );
192
230
}
193
231
194
232
// allow users to register their *message encryption* public key
195
233
// this is used to allow others to message you securely
196
234
// 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 {
198
241
// presently we do not allow to update the public keys otherwise the decryption of old messages will become impossible
199
242
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
+ );
201
247
checkUserParams (name_, bio_, avatar_);
202
248
users[msg .sender ] = User (
203
249
msg .sender ,
@@ -214,7 +260,11 @@ contract MarketplaceDataV1 is OwnableUpgradeable {
214
260
emit UserRegistered (msg .sender , pubkey_, name_, bio_, avatar_);
215
261
}
216
262
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 {
218
268
require (users[msg .sender ].publicKey.length > 0 , "not registered " );
219
269
checkUserParams (name_, bio_, avatar_);
220
270
@@ -229,19 +279,22 @@ contract MarketplaceDataV1 is OwnableUpgradeable {
229
279
return users[address_].publicKey.length > 0 ;
230
280
}
231
281
232
- function userRefunded (address address_ ) public onlyMarketplace () {
282
+ function userRefunded (address address_ ) public onlyMarketplace {
233
283
users[address_].reputationDown += 1 ;
234
284
}
235
285
236
- function userDelivered (address address_ ) public onlyMarketplace () {
286
+ function userDelivered (address address_ ) public onlyMarketplace {
237
287
users[address_].reputationUp += 1 ;
238
288
}
239
289
240
290
function usersLength () public view returns (uint256 ) {
241
291
return userAddresses.length ;
242
292
}
243
293
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 ) {
245
298
uint256 usersLength_ = userAddresses.length ;
246
299
require (index_ < usersLength_, "index out of bounds " );
247
300
@@ -257,7 +310,9 @@ contract MarketplaceDataV1 is OwnableUpgradeable {
257
310
return result;
258
311
}
259
312
260
- function publicKeys (address userAddress_ ) public view returns (bytes memory ) {
313
+ function publicKeys (
314
+ address userAddress_
315
+ ) public view returns (bytes memory ) {
261
316
return users[userAddress_].publicKey;
262
317
}
263
318
@@ -266,10 +321,22 @@ contract MarketplaceDataV1 is OwnableUpgradeable {
266
321
}
267
322
268
323
// 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 {
270
331
// 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
+ );
273
340
checkUserParams (name_, bio_, avatar_);
274
341
arbitrators[msg .sender ] = JobArbitrator (
275
342
msg .sender ,
@@ -284,10 +351,21 @@ contract MarketplaceDataV1 is OwnableUpgradeable {
284
351
285
352
arbitratorAddresses.push (msg .sender );
286
353
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
+ );
288
362
}
289
363
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 {
291
369
require (arbitrators[msg .sender ].publicKey.length > 0 , "not registered " );
292
370
checkUserParams (name_, bio_, avatar_);
293
371
@@ -298,11 +376,11 @@ contract MarketplaceDataV1 is OwnableUpgradeable {
298
376
emit ArbitratorUpdated (msg .sender , name_, bio_, avatar_);
299
377
}
300
378
301
- function arbitratorRefused (address address_ ) public onlyMarketplace () {
379
+ function arbitratorRefused (address address_ ) public onlyMarketplace {
302
380
arbitrators[address_].refusedCount += 1 ;
303
381
}
304
382
305
- function arbitratorSettled (address address_ ) public onlyMarketplace () {
383
+ function arbitratorSettled (address address_ ) public onlyMarketplace {
306
384
arbitrators[address_].settledCount += 1 ;
307
385
}
308
386
@@ -318,7 +396,10 @@ contract MarketplaceDataV1 is OwnableUpgradeable {
318
396
return arbitratorAddresses.length ;
319
397
}
320
398
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 ) {
322
403
uint256 arbitratorsLength_ = arbitratorAddresses.length ;
323
404
require (index_ < arbitratorsLength_, "index out of bounds " );
324
405
@@ -334,49 +415,84 @@ contract MarketplaceDataV1 is OwnableUpgradeable {
334
415
return result;
335
416
}
336
417
337
- function getArbitrator (address arbitratorAddress_ ) public view returns (JobArbitrator memory ) {
418
+ function getArbitrator (
419
+ address arbitratorAddress_
420
+ ) public view returns (JobArbitrator memory ) {
338
421
return arbitrators[arbitratorAddress_];
339
422
}
340
423
341
- function updateUserRating (address userAddress_ , uint8 reviewRating_ ) public onlyMarketplace () {
424
+ function updateUserRating (
425
+ address userAddress_ ,
426
+ uint8 reviewRating_
427
+ ) public onlyMarketplace {
342
428
UserRating storage rating = userRatings[userAddress_];
343
429
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
+ );
345
436
rating.numberOfReviews++ ;
346
437
}
347
438
348
- function getUserRating (address userAddress_ ) public view returns (UserRating memory ) {
439
+ function getUserRating (
440
+ address userAddress_
441
+ ) public view returns (UserRating memory ) {
349
442
return userRatings[userAddress_];
350
443
}
351
444
352
445
// 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 ) {
354
449
require (bytes (meceTags[shortForm]).length != 0 , "Invalid MECE tag " );
355
450
return meceTags[shortForm];
356
451
}
357
452
358
453
// 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
+ );
361
462
meceTags[shortForm] = longForm;
362
463
}
363
464
364
465
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
+ );
366
470
delete meceTags[shortForm];
367
471
}
368
472
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
+ );
377
489
}
378
490
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 ) {
380
496
uint256 reviewsLength_ = userReviews[target_].length ;
381
497
require (index_ < reviewsLength_, "index out of bounds " );
382
498
0 commit comments