2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let lastCell = 4 |
---|
5 | | - | |
---|
6 | | - | let cellsKey = "cells" |
---|
7 | | - | |
---|
8 | | - | @Callable(i) |
---|
9 | | - | func create (name,desc,ticketPrice,ticketAsset) = { |
---|
10 | | - | let assetId = if ((ticketAsset != "WAVES")) |
---|
11 | | - | then { |
---|
12 | | - | let aInfo = valueOrErrorMessage(assetInfo(fromBase58String(ticketAsset)), "There is no asset with specified id") |
---|
13 | | - | ticketAsset |
---|
14 | | - | } |
---|
15 | | - | else "WAVES" |
---|
16 | | - | let pmt = valueOrErrorMessage(i.payment, "Where is prize?") |
---|
17 | | - | let prizeAsset = if (isDefined(pmt.assetId)) |
---|
18 | | - | then toBase58String(value(pmt.assetId)) |
---|
19 | | - | else "WAVES" |
---|
20 | | - | if (if (if ((name == "")) |
---|
21 | | - | then true |
---|
22 | | - | else (desc == "")) |
---|
23 | | - | then true |
---|
24 | | - | else (0 > ticketPrice)) |
---|
25 | | - | then throw("Invalid name, description or ticket price") |
---|
26 | | - | else { |
---|
27 | | - | let lotteryId = toBase58String(i.transactionId) |
---|
28 | | - | WriteSet([DataEntry((lotteryId + "_name"), name), DataEntry((lotteryId + "_desc"), desc), DataEntry((lotteryId + "_ticket_price"), ticketPrice), DataEntry((lotteryId + "_ticket_asset"), assetId), DataEntry((lotteryId + "_prize_amount"), pmt.amount), DataEntry((lotteryId + "_prize_asset"), prizeAsset), DataEntry((lotteryId + "_creator"), toBase58String(i.caller.bytes)), DataEntry((lotteryId + "_cells"), 0), DataEntry((lotteryId + "_status"), true), DataEntry((lotteryId + "_balance"), 0)]) |
---|
29 | | - | } |
---|
30 | | - | } |
---|
31 | | - | |
---|
32 | | - | |
---|
33 | | - | |
---|
34 | | - | @Callable(i) |
---|
35 | | - | func buy (id,cell) = { |
---|
36 | | - | let cells = valueOrErrorMessage(getInteger(this, (id + "_cells")), "No lottery with specified id") |
---|
37 | | - | let status = getBooleanValue(this, (id + "_status")) |
---|
38 | | - | if (!(status)) |
---|
39 | | - | then throw("Specified lottery is over") |
---|
40 | | - | else if (if ((0 > cell)) |
---|
41 | | - | then true |
---|
42 | | - | else (cell > lastCell)) |
---|
43 | | - | then throw("Invalid number") |
---|
44 | | - | else { |
---|
45 | | - | let ticketPrice = valueOrErrorMessage(getInteger(this, (id + "_ticket_price")), "Ticket price error") |
---|
46 | | - | let ticketAsset = valueOrErrorMessage(getString(this, (id + "_ticket_asset")), "Ticket asset error") |
---|
47 | | - | let pmt = valueOrErrorMessage(i.payment, "Where is payment?") |
---|
48 | | - | let assetId = if (isDefined(pmt.assetId)) |
---|
49 | | - | then toBase58String(value(pmt.assetId)) |
---|
50 | | - | else "WAVES" |
---|
51 | | - | if (if ((assetId != ticketAsset)) |
---|
52 | | - | then true |
---|
53 | | - | else (pmt.amount != ticketPrice)) |
---|
54 | | - | then throw("Invalid payment") |
---|
55 | | - | else if (isDefined(getString(this, toString(cell)))) |
---|
56 | | - | then throw("Already bought") |
---|
57 | | - | else { |
---|
58 | | - | let last = (cells == lastCell) |
---|
59 | | - | let balance = (valueOrErrorMessage(getInteger(this, (id + "_balance")), "Balance error") + pmt.amount) |
---|
60 | | - | if (last) |
---|
61 | | - | then { |
---|
62 | | - | let creator = addressFromStringValue(valueOrErrorMessage(getString(this, (id + "_creator")), "Creator error")) |
---|
63 | | - | let prizeAmount = valueOrErrorMessage(getInteger(this, (id + "_prize_amount")), "Prize amount error") |
---|
64 | | - | let prizeAsset = valueOrErrorMessage(getString(this, (id + "_prize_asset")), "Prize asset error") |
---|
65 | | - | let winCell = (toInt(lastBlock.generationSignature) % (lastCell + 1)) |
---|
66 | | - | let winAddress = if ((winCell == cell)) |
---|
67 | | - | then i.caller |
---|
68 | | - | else { |
---|
69 | | - | let winData = valueOrErrorMessage(getString(this, ((id + "_cell:") + toString(winCell))), "Win data error") |
---|
70 | | - | value(addressFromString(winData)) |
---|
71 | | - | } |
---|
72 | | - | ScriptResult(WriteSet([DataEntry((id + "_status"), false), DataEntry((id + "_balance"), 0), DataEntry((id + "_cells"), (cells + 1)), DataEntry(((id + "_cell:") + toString(cell)), toString(i.caller)), DataEntry((id + "_winner:"), toBase58String(winAddress.bytes))]), TransferSet([if ((prizeAsset == "WAVES")) |
---|
73 | | - | then ScriptTransfer(winAddress, prizeAmount, unit) |
---|
74 | | - | else ScriptTransfer(winAddress, prizeAmount, fromBase58String(prizeAsset)), if ((ticketAsset == "WAVES")) |
---|
75 | | - | then ScriptTransfer(creator, balance, unit) |
---|
76 | | - | else ScriptTransfer(creator, balance, fromBase58String(ticketAsset))])) |
---|
77 | | - | } |
---|
78 | | - | else WriteSet([DataEntry(((id + "_cell:") + toString(cell)), toString(i.caller)), DataEntry((id + "_cells"), (cells + 1)), DataEntry((id + "_balance"), balance)]) |
---|
79 | | - | } |
---|
80 | | - | } |
---|
81 | | - | } |
---|
82 | | - | |
---|
83 | | - | |
---|
84 | | - | @Verifier(tx) |
---|
85 | | - | func verify () = true |
---|
86 | | - | |
---|
| 2 | + | {-# CONTENT_TYPE EXPRESSION #-} |
---|
| 3 | + | let PubKey1 = base58'854p8BYzrj6yBPRPmfQur3oF1Rjc1AJ548qRp5FT5kDa' |
---|
| 4 | + | let PubKey2 = base58'DKGFPozLrsiR8NM4NJzqQaBYC8NyGYjuw2hDYicQVjco' |
---|
| 5 | + | let sig1 = if (sigVerify(tx.bodyBytes, tx.proofs[0], PubKey1)) |
---|
| 6 | + | then 1 |
---|
| 7 | + | else 0 |
---|
| 8 | + | let sig2 = if (sigVerify(tx.bodyBytes, tx.proofs[1], PubKey2)) |
---|
| 9 | + | then 1 |
---|
| 10 | + | else 0 |
---|
| 11 | + | ((sig1 + sig2) > 0) |
---|