214 | | - | |
---|
215 | | - | |
---|
216 | | - | @Callable(i) |
---|
217 | | - | func createAuction (jobExecutionDays,auctionDurationDays,auctionInfo) = { |
---|
218 | | - | let auctionId = toBase58String(i.transactionId) |
---|
219 | | - | let auctionClient = toBase58String(i.callerPublicKey) |
---|
220 | | - | let pmt = extract(i.payment) |
---|
221 | | - | let pmtAmount = pmt.amount |
---|
222 | | - | let auctionPrice = createAuctionPriceCheck(pmtAmount) |
---|
223 | | - | let auctionStart = height |
---|
224 | | - | let auctionDurationBlocks = (auctionDurationDays * day) |
---|
225 | | - | let blocksForExecution = (jobExecutionDays * day) |
---|
226 | | - | let pmtAssetName = if (!(isDefined(pmt.assetId))) |
---|
227 | | - | then "WAVES" |
---|
228 | | - | else if ((pmt.assetId == wBTC)) |
---|
229 | | - | then "BTC" |
---|
230 | | - | else if ((pmt.assetId == wEUR)) |
---|
231 | | - | then "EUR" |
---|
232 | | - | else if ((pmt.assetId == wUSD)) |
---|
233 | | - | then "USD" |
---|
234 | | - | else throw("AssetId is incorrect") |
---|
235 | | - | let newFreezedBalance = increaseFreezedBalance(pmtAssetName, auctionPrice) |
---|
236 | | - | WriteSet([DataEntry((auctionId + "_State"), stateOpen), DataEntry((auctionId + "_Info"), auctionInfo), DataEntry((auctionId + "_AuctionClient"), auctionClient), DataEntry((auctionId + "_AuctionStart"), auctionStart), DataEntry((auctionId + "_AuctionDuration"), auctionDurationBlocks), DataEntry((auctionId + "_JobPerformance"), blocksForExecution), DataEntry((auctionId + "_AssetName"), pmtAssetName), DataEntry((auctionId + "_Price"), auctionPrice), DataEntry((pmtAssetName + "_Freezed"), newFreezedBalance)]) |
---|
237 | | - | } |
---|
238 | | - | |
---|
239 | | - | |
---|
240 | | - | |
---|
241 | | - | @Callable(i) |
---|
242 | | - | func makeBid (auctionId,betPrice) = { |
---|
243 | | - | let callerPub = toBase58String(i.callerPublicKey) |
---|
244 | | - | let betTime = height |
---|
245 | | - | let auctionState = getAuctionState(auctionId) |
---|
246 | | - | let auctionClient = getAuctionClientPub(auctionId) |
---|
247 | | - | let auctionStart = getAuctionStartTime(auctionId) |
---|
248 | | - | let auctionDuration = getAuctionDurationTime(auctionId) |
---|
249 | | - | let auctionBlocksForExecution = getAuctionJobPerformanceTime(auctionId) |
---|
250 | | - | let auctionAssetName = getAuctionAssetName(auctionId) |
---|
251 | | - | let auctionPrice = getAuctionPrice(auctionId) |
---|
252 | | - | let auctionAssetId58 = AssetNameToBase58(auctionAssetName) |
---|
253 | | - | let newFreelancer = freelancerIsRegistered(callerPub) |
---|
254 | | - | let dAppCommission = ((auctionPrice * 3) / 100) |
---|
255 | | - | let newFreezedBalance = decreaseFreezedBalance(auctionAssetName, auctionPrice) |
---|
256 | | - | let auctionTimeisOver = timeCheck(betTime, auctionStart, auctionDuration) |
---|
257 | | - | if (auctionTimeisOver) |
---|
258 | | - | then if ((auctionState == stateOpen)) |
---|
259 | | - | then ScriptResult(WriteSet([DataEntry((auctionId + "_State"), stateCancel), DataEntry((auctionAssetName + "_Freezed"), newFreezedBalance)]), TransferSet([ScriptTransfer(addressFromPublicKey(auctionClient), (auctionPrice - dAppCommission), auctionAssetId58)])) |
---|
260 | | - | else if ((auctionState == stateSuggested)) |
---|
261 | | - | then { |
---|
262 | | - | let auctionLowestBidder = { |
---|
263 | | - | let valueLowestBidder = getString(this, (auctionId + "_LowestBidderPub")) |
---|
264 | | - | match valueLowestBidder { |
---|
265 | | - | case a: String => |
---|
266 | | - | a |
---|
267 | | - | case _ => |
---|
268 | | - | throw("Auction lowest bidder was not found") |
---|
269 | | - | } |
---|
270 | | - | } |
---|
271 | | - | let newAuctionPrice = { |
---|
272 | | - | let valueNewAuctionPrice = getInteger(this, ((auctionId + "_Bid_") + auctionLowestBidder)) |
---|
273 | | - | match valueNewAuctionPrice { |
---|
274 | | - | case a: Int => |
---|
275 | | - | a |
---|
276 | | - | case _ => |
---|
277 | | - | throw("Auction lowest bid was not found") |
---|
278 | | - | } |
---|
279 | | - | } |
---|
280 | | - | let amountDifference = ((auctionPrice - newAuctionPrice) - dAppCommission) |
---|
281 | | - | ScriptResult(WriteSet([DataEntry((auctionId + "_State"), stateInProgress), DataEntry((auctionId + "_HiredFreelancer"), auctionLowestBidder), DataEntry((auctionId + "_Price"), newAuctionPrice)]), TransferSet([ScriptTransfer(addressFromPublicKey(auctionClient), amountDifference, auctionAssetId58)])) |
---|
282 | | - | } |
---|
283 | | - | else throw("Incorrect auction state") |
---|
284 | | - | else if ((auctionState == stateOpen)) |
---|
285 | | - | then WriteSet([DataEntry(((auctionId + "_Bid_") + newFreelancer), betPrice), DataEntry((auctionId + "_State"), stateSuggested), DataEntry((auctionId + "_LowestBidderPub"), callerPub)]) |
---|
286 | | - | else if ((auctionState == stateSuggested)) |
---|
287 | | - | then { |
---|
288 | | - | let currentLowestBidderPub = { |
---|
289 | | - | let lowestBidder = getString(this, (auctionId + "_LowestBidderPub")) |
---|
290 | | - | match lowestBidder { |
---|
291 | | - | case a: String => |
---|
292 | | - | a |
---|
293 | | - | case _ => |
---|
294 | | - | throw("Auction lowest bidder was not found") |
---|
295 | | - | } |
---|
296 | | - | } |
---|
297 | | - | let newLowestBidderPub = { |
---|
298 | | - | let valueCurrentLowestBid = getInteger(this, ((auctionId + "_Bid_") + currentLowestBidderPub)) |
---|
299 | | - | let currentLowestBid = match valueCurrentLowestBid { |
---|
300 | | - | case a: Int => |
---|
301 | | - | a |
---|
302 | | - | case _ => |
---|
303 | | - | throw("Auction lowest bid was not found") |
---|
304 | | - | } |
---|
305 | | - | if ((currentLowestBid > betPrice)) |
---|
306 | | - | then newFreelancer |
---|
307 | | - | else currentLowestBidderPub |
---|
308 | | - | } |
---|
309 | | - | WriteSet([DataEntry((auctionId + "_LowestBidderPub"), newLowestBidderPub), DataEntry(((auctionId + "_Bid_") + newFreelancer), betPrice)]) |
---|
310 | | - | } |
---|
311 | | - | else throw(((((("Incorrect jobId state. Now: " + auctionState) + ", must be: ") + stateOpen) + " or ") + stateSuggested)) |
---|
312 | | - | } |
---|
313 | | - | |
---|
314 | | - | |
---|
315 | | - | |
---|
316 | | - | @Callable(i) |
---|
317 | | - | func chooseFreelancer (auctionId,freelancerPub) = { |
---|
318 | | - | let callerPub = extract(i.callerPublicKey) |
---|
319 | | - | let betTime = height |
---|
320 | | - | let auctionState = getAuctionState(auctionId) |
---|
321 | | - | let auctionClient = getAuctionClientPub(auctionId) |
---|
322 | | - | let auctionStart = getAuctionStartTime(auctionId) |
---|
323 | | - | let auctionDuration = getAuctionDurationTime(auctionId) |
---|
324 | | - | let auctionAssetName = getAuctionAssetName(auctionId) |
---|
325 | | - | let auctionPrice = getAuctionPrice(auctionId) |
---|
326 | | - | let auctionAssetId58 = AssetNameToBase58(auctionAssetName) |
---|
327 | | - | let freelancerBidAmount = { |
---|
328 | | - | let keyFreelancerBid = ((auctionId + "_Bid_") + freelancerPub) |
---|
329 | | - | let valueFreelacerBid = getInteger(this, keyFreelancerBid) |
---|
330 | | - | match valueFreelacerBid { |
---|
331 | | - | case a: Int => |
---|
332 | | - | a |
---|
333 | | - | case _ => |
---|
334 | | - | throw("Freelancer's bet was not found") |
---|
335 | | - | } |
---|
336 | | - | } |
---|
337 | | - | let dAppCommission = ((freelancerBidAmount * 3) / 100) |
---|
338 | | - | let auctionTimeisOver = timeCheck(betTime, auctionStart, auctionDuration) |
---|
339 | | - | if ((callerPub == auctionClient)) |
---|
340 | | - | then if (auctionTimeisOver) |
---|
341 | | - | then if ((auctionState == stateOpen)) |
---|
342 | | - | then { |
---|
343 | | - | let newFreezedBalance = decreaseFreezedBalance(auctionAssetName, auctionPrice) |
---|
344 | | - | ScriptResult(WriteSet([DataEntry((auctionId + "_State"), stateCancel), DataEntry((auctionAssetName + "_Freezed"), newFreezedBalance)]), TransferSet([ScriptTransfer(addressFromPublicKey(auctionClient), (auctionPrice - dAppCommission), auctionAssetId58)])) |
---|
345 | | - | } |
---|
346 | | - | else if ((auctionState == stateSuggested)) |
---|
347 | | - | then { |
---|
348 | | - | let auctionLowestBidder = { |
---|
349 | | - | let valueLowestBidder = getString(this, (auctionId + "_LowestBidderPub")) |
---|
350 | | - | match valueLowestBidder { |
---|
351 | | - | case a: String => |
---|
352 | | - | a |
---|
353 | | - | case _ => |
---|
354 | | - | throw("Auction lowest bidder was not found") |
---|
355 | | - | } |
---|
356 | | - | } |
---|
357 | | - | let newAuctionPrice = { |
---|
358 | | - | let valueNewAuctionPrice = getInteger(this, ((auctionId + "_Bid_") + auctionLowestBidder)) |
---|
359 | | - | match valueNewAuctionPrice { |
---|
360 | | - | case a: Int => |
---|
361 | | - | a |
---|
362 | | - | case _ => |
---|
363 | | - | throw("Auction lowest bid was not found") |
---|
364 | | - | } |
---|
365 | | - | } |
---|
366 | | - | let amountDifference = (auctionPrice - newAuctionPrice) |
---|
367 | | - | let newFreezedBalance = decreaseFreezedBalance(auctionAssetName, amountDifference) |
---|
368 | | - | ScriptResult(WriteSet([DataEntry((auctionId + "_State"), stateInProgress), DataEntry((auctionId + "_HiredFreelancer"), auctionLowestBidder), DataEntry((auctionId + "_Price"), newAuctionPrice), DataEntry((auctionAssetName + "_Freezed"), newFreezedBalance)]), TransferSet([ScriptTransfer(addressFromPublicKey(auctionClient), amountDifference, auctionAssetId58)])) |
---|
369 | | - | } |
---|
370 | | - | else throw("Incorrect auction state") |
---|
371 | | - | else { |
---|
372 | | - | let setNewFreelancer = { |
---|
373 | | - | let newFreelancer = getInteger(this, ((auctionId + "_Bid_") + freelancerPub)) |
---|
374 | | - | match newFreelancer { |
---|
375 | | - | case a: Int => |
---|
376 | | - | freelancerPub |
---|
377 | | - | case _ => |
---|
378 | | - | throw("Error: Incorrect freelancerPub") |
---|
379 | | - | } |
---|
380 | | - | } |
---|
381 | | - | let newAuctionPrice = { |
---|
382 | | - | let freelancerBid = getInteger(this, ((auctionId + "_Bid_") + freelancerPub)) |
---|
383 | | - | match freelancerBid { |
---|
384 | | - | case a: Int => |
---|
385 | | - | a |
---|
386 | | - | case _ => |
---|
387 | | - | throw("Auction lowest bidder was not found") |
---|
388 | | - | } |
---|
389 | | - | } |
---|
390 | | - | let amountDifference = (auctionPrice - freelancerBidAmount) |
---|
391 | | - | let newFreezedBalance = decreaseFreezedBalance(auctionAssetName, amountDifference) |
---|
392 | | - | ScriptResult(WriteSet([DataEntry((auctionId + "_State"), stateInProgress), DataEntry((auctionId + "_HiredFreelancer"), setNewFreelancer), DataEntry((auctionId + "_Price"), newAuctionPrice), DataEntry((auctionAssetName + "_Freezed"), newFreezedBalance)]), TransferSet([ScriptTransfer(addressFromPublicKey(auctionClient), (amountDifference - dAppCommission), auctionAssetId58)])) |
---|
393 | | - | } |
---|
394 | | - | else throw("Only auction customer can choose a freelancer") |
---|
395 | | - | } |
---|
396 | | - | |
---|
397 | | - | |
---|
398 | | - | |
---|
399 | | - | @Callable(i) |
---|
400 | | - | func increaseExecutionTime (auctionId,executionDays) = { |
---|
401 | | - | let caller = extract(i.callerPublicKey) |
---|
402 | | - | let auctionState = getAuctionState(auctionId) |
---|
403 | | - | let auctionClient = getAuctionClientPub(auctionId) |
---|
404 | | - | let auctionBlocksForExecution = getAuctionJobPerformanceTime(auctionId) |
---|
405 | | - | let newAuctionExecutionTime = { |
---|
406 | | - | let newAuctionBlocksForExecution = (executionDays * day) |
---|
407 | | - | if ((newAuctionBlocksForExecution > auctionBlocksForExecution)) |
---|
408 | | - | then newAuctionBlocksForExecution |
---|
409 | | - | else throw("New execution time must more than current execution time") |
---|
410 | | - | } |
---|
411 | | - | if ((caller == auctionClient)) |
---|
412 | | - | then if (if (if ((auctionState == stateOpen)) |
---|
413 | | - | then true |
---|
414 | | - | else (auctionState == stateSuggested)) |
---|
415 | | - | then true |
---|
416 | | - | else (auctionState == stateInProgress)) |
---|
417 | | - | then WriteSet([DataEntry((auctionId + "_JobPerformance"), newAuctionExecutionTime)]) |
---|
418 | | - | else throw("Incorrect state") |
---|
419 | | - | else throw("Only Client can increase execution time") |
---|
420 | | - | } |
---|
421 | | - | |
---|
422 | | - | |
---|
423 | | - | |
---|
424 | | - | @Callable(i) |
---|
425 | | - | func cancelAuction (auctionId) = { |
---|
426 | | - | let callerPub = extract(i.callerPublicKey) |
---|
427 | | - | let auctionState = getAuctionState(auctionId) |
---|
428 | | - | let auctionClient = getAuctionClientPub(auctionId) |
---|
429 | | - | let auctionAssetName = getAuctionAssetName(auctionId) |
---|
430 | | - | let auctionPrice = getAuctionPrice(auctionId) |
---|
431 | | - | let auctionAssetId58 = AssetNameToBase58(auctionAssetName) |
---|
432 | | - | let dAppCommission = ((auctionPrice * 3) / 100) |
---|
433 | | - | let amountWithoutComm = (auctionPrice - dAppCommission) |
---|
434 | | - | let newFreezedBalance = decreaseFreezedBalance(auctionAssetName, auctionPrice) |
---|
435 | | - | let callerIsClient = if ((callerPub == auctionClient)) |
---|
436 | | - | then true |
---|
437 | | - | else throw("Auction can be canceled only by auction owner.") |
---|
438 | | - | if (callerIsClient) |
---|
439 | | - | then if ((auctionState == stateOpen)) |
---|
440 | | - | then ScriptResult(WriteSet([DataEntry((auctionId + "_State"), stateCancel), DataEntry((auctionAssetName + "_Freezed"), newFreezedBalance)]), TransferSet([ScriptTransfer(addressFromPublicKey(auctionClient), amountWithoutComm, auctionAssetId58)])) |
---|
441 | | - | else throw("Incorrect auction state.") |
---|
442 | | - | else throw("Only Client can cancel auction") |
---|
443 | | - | } |
---|
444 | | - | |
---|
445 | | - | |
---|
446 | | - | |
---|
447 | | - | @Callable(i) |
---|
448 | | - | func openDispute (auctionId) = { |
---|
449 | | - | let caller = extract(i.callerPublicKey) |
---|
450 | | - | let auctionState = getAuctionState(auctionId) |
---|
451 | | - | let auctionClient = getAuctionClientPub(auctionId) |
---|
452 | | - | let auctionFreelancer = getAuctionFreelancerPub(auctionId) |
---|
453 | | - | if (if ((auctionState == stateOpen)) |
---|
454 | | - | then true |
---|
455 | | - | else (auctionState == stateSuggested)) |
---|
456 | | - | then throw("Incorrect auction state for dispute opening") |
---|
457 | | - | else if (if ((caller == auctionClient)) |
---|
458 | | - | then true |
---|
459 | | - | else (caller == auctionFreelancer)) |
---|
460 | | - | then WriteSet([DataEntry((auctionId + "_State"), stateDispute), DataEntry((auctionId + "_DisputeVotes"), 0)]) |
---|
461 | | - | else throw("Only customer and freelancer can open dispute") |
---|
462 | | - | } |
---|
463 | | - | |
---|
464 | | - | |
---|
465 | | - | |
---|
466 | | - | @Callable(i) |
---|
467 | | - | func voteDispute (auctionId,vote) = { |
---|
468 | | - | let callerPub = extract(i.callerPublicKey) |
---|
469 | | - | let auctionState = getAuctionState(auctionId) |
---|
470 | | - | let auctionClient = getAuctionClientPub(auctionId) |
---|
471 | | - | let auctionAssetName = getAuctionAssetName(auctionId) |
---|
472 | | - | let auctionPrice = getAuctionPrice(auctionId) |
---|
473 | | - | let auctionFreelancer = getAuctionFreelancerPub(auctionId) |
---|
474 | | - | let comission = ((auctionPrice * 3) / 100) |
---|
475 | | - | let auctionAssetId58 = AssetNameToBase58(auctionAssetName) |
---|
476 | | - | let callerIsAmbassador = if (if (if (if (if ((callerPub == ambassador1)) |
---|
477 | | - | then true |
---|
478 | | - | else (callerPub == ambassador2)) |
---|
479 | | - | then true |
---|
480 | | - | else (callerPub == ambassador3)) |
---|
481 | | - | then true |
---|
482 | | - | else (callerPub == ambassador4)) |
---|
483 | | - | then true |
---|
484 | | - | else (callerPub == ambassador5)) |
---|
485 | | - | then toBase58String(callerPub) |
---|
486 | | - | else throw("Only defined ambassadors can vote in disputes") |
---|
487 | | - | let newVote = if (if ((vote == client)) |
---|
488 | | - | then true |
---|
489 | | - | else (vote == freelancer)) |
---|
490 | | - | then vote |
---|
491 | | - | else throw(((("Vote is incorrect. Must be: " + client) + " or ") + freelancer)) |
---|
492 | | - | let newVoter = { |
---|
493 | | - | let keyVoter = ((auctionId + "_DiputeVote_") + callerIsAmbassador) |
---|
494 | | - | let valueVoter = getString(this, keyVoter) |
---|
495 | | - | match valueVoter { |
---|
496 | | - | case a: String => |
---|
497 | | - | throw("User already voted") |
---|
498 | | - | case _ => |
---|
499 | | - | callerIsAmbassador |
---|
500 | | - | } |
---|
501 | | - | } |
---|
502 | | - | let votesNumber = { |
---|
503 | | - | let valueVotesNumber = getInteger(this, (auctionId + "_DisputeVotes")) |
---|
504 | | - | match valueVotesNumber { |
---|
505 | | - | case a: Int => |
---|
506 | | - | a |
---|
507 | | - | case _ => |
---|
508 | | - | throw("VotesNumber was not found") |
---|
509 | | - | } |
---|
510 | | - | } |
---|
511 | | - | if ((auctionState == stateDispute)) |
---|
512 | | - | then if ((votesNumber == 4)) |
---|
513 | | - | then { |
---|
514 | | - | let disputeWinner = { |
---|
515 | | - | let ambassador1Vote = getString(this, ((auctionId + "_DiputeVote_") + toBase58String(ambassador1))) |
---|
516 | | - | let ambassador2Vote = getString(this, ((auctionId + "_DiputeVote_") + toBase58String(ambassador2))) |
---|
517 | | - | let ambassador3Vote = getString(this, ((auctionId + "_DiputeVote_") + toBase58String(ambassador3))) |
---|
518 | | - | let ambassador4Vote = getString(this, ((auctionId + "_DiputeVote_") + toBase58String(ambassador4))) |
---|
519 | | - | let ambassador5Vote = getString(this, ((auctionId + "_DiputeVote_") + toBase58String(ambassador5))) |
---|
520 | | - | let v1 = if ((ambassador1Vote == client)) |
---|
521 | | - | then 1 |
---|
522 | | - | else 0 |
---|
523 | | - | let v2 = if ((ambassador2Vote == client)) |
---|
524 | | - | then 1 |
---|
525 | | - | else 0 |
---|
526 | | - | let v3 = if ((ambassador3Vote == client)) |
---|
527 | | - | then 1 |
---|
528 | | - | else 0 |
---|
529 | | - | let v4 = if ((ambassador4Vote == client)) |
---|
530 | | - | then 1 |
---|
531 | | - | else 0 |
---|
532 | | - | let v5 = if ((ambassador5Vote == client)) |
---|
533 | | - | then 1 |
---|
534 | | - | else 0 |
---|
535 | | - | let currentVote = if ((newVote == client)) |
---|
536 | | - | then 1 |
---|
537 | | - | else 0 |
---|
538 | | - | let votesForClient = (((((v1 + v2) + v3) + v4) + v5) + currentVote) |
---|
539 | | - | if ((votesForClient > 2)) |
---|
540 | | - | then auctionClient |
---|
541 | | - | else auctionFreelancer |
---|
542 | | - | } |
---|
543 | | - | let paymentWithoutComm = if ((disputeWinner == auctionClient)) |
---|
544 | | - | then auctionPrice |
---|
545 | | - | else (auctionPrice - comission) |
---|
546 | | - | let newFreezedBalance = decreaseFreezedBalance(auctionAssetName, auctionPrice) |
---|
547 | | - | ScriptResult(WriteSet([DataEntry((auctionId + "_DisputeVotes"), (votesNumber + 1)), DataEntry((auctionId + "_State"), stateDisputeResolved), DataEntry(((auctionId + "_DiputeVote_") + callerIsAmbassador), newVote), DataEntry((auctionAssetName + "_Freezed"), newFreezedBalance)]), TransferSet([ScriptTransfer(addressFromPublicKey(disputeWinner), paymentWithoutComm, auctionAssetId58)])) |
---|
548 | | - | } |
---|
549 | | - | else WriteSet([DataEntry((auctionId + "_DisputeVotes"), (votesNumber + 1)), DataEntry(((auctionId + "_DiputeVote_") + callerIsAmbassador), newVote)]) |
---|
550 | | - | else throw(("Incorrect state. Must be: " + stateDispute)) |
---|
551 | | - | } |
---|
552 | | - | |
---|
553 | | - | |
---|
554 | | - | |
---|
555 | | - | @Callable(i) |
---|
556 | | - | func workHandOver (auctionId) = { |
---|
557 | | - | let callerPub = extract(i.callerPublicKey) |
---|
558 | | - | let auctionState = getAuctionState(auctionId) |
---|
559 | | - | let auctionStart = getAuctionStartTime(auctionId) |
---|
560 | | - | let auctionDuration = getAuctionDurationTime(auctionId) |
---|
561 | | - | let auctionBlocksForExecution = getAuctionJobPerformanceTime(auctionId) |
---|
562 | | - | let auctionFreelancer = getAuctionFreelancerPub(auctionId) |
---|
563 | | - | let currentTime = height |
---|
564 | | - | let freelancerPubCheck = if ((callerPub == auctionFreelancer)) |
---|
565 | | - | then callerPub |
---|
566 | | - | else throw("Only a freelancer can indicate that the work is done") |
---|
567 | | - | let timeIsOver = ((currentTime - auctionStart) > auctionBlocksForExecution) |
---|
568 | | - | if ((auctionState == stateInProgress)) |
---|
569 | | - | then if (timeIsOver) |
---|
570 | | - | then WriteSet([DataEntry((auctionId + "_State"), stateDispute), DataEntry((auctionId + "_DisputeVotes"), "0")]) |
---|
571 | | - | else WriteSet([DataEntry((auctionId + "_State"), stateWait4Confirm)]) |
---|
572 | | - | else throw("Auction state is incorrect") |
---|
573 | | - | } |
---|
574 | | - | |
---|
575 | | - | |
---|
576 | | - | |
---|
577 | | - | @Callable(i) |
---|
578 | | - | func acceptWork (auctionId) = { |
---|
579 | | - | let callerPub = extract(i.callerPublicKey) |
---|
580 | | - | let auctionState = getAuctionState(auctionId) |
---|
581 | | - | let auctionClient = getAuctionClientPub(auctionId) |
---|
582 | | - | let auctionStart = getAuctionStartTime(auctionId) |
---|
583 | | - | let auctionDuration = getAuctionDurationTime(auctionId) |
---|
584 | | - | let auctionAssetName = getAuctionAssetName(auctionId) |
---|
585 | | - | let auctionPrice = getAuctionPrice(auctionId) |
---|
586 | | - | let auctionFreelancer = getAuctionFreelancerPub(auctionId) |
---|
587 | | - | let dAppCommission = ((auctionPrice * 3) / 100) |
---|
588 | | - | let amountWithoutComm = (auctionPrice - dAppCommission) |
---|
589 | | - | let auctionAssetId58 = AssetNameToBase58(auctionAssetName) |
---|
590 | | - | let newFreezedBalance = decreaseFreezedBalance(auctionAssetName, auctionPrice) |
---|
591 | | - | let newRating = { |
---|
592 | | - | let valueRating = getInteger(this, (toBase58String(auctionFreelancer) + "_Rating")) |
---|
593 | | - | let currentRating = match valueRating { |
---|
594 | | - | case a: Int => |
---|
595 | | - | a |
---|
596 | | - | case _ => |
---|
597 | | - | 0 |
---|
598 | | - | } |
---|
599 | | - | (currentRating + 1) |
---|
600 | | - | } |
---|
601 | | - | if ((callerPub == auctionClient)) |
---|
602 | | - | then if ((auctionState == stateWait4Confirm)) |
---|
603 | | - | then ScriptResult(WriteSet([DataEntry((auctionId + "_State"), stateComplete), DataEntry((toBase58String(auctionFreelancer) + "_Rating"), newRating), DataEntry((auctionAssetName + "_Freezed"), newFreezedBalance)]), TransferSet([ScriptTransfer(addressFromPublicKey(auctionFreelancer), amountWithoutComm, auctionAssetId58)])) |
---|
604 | | - | else throw(("Incorrect state. Must be: " + stateWait4Confirm)) |
---|
605 | | - | else throw("Only auction customer can use this function") |
---|
606 | | - | } |
---|
607 | | - | |
---|
608 | | - | |
---|
609 | | - | @Verifier(tx) |
---|
610 | | - | func verify () = if (sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)) |
---|
611 | | - | then match tx { |
---|
612 | | - | case ttx: TransferTransaction => |
---|
613 | | - | true |
---|
614 | | - | case stx: SetScriptTransaction => |
---|
615 | | - | true |
---|
616 | | - | case _ => |
---|
617 | | - | false |
---|
618 | | - | } |
---|
619 | | - | else false |
---|