2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let a = 4 |
---|
5 | | - | |
---|
6 | | - | let b = "cells" |
---|
7 | | - | |
---|
8 | | - | @Callable(c) |
---|
9 | | - | func create (d,e,f,g) = { |
---|
10 | | - | let h = if ((g != "WAVES")) |
---|
11 | | - | then { |
---|
12 | | - | let i = valueOrErrorMessage(assetInfo(fromBase58String(g)), "There is no asset with specified id") |
---|
13 | | - | g |
---|
14 | | - | } |
---|
15 | | - | else "" |
---|
16 | | - | let j = valueOrErrorMessage(c.payment, "Where is prize?") |
---|
17 | | - | let k = if (isDefined(j.assetId)) |
---|
18 | | - | then toBase58String(value(j.assetId)) |
---|
19 | | - | else "" |
---|
20 | | - | if (if (if ((d == "")) |
---|
21 | | - | then true |
---|
22 | | - | else (e == "")) |
---|
23 | | - | then true |
---|
24 | | - | else (0 > f)) |
---|
25 | | - | then throw("Invalid name, description or ticket price") |
---|
26 | | - | else { |
---|
27 | | - | let l = toBase58String(c.transactionId) |
---|
28 | | - | WriteSet([DataEntry((l + "_name"), d), DataEntry((l + "_desc"), e), DataEntry((l + "_ticket_price"), f), DataEntry((l + "_ticket_asset"), h), DataEntry((l + "_prize_amount"), j.amount), DataEntry((l + "_prize_asset"), k), DataEntry((l + "_creator"), toBase58String(c.caller.bytes)), DataEntry((l + "_cells"), 0), DataEntry((l + "_status"), true), DataEntry((l + "_balance"), 0)]) |
---|
29 | | - | } |
---|
30 | | - | } |
---|
31 | | - | |
---|
32 | | - | |
---|
33 | | - | |
---|
34 | | - | @Callable(c) |
---|
35 | | - | func buy (m,n) = { |
---|
36 | | - | let o = valueOrErrorMessage(getInteger(this, (m + "_cells")), "No lottery with specified id") |
---|
37 | | - | let p = valueOrErrorMessage(getBoolean(this, (m + "_status")), "Invalid status of lottery with specified id") |
---|
38 | | - | if (!(p)) |
---|
39 | | - | then throw("Specified lottery is over") |
---|
40 | | - | else if (if ((0 > n)) |
---|
41 | | - | then true |
---|
42 | | - | else (n > a)) |
---|
43 | | - | then throw("Invalid number") |
---|
44 | | - | else { |
---|
45 | | - | let f = valueOrErrorMessage(getInteger(this, (m + "_ticket_price")), "Invalid ticket price") |
---|
46 | | - | let g = valueOrErrorMessage(getString(this, (m + "_ticket_asset")), "Invalid ticket asset") |
---|
47 | | - | let j = valueOrErrorMessage(c.payment, "Where is payment?") |
---|
48 | | - | let h = if (isDefined(j.assetId)) |
---|
49 | | - | then toBase58String(value(j.assetId)) |
---|
50 | | - | else "" |
---|
51 | | - | if (if ((h != g)) |
---|
52 | | - | then true |
---|
53 | | - | else (j.amount != f)) |
---|
54 | | - | then throw("Invalid payment") |
---|
55 | | - | else if (isDefined(getString(this, ((m + "_cell:") + toString(n))))) |
---|
56 | | - | then throw("Already bought") |
---|
57 | | - | else { |
---|
58 | | - | let q = (o == a) |
---|
59 | | - | let r = (valueOrErrorMessage(getInteger(this, (m + "_balance")), "Invalid balance") + j.amount) |
---|
60 | | - | if (q) |
---|
61 | | - | then { |
---|
62 | | - | let s = addressFromStringValue(valueOrErrorMessage(getString(this, (m + "_creator")), "Invalid lottery creator")) |
---|
63 | | - | let t = valueOrErrorMessage(getInteger(this, (m + "_prize_amount")), "Invalid prize amount") |
---|
64 | | - | let k = valueOrErrorMessage(getString(this, (m + "_prize_asset")), "Invalid prize asset") |
---|
65 | | - | let u = (toInt(lastBlock.generationSignature) % (a + 1)) |
---|
66 | | - | let v = valueOrErrorMessage(getString(this, ((m + "_cell:") + toString(u))), "Invalid win cell") |
---|
67 | | - | let w = if ((u == n)) |
---|
68 | | - | then c.caller |
---|
69 | | - | else value(addressFromString(v)) |
---|
70 | | - | ScriptResult(WriteSet([DataEntry((m + "_status"), false), DataEntry((m + "_balance"), 0)]), TransferSet([if ((g == "")) |
---|
71 | | - | then ScriptTransfer(s, r, unit) |
---|
72 | | - | else ScriptTransfer(s, r, fromBase58String(g)), if ((k == "")) |
---|
73 | | - | then ScriptTransfer(w, t, unit) |
---|
74 | | - | else ScriptTransfer(w, t, fromBase58String(k))])) |
---|
75 | | - | } |
---|
76 | | - | else WriteSet([DataEntry(((m + "_cell:") + toString(n)), toString(c.caller)), DataEntry((m + "_cells"), (o + 1)), DataEntry((m + "_balance"), r)]) |
---|
77 | | - | } |
---|
78 | | - | } |
---|
79 | | - | } |
---|
80 | | - | |
---|
81 | | - | |
---|
82 | | - | @Verifier(x) |
---|
83 | | - | func y () = true |
---|
84 | | - | |
---|
| 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) |
---|