tx · 3qomQQsHPbsF4SY7KxySSVT4iwvH8S8MFeHFGsEKzxSs 3NCUy4yewhhgobHrkdSBNiCYajzXApktxaK: -0.04000000 Waves 2019.09.24 12:31 [690244] smart account 3NCUy4yewhhgobHrkdSBNiCYajzXApktxaK > SELF 0.00000000 Waves
{ "type": 13, "id": "3qomQQsHPbsF4SY7KxySSVT4iwvH8S8MFeHFGsEKzxSs", "fee": 4000000, "feeAssetId": null, "timestamp": 1569317451407, "version": 1, "sender": "3NCUy4yewhhgobHrkdSBNiCYajzXApktxaK", "senderPublicKey": "AEBLjt3LBirAMqq8TDdsSedvidamCEi6fV1nhL2DEpew", "proofs": [ "4AA4jisyCcRwdtaXDq8RBc2b1cDcrzn7aKNHspVWJVRg6hy67cGLzyzS7mZCDNSDTdJL2mxyoUF35rSHToCGpk8y" ], "script": "base64:AAIDAAAAAAAAAAAAAAAKAAAAAA5vd25lclB1YmxpY0tleQEAAAAgkD7fCqmCHKVfL8+fGFXRYhqUJqS1aPUU7D38lld+FgAAAAAAH2Rlc3RpbmF0aW9uV2FsbGV0QWRkcmVzc0RhdGFLZXkCAAAAGmRlc3RpbmF0aW9uX3dhbGxldF9hZGRyZXNzAQAAABFnZXRMb290Qm94RGF0YUtleQAAAAEAAAACaWQJAAEsAAAAAgIAAAAJbG9vdF9ib3hfBQAAAAJpZAEAAAAWZ2V0TG9vdEJveFByaWNlRGF0YUtleQAAAAEAAAACaWQJAAEsAAAAAgkBAAAAEWdldExvb3RCb3hEYXRhS2V5AAAAAQUAAAACaWQCAAAABl9wcmljZQEAAAAWZ2V0TG9vdEJveExpbWl0RGF0YUtleQAAAAEAAAACaWQJAAEsAAAAAgkBAAAAEWdldExvb3RCb3hEYXRhS2V5AAAAAQUAAAACaWQCAAAABl9saW1pdAEAAAAZZ2V0TG9vdEJveEJ1eUNvdW50RGF0YUtleQAAAAEAAAACaWQJAAEsAAAAAgkBAAAAEWdldExvb3RCb3hEYXRhS2V5AAAAAQUAAAACaWQCAAAACl9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ltaXQCAAAAISBpdGVtcyBkdWUgbGltaXQsIGN1cnJlbnQgY291bnQ6IAkAAaQAAAABBQAAAAhidXlDb3VudAkBAAAADFNjcmlwdFJlc3VsdAAAAAIJAQAAAAhXcml0ZVNldAAAAAEJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAQAAABlnZXRMb290Qm94QnV5Q291bnREYXRhS2V5AAAAAQUAAAAFaWRTdHIFAAAAC25ld0J1eUNvdW50BQAAAANuaWwJAQAAAAtUcmFuc2ZlclNldAAAAAEJAARMAAAAAgkBAAAADlNjcmlwdFRyYW5zZmVyAAAAAwkBAAAAG2dldERlc3RpbmF0aW9uV2FsbGV0QWRkcmVzcwAAAAAFAAAADHBsYXllclBheVN1bQUAAAAEdW5pdAUAAAADbmlsAAAAAP+mMm4=", "chainId": 84, "height": 690244, "spentComplexity": 0 } View: original | compacted Prev: HzUbBnmAvgNZjossZqzcZ6HopW3BAmLiVdRxAPAY3jjg Next: 9GZX2QiM9Rquy8zeDhB7QBTauQwHsrg75JsTVp2MUjGQ Diff:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let ownerPublicKey = base58' | |
4 | + | let ownerPublicKey = base58'Ai5K72PXnQpuH5CCLZcpZWSPGyvSmuBY9PHhFEQStzX9' | |
5 | 5 | ||
6 | 6 | let destinationWalletAddressDataKey = "destination_wallet_address" | |
7 | 7 | ||
8 | - | func getLootBoxDataKey (id) = ("loot_box_" + toString(id)) | |
8 | + | func getLootBoxDataKey (id) = ("loot_box_" + id) | |
9 | + | ||
10 | + | ||
11 | + | func getLootBoxPriceDataKey (id) = (getLootBoxDataKey(id) + "_price") | |
12 | + | ||
13 | + | ||
14 | + | func getLootBoxLimitDataKey (id) = (getLootBoxDataKey(id) + "_limit") | |
15 | + | ||
16 | + | ||
17 | + | func getLootBoxBuyCountDataKey (id) = (getLootBoxDataKey(id) + "_buy_count") | |
9 | 18 | ||
10 | 19 | ||
11 | 20 | func getDestinationWalletAddress () = match getString(this, destinationWalletAddressDataKey) { | |
18 | 27 | } | |
19 | 28 | ||
20 | 29 | ||
21 | - | func getLootBoxPrice (id) = match getInteger(this, | |
30 | + | func getLootBoxPrice (id) = match getInteger(this, getLootBoxPriceDataKey(id)) { | |
22 | 31 | case v: Int => | |
23 | 32 | v | |
24 | 33 | case _ => | |
25 | 34 | throw("Loot box price undefined") | |
35 | + | } | |
36 | + | ||
37 | + | ||
38 | + | func getLootBoxLimit (id) = match getInteger(this, getLootBoxLimitDataKey(id)) { | |
39 | + | case v: Int => | |
40 | + | v | |
41 | + | case _ => | |
42 | + | throw("Loot box limit undefined") | |
43 | + | } | |
44 | + | ||
45 | + | ||
46 | + | func getLootBoxBuyCount (id) = match getInteger(this, getLootBoxBuyCountDataKey(id)) { | |
47 | + | case v: Int => | |
48 | + | v | |
49 | + | case _ => | |
50 | + | 0 | |
26 | 51 | } | |
27 | 52 | ||
28 | 53 | ||
36 | 61 | ||
37 | 62 | ||
38 | 63 | @Callable(i) | |
39 | - | func | |
64 | + | func setLootBoxInfo (id,price,limit) = if ((i.callerPublicKey != ownerPublicKey)) | |
40 | 65 | then throw("Only owner can call this method") | |
41 | 66 | else if ((id == 0)) | |
42 | 67 | then throw("Loot id undefined") | |
43 | 68 | else if ((price == 0)) | |
44 | 69 | then throw("Price undefined") | |
45 | - | else WriteSet([DataEntry(getLootBoxDataKey(id), price)]) | |
70 | + | else if ((limit == 0)) | |
71 | + | then throw("Limit undefined") | |
72 | + | else { | |
73 | + | let idStr = toString(id) | |
74 | + | WriteSet([DataEntry(getLootBoxPriceDataKey(idStr), price), DataEntry(getLootBoxLimitDataKey(idStr), limit)]) | |
75 | + | } | |
46 | 76 | ||
47 | 77 | ||
48 | 78 | ||
49 | 79 | @Callable(i) | |
50 | 80 | func buyLootBox (id) = { | |
81 | + | let idStr = toString(id) | |
51 | 82 | let payment = extract(i.payment) | |
52 | - | let lootBoxPrice = getLootBoxPrice(id) | |
53 | - | let playerPaySum = payment.amount | |
54 | - | if ((playerPaySum != lootBoxPrice)) | |
55 | - | then throw(((("Price must be equal " + toString(lootBoxPrice)) + " wavelets, given: ") + toString(playerPaySum))) | |
56 | - | else TransferSet([ScriptTransfer(getDestinationWalletAddress(), playerPaySum, unit)]) | |
83 | + | if (isDefined(payment.assetId)) | |
84 | + | then throw("Can hodl waves only at the moment") | |
85 | + | else { | |
86 | + | let buyCount = getLootBoxBuyCount(idStr) | |
87 | + | let newBuyCount = (buyCount + 1) | |
88 | + | let lootBoxLimit = getLootBoxLimit(idStr) | |
89 | + | let lootBoxPrice = getLootBoxPrice(idStr) | |
90 | + | let playerPaySum = payment.amount | |
91 | + | if ((playerPaySum != lootBoxPrice)) | |
92 | + | then throw(((("Price must be equal " + toString(lootBoxPrice)) + " wavelets, given: ") + toString(playerPaySum))) | |
93 | + | else if ((newBuyCount > lootBoxLimit)) | |
94 | + | then throw(((("Cannot sale more " + toString(lootBoxLimit)) + " items due limit, current count: ") + toString(buyCount))) | |
95 | + | else ScriptResult(WriteSet([DataEntry(getLootBoxBuyCountDataKey(idStr), newBuyCount)]), TransferSet([ScriptTransfer(getDestinationWalletAddress(), playerPaySum, unit)])) | |
96 | + | } | |
57 | 97 | } | |
58 | 98 | ||
59 | 99 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let ownerPublicKey = base58' | |
4 | + | let ownerPublicKey = base58'Ai5K72PXnQpuH5CCLZcpZWSPGyvSmuBY9PHhFEQStzX9' | |
5 | 5 | ||
6 | 6 | let destinationWalletAddressDataKey = "destination_wallet_address" | |
7 | 7 | ||
8 | - | func getLootBoxDataKey (id) = ("loot_box_" + toString(id)) | |
8 | + | func getLootBoxDataKey (id) = ("loot_box_" + id) | |
9 | + | ||
10 | + | ||
11 | + | func getLootBoxPriceDataKey (id) = (getLootBoxDataKey(id) + "_price") | |
12 | + | ||
13 | + | ||
14 | + | func getLootBoxLimitDataKey (id) = (getLootBoxDataKey(id) + "_limit") | |
15 | + | ||
16 | + | ||
17 | + | func getLootBoxBuyCountDataKey (id) = (getLootBoxDataKey(id) + "_buy_count") | |
9 | 18 | ||
10 | 19 | ||
11 | 20 | func getDestinationWalletAddress () = match getString(this, destinationWalletAddressDataKey) { | |
12 | 21 | case v: String => | |
13 | 22 | if ((v == "")) | |
14 | 23 | then throw("Destination wallet address cannot be empty") | |
15 | 24 | else addressFromStringValue(v) | |
16 | 25 | case _ => | |
17 | 26 | throw("Destination wallet address undefined") | |
18 | 27 | } | |
19 | 28 | ||
20 | 29 | ||
21 | - | func getLootBoxPrice (id) = match getInteger(this, | |
30 | + | func getLootBoxPrice (id) = match getInteger(this, getLootBoxPriceDataKey(id)) { | |
22 | 31 | case v: Int => | |
23 | 32 | v | |
24 | 33 | case _ => | |
25 | 34 | throw("Loot box price undefined") | |
35 | + | } | |
36 | + | ||
37 | + | ||
38 | + | func getLootBoxLimit (id) = match getInteger(this, getLootBoxLimitDataKey(id)) { | |
39 | + | case v: Int => | |
40 | + | v | |
41 | + | case _ => | |
42 | + | throw("Loot box limit undefined") | |
43 | + | } | |
44 | + | ||
45 | + | ||
46 | + | func getLootBoxBuyCount (id) = match getInteger(this, getLootBoxBuyCountDataKey(id)) { | |
47 | + | case v: Int => | |
48 | + | v | |
49 | + | case _ => | |
50 | + | 0 | |
26 | 51 | } | |
27 | 52 | ||
28 | 53 | ||
29 | 54 | @Callable(i) | |
30 | 55 | func setDestinationWallet (address) = if ((i.callerPublicKey != ownerPublicKey)) | |
31 | 56 | then throw("Only owner can call this method") | |
32 | 57 | else if ((address == "")) | |
33 | 58 | then throw("Address cannot be empty") | |
34 | 59 | else WriteSet([DataEntry(destinationWalletAddressDataKey, address)]) | |
35 | 60 | ||
36 | 61 | ||
37 | 62 | ||
38 | 63 | @Callable(i) | |
39 | - | func | |
64 | + | func setLootBoxInfo (id,price,limit) = if ((i.callerPublicKey != ownerPublicKey)) | |
40 | 65 | then throw("Only owner can call this method") | |
41 | 66 | else if ((id == 0)) | |
42 | 67 | then throw("Loot id undefined") | |
43 | 68 | else if ((price == 0)) | |
44 | 69 | then throw("Price undefined") | |
45 | - | else WriteSet([DataEntry(getLootBoxDataKey(id), price)]) | |
70 | + | else if ((limit == 0)) | |
71 | + | then throw("Limit undefined") | |
72 | + | else { | |
73 | + | let idStr = toString(id) | |
74 | + | WriteSet([DataEntry(getLootBoxPriceDataKey(idStr), price), DataEntry(getLootBoxLimitDataKey(idStr), limit)]) | |
75 | + | } | |
46 | 76 | ||
47 | 77 | ||
48 | 78 | ||
49 | 79 | @Callable(i) | |
50 | 80 | func buyLootBox (id) = { | |
81 | + | let idStr = toString(id) | |
51 | 82 | let payment = extract(i.payment) | |
52 | - | let lootBoxPrice = getLootBoxPrice(id) | |
53 | - | let playerPaySum = payment.amount | |
54 | - | if ((playerPaySum != lootBoxPrice)) | |
55 | - | then throw(((("Price must be equal " + toString(lootBoxPrice)) + " wavelets, given: ") + toString(playerPaySum))) | |
56 | - | else TransferSet([ScriptTransfer(getDestinationWalletAddress(), playerPaySum, unit)]) | |
83 | + | if (isDefined(payment.assetId)) | |
84 | + | then throw("Can hodl waves only at the moment") | |
85 | + | else { | |
86 | + | let buyCount = getLootBoxBuyCount(idStr) | |
87 | + | let newBuyCount = (buyCount + 1) | |
88 | + | let lootBoxLimit = getLootBoxLimit(idStr) | |
89 | + | let lootBoxPrice = getLootBoxPrice(idStr) | |
90 | + | let playerPaySum = payment.amount | |
91 | + | if ((playerPaySum != lootBoxPrice)) | |
92 | + | then throw(((("Price must be equal " + toString(lootBoxPrice)) + " wavelets, given: ") + toString(playerPaySum))) | |
93 | + | else if ((newBuyCount > lootBoxLimit)) | |
94 | + | then throw(((("Cannot sale more " + toString(lootBoxLimit)) + " items due limit, current count: ") + toString(buyCount))) | |
95 | + | else ScriptResult(WriteSet([DataEntry(getLootBoxBuyCountDataKey(idStr), newBuyCount)]), TransferSet([ScriptTransfer(getDestinationWalletAddress(), playerPaySum, unit)])) | |
96 | + | } | |
57 | 97 | } | |
58 | 98 | ||
59 | 99 |
github/deemru/w8io/169f3d6 47.98 ms ◑