2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let adminPublicKey = base58'5584brtd1tLqMNJdCzvPFUEL1ujYRyi4Sy3zEZ5nTPsJ' |
---|
5 | | - | |
---|
6 | | - | let wctId = base58'DHgwrRvVyqJsepd32YbBqUeDH4GJ1N984X8QoekjgH8J' |
---|
7 | | - | |
---|
8 | | - | let wvsPrice = 100000000 |
---|
9 | | - | |
---|
10 | | - | let wctPrice = 100 |
---|
11 | | - | |
---|
12 | | - | let lastCell = 24 |
---|
13 | | - | |
---|
14 | | - | let roundKey = "round" |
---|
15 | | - | |
---|
16 | | - | let cellsKey = "cells" |
---|
17 | | - | |
---|
18 | | - | let lastWinKey = "lastWin" |
---|
19 | | - | |
---|
20 | | - | let lastWinWctKey = "lastWinWct" |
---|
21 | | - | |
---|
22 | | - | let lastWinWvsKey = "lastWinWvs" |
---|
23 | | - | |
---|
24 | | - | @Callable(i) |
---|
25 | | - | func create (ticketAsset) = { |
---|
26 | | - | let aInfo = valueOrErrorMessage(assetInfo(ticketAsset), "There is no asset with specified id") |
---|
27 | | - | throw(toBase58String(aInfo.id)) |
---|
28 | | - | } |
---|
29 | | - | |
---|
30 | | - | |
---|
31 | | - | |
---|
32 | | - | @Callable(i) |
---|
33 | | - | func buy (cell) = { |
---|
34 | | - | let round = extract(getInteger(this, roundKey)) |
---|
35 | | - | let cells = extract(getInteger(this, cellsKey)) |
---|
36 | | - | if (if ((0 > cell)) |
---|
37 | | - | then true |
---|
38 | | - | else (cell > lastCell)) |
---|
39 | | - | then throw("Invalid number") |
---|
40 | | - | else { |
---|
41 | | - | let pmt = valueOrErrorMessage(i.payment, "Where is payment?") |
---|
42 | | - | let wvs = !(isDefined(pmt.assetId)) |
---|
43 | | - | let wct = (pmt.assetId == wctId) |
---|
44 | | - | if (if (if (if (!(wct)) |
---|
45 | | - | then !(wvs) |
---|
46 | | - | else false) |
---|
47 | | - | then true |
---|
48 | | - | else if (wct) |
---|
49 | | - | then (pmt.amount != wctPrice) |
---|
50 | | - | else false) |
---|
51 | | - | then true |
---|
52 | | - | else if (wvs) |
---|
53 | | - | then (pmt.amount != wvsPrice) |
---|
54 | | - | else false) |
---|
55 | | - | then throw("Price is 1 WCT or 1 WAVES") |
---|
56 | | - | else { |
---|
57 | | - | let cellData = getString(this, toString(cell)) |
---|
58 | | - | let bought = if (isDefined(cellData)) |
---|
59 | | - | then { |
---|
60 | | - | let cellRound = split(extract(cellData), "_")[1] |
---|
61 | | - | if ((cellRound == toString(round))) |
---|
62 | | - | then true |
---|
63 | | - | else false |
---|
64 | | - | } |
---|
65 | | - | else false |
---|
66 | | - | if (bought) |
---|
67 | | - | then throw("Already bought") |
---|
68 | | - | else { |
---|
69 | | - | let last = (cells == lastCell) |
---|
70 | | - | if (last) |
---|
71 | | - | then { |
---|
72 | | - | let wctFlag = if (wct) |
---|
73 | | - | then 1 |
---|
74 | | - | else 0 |
---|
75 | | - | let wvsFlag = if (wvs) |
---|
76 | | - | then 1 |
---|
77 | | - | else 0 |
---|
78 | | - | let wctAmount = (assetBalance(this, wctId) + (pmt.amount * wctFlag)) |
---|
79 | | - | let wvsAmount = (wavesBalance(this) + (pmt.amount * wvsFlag)) |
---|
80 | | - | let wvsAdminShare = (wvsAmount / 100) |
---|
81 | | - | let wvsWinShare = (wvsAmount - wvsAdminShare) |
---|
82 | | - | let wctAdminShare = (wctAmount / 100) |
---|
83 | | - | let wctWinShare = (wctAmount - wctAdminShare) |
---|
84 | | - | let adminAddress = addressFromPublicKey(adminPublicKey) |
---|
85 | | - | let winCell = (toInt(lastBlock.generationSignature) % (lastCell + 1)) |
---|
86 | | - | let winData = extract(getString(this, toString(winCell))) |
---|
87 | | - | let winAddress = if ((winCell == cell)) |
---|
88 | | - | then i.caller |
---|
89 | | - | else extract(addressFromString(split(winData, "_")[0])) |
---|
90 | | - | ScriptResult(WriteSet([DataEntry(toString(cell), ((toString(i.caller) + "_") + toString(round))), DataEntry(cellsKey, 0), DataEntry(roundKey, (round + 1)), DataEntry(lastWinKey, ((toString(winCell) + "_") + toString(winAddress))), DataEntry(lastWinWvsKey, wvsAmount), DataEntry(lastWinWctKey, wctAmount)]), TransferSet([ScriptTransfer(winAddress, wvsWinShare, unit), ScriptTransfer(adminAddress, wvsAdminShare, unit), ScriptTransfer(winAddress, wctWinShare, wctId), ScriptTransfer(adminAddress, wctAdminShare, wctId)])) |
---|
91 | | - | } |
---|
92 | | - | else WriteSet([DataEntry(toString(cell), ((toString(i.caller) + "_") + toString(round))), DataEntry(cellsKey, (cells + 1))]) |
---|
93 | | - | } |
---|
94 | | - | } |
---|
95 | | - | } |
---|
96 | | - | } |
---|
97 | | - | |
---|
98 | | - | |
---|
99 | | - | @Verifier(tx) |
---|
100 | | - | func verify () = true |
---|
101 | | - | |
---|
| 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) |
---|