1 | | - | {-# STDLIB_VERSION 3 #-} |
---|
2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let ownerPublicKey = base58'9UUaVVahBUyLHLQo4HNuQsRMKY9QBH43Grojkbdf4wG4' |
---|
5 | | - | |
---|
6 | | - | func getDestinationWalletAddress () = match getString(this, "destination_wallet_public_key") { |
---|
7 | | - | case v: String => |
---|
8 | | - | if ((v == "")) |
---|
9 | | - | then throw("Destination wallet address cannot be empty") |
---|
10 | | - | else addressFromPublicKey(toBytes(v)) |
---|
11 | | - | case _ => |
---|
12 | | - | throw("Destination wallet undefined") |
---|
13 | | - | } |
---|
14 | | - | |
---|
15 | | - | |
---|
16 | | - | func getLootBoxPrice (id) = match getInteger(this, ("loot_box_" + toString(id))) { |
---|
17 | | - | case v: Int => |
---|
18 | | - | v |
---|
19 | | - | case _ => |
---|
20 | | - | throw("Loot box price undefined") |
---|
21 | | - | } |
---|
22 | | - | |
---|
23 | | - | |
---|
24 | | - | @Callable(i) |
---|
25 | | - | func setDestinationWallet (publicKey) = if ((i.callerPublicKey != ownerPublicKey)) |
---|
26 | | - | then throw("Only owner can call this method") |
---|
27 | | - | else if ((publicKey == "")) |
---|
28 | | - | then throw("Public key cannot be empty") |
---|
29 | | - | else WriteSet([DataEntry("destination_wallet_public_key", publicKey)]) |
---|
30 | | - | |
---|
31 | | - | |
---|
32 | | - | |
---|
33 | | - | @Callable(i) |
---|
34 | | - | func setLootBoxPrice (id,price) = if ((i.callerPublicKey != ownerPublicKey)) |
---|
35 | | - | then throw("Only owner can call this method") |
---|
36 | | - | else if ((id == 0)) |
---|
37 | | - | then throw("Loot id undefined") |
---|
38 | | - | else if ((price == 0)) |
---|
39 | | - | then throw("Price undefined") |
---|
40 | | - | else WriteSet([DataEntry(("loot_box_" + toString(id)), price)]) |
---|
41 | | - | |
---|
42 | | - | |
---|
43 | | - | |
---|
44 | | - | @Callable(i) |
---|
45 | | - | func buyLootBox (id) = { |
---|
46 | | - | let distinationWalletAddress = getDestinationWalletAddress() |
---|
47 | | - | let payment = extract(i.payment) |
---|
48 | | - | let lootBoxPrice = getLootBoxPrice(id) |
---|
49 | | - | let playerPaySum = payment.amount |
---|
50 | | - | if ((playerPaySum != lootBoxPrice)) |
---|
51 | | - | then throw(((("Price must be equal " + toString(lootBoxPrice)) + " wavelets, given: ") + toString(playerPaySum))) |
---|
52 | | - | else TransferSet([ScriptTransfer(distinationWalletAddress, playerPaySum, unit)]) |
---|
53 | | - | } |
---|
54 | | - | |
---|
55 | | - | |
---|
56 | | - | @Verifier(tx) |
---|
57 | | - | func verify () = match tx { |
---|
58 | | - | case i: InvokeScriptTransaction => |
---|
59 | | - | true |
---|
60 | | - | case _ => |
---|
61 | | - | sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) |
---|
62 | | - | } |
---|
63 | | - | |
---|
| 1 | + | # no script |
---|