tx · 4teELnsVnyY8cpsfBLt2qg8eMfmtr2E2mR8vToU2PMXP 3Mz9ndf12uVKYMqYmwUr81wcNLYEgr82ei6: -0.01400000 Waves 2019.11.16 22:40 [768102] smart account 3Mz9ndf12uVKYMqYmwUr81wcNLYEgr82ei6 > SELF 0.00000000 Waves
{ "type": 13, "id": "4teELnsVnyY8cpsfBLt2qg8eMfmtr2E2mR8vToU2PMXP", "fee": 1400000, "feeAssetId": null, "timestamp": 1573933223437, "version": 1, "sender": "3Mz9ndf12uVKYMqYmwUr81wcNLYEgr82ei6", "senderPublicKey": "8bmUdC19peGBa1TGeRZaZfpuDG6yKaGYBd8FQvcBLAXR", "proofs": [ "3AiPTLmwTuKnzJfCrBmyyrHJqvvrrJ1tp8JxgPmK8XqrVFuYifGkjcdb4AKj6S64g4SNL3oyV6VRvPe8L3j18WhE" ], "script": "base64:AAIDAAAAAAAAAAkIARIFCgMICAgAAAAdAAAAAAROT05FAgAAAARub25lAAAAAAZWT1RFUlMAAAAAAAAAAAMAAAAABlFVT1JVTQAAAAAAAAAAAgAAAAAGVk9USU5HAgAAAAZ2b3RpbmcAAAAABlJFVkVBTAIAAAAGcmV2ZWFsAAAAAAhGRUFUVVJFRAIAAAAIZmVhdHVyZWQAAAAACERFTElTVEVEAgAAAAhkZWxpc3RlZAEAAAALZ2V0U3RyQnlLZXkAAAABAAAAA2tleQQAAAADc3RyBAAAAAckbWF0Y2gwCQAEHQAAAAIFAAAABHRoaXMFAAAAA2tleQMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAAGU3RyaW5nBAAAAAFhBQAAAAckbWF0Y2gwBQAAAAFhBQAAAAROT05FBQAAAANzdHIBAAAADmdldE51bWJlckJ5S2V5AAAAAQAAAANrZXkEAAAAA251bQQAAAAHJG1hdGNoMAkABBoAAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAA0ludAQAAAABYQUAAAAHJG1hdGNoMAUAAAABYQAAAAAAAAA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AcJAAACAAAAAQIAAAAMd3Jvbmcgc3RhdHVzAwMJAQAAAAIhPQAAAAIFAAAABHZvdGUFAAAACEZFQVRVUkVECQEAAAACIT0AAAACBQAAAAR2b3RlBQAAAAhERUxJU1RFRAcJAAACAAAAAQIAAAAKd3Jvbmcgdm90ZQMDCQAAAAAAAAIFAAAABnN0YXR1cwUAAAAIRkVBVFVSRUQGCQAAAAAAAAIFAAAABnN0YXR1cwUAAAAIREVMSVNURUQJAAACAAAAAQIAAAARdm90ZSBoYXMgZmluaXNoZWQJAQAAAAhXcml0ZVNldAAAAAEJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAQAAAAxnZXRLZXlSZXZlYWwAAAACBQAAAARpdGVtBQAAAAR1c2VyBQAAAAR2b3RlCQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACCQEAAAAPZ2V0S2V5Vm90ZUNvdW50AAAAAgUAAAAEaXRlbQUAAAAEdm90ZQUAAAAMbmV3Vm90ZUNvdW50CQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACCQEAAAAQZ2V0S2V5SXRlbVN0YXR1cwAAAAEFAAAABGl0ZW0DCQAAZwAAAAIFAAAADG5ld1ZvdGVDb3VudAUAAAAGUVVPUlVNBQAAAAR2b3RlBQAAAAZSRVZFQUwFAAAAA25pbAAAAACQveNY", "chainId": 84, "height": 768102, "spentComplexity": 0 } View: original | compacted Prev: CbG2SFGC41RXzayu92DDGmMNxZmZYAeBVZp6xLcc1k4z Next: none Diff:
Old | New | Differences | |
---|---|---|---|
98 | 98 | ||
99 | 99 | ||
100 | 100 | @Callable(i) | |
101 | - | func | |
101 | + | func voteReveal (item,vote,salt) = { | |
102 | 102 | let user = toBase58String(i.caller.bytes) | |
103 | - | let commits = getValueCommitsCount(item) | |
104 | 103 | let status = getValueItemStatus(item) | |
105 | - | if ((commits >= VOTERS)) | |
106 | - | then throw("reahced max voters") | |
107 | - | else if ((getValueCommit(item, user) != NONE)) | |
108 | - | then throw("user already voted") | |
109 | - | else if ((getKeyItemSupp(item) == NONE)) | |
110 | - | then throw("item does not exist") | |
111 | - | else if (if ((status != NONE)) | |
112 | - | then (status != VOTING) | |
104 | + | let newVoteCount = (getValueVoteCount(item, vote) + 1) | |
105 | + | if ((toBase58String(sha256(toBytes((vote + salt)))) != getValueCommit(item, user))) | |
106 | + | then throw("reveal data is not valid") | |
107 | + | else if ((VOTERS > getValueCommitsCount(item))) | |
108 | + | then throw("max num of votes hasn't reached yet") | |
109 | + | else if ((getValueReveal(item, user) != NONE)) | |
110 | + | then throw("user has already participated") | |
111 | + | else if (if ((status != VOTING)) | |
112 | + | then (status != REVEAL) | |
113 | 113 | else false) | |
114 | - | then throw("vote is not possible") | |
115 | - | else WriteSet([DataEntry(getKeyCommit(item, user), hash), DataEntry(getKeyCommitsCount(item), (commits + 1)), DataEntry(getKeyItemStatus(item), if ((commits == VOTERS)) | |
116 | - | then REVEAL | |
117 | - | else VOTING)]) | |
114 | + | then throw("wrong status") | |
115 | + | else if (if ((vote != FEATURED)) | |
116 | + | then (vote != DELISTED) | |
117 | + | else false) | |
118 | + | then throw("wrong vote") | |
119 | + | else if (if ((status == FEATURED)) | |
120 | + | then true | |
121 | + | else (status == DELISTED)) | |
122 | + | then throw("vote has finished") | |
123 | + | else WriteSet([DataEntry(getKeyReveal(item, user), vote), DataEntry(getKeyVoteCount(item, vote), newVoteCount), DataEntry(getKeyItemStatus(item), if ((newVoteCount >= QUORUM)) | |
124 | + | then vote | |
125 | + | else REVEAL)]) | |
118 | 126 | } | |
119 | 127 | ||
120 | 128 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let NONE = "none" | |
5 | 5 | ||
6 | 6 | let VOTERS = 3 | |
7 | 7 | ||
8 | 8 | let QUORUM = 2 | |
9 | 9 | ||
10 | 10 | let VOTING = "voting" | |
11 | 11 | ||
12 | 12 | let REVEAL = "reveal" | |
13 | 13 | ||
14 | 14 | let FEATURED = "featured" | |
15 | 15 | ||
16 | 16 | let DELISTED = "delisted" | |
17 | 17 | ||
18 | 18 | func getStrByKey (key) = { | |
19 | 19 | let str = match getString(this, key) { | |
20 | 20 | case a: String => | |
21 | 21 | a | |
22 | 22 | case _ => | |
23 | 23 | NONE | |
24 | 24 | } | |
25 | 25 | str | |
26 | 26 | } | |
27 | 27 | ||
28 | 28 | ||
29 | 29 | func getNumberByKey (key) = { | |
30 | 30 | let num = match getInteger(this, key) { | |
31 | 31 | case a: Int => | |
32 | 32 | a | |
33 | 33 | case _ => | |
34 | 34 | 0 | |
35 | 35 | } | |
36 | 36 | num | |
37 | 37 | } | |
38 | 38 | ||
39 | 39 | ||
40 | 40 | func getKeyCommit (item,user) = (((item + "_") + user) + "_commit") | |
41 | 41 | ||
42 | 42 | ||
43 | 43 | func getValueCommit (item,user) = getStrByKey(getKeyCommit(item, user)) | |
44 | 44 | ||
45 | 45 | ||
46 | 46 | func getKeyCommitsCount (item) = (item + "_comcnt") | |
47 | 47 | ||
48 | 48 | ||
49 | 49 | func getValueCommitsCount (item) = getNumberByKey(getKeyCommitsCount(item)) | |
50 | 50 | ||
51 | 51 | ||
52 | 52 | func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal") | |
53 | 53 | ||
54 | 54 | ||
55 | 55 | func getValueReveal (item,user) = getStrByKey(getKeyReveal(item, user)) | |
56 | 56 | ||
57 | 57 | ||
58 | 58 | func getKeyItemStatus (item) = (item + "_status") | |
59 | 59 | ||
60 | 60 | ||
61 | 61 | func getValueItemStatus (item) = getStrByKey(getKeyItemStatus(item)) | |
62 | 62 | ||
63 | 63 | ||
64 | 64 | func getKeyVoteCount (item,vote) = ((item + "_res:") + vote) | |
65 | 65 | ||
66 | 66 | ||
67 | 67 | func getValueVoteCount (item,vote) = getNumberByKey(getKeyVoteCount(item, vote)) | |
68 | 68 | ||
69 | 69 | ||
70 | 70 | func getKeyItemPrice (item) = (item + "_price") | |
71 | 71 | ||
72 | 72 | ||
73 | 73 | func getKeyItemData (item) = (item + "_data") | |
74 | 74 | ||
75 | 75 | ||
76 | 76 | func getKeyItemSupp (item) = (item + "_owner") | |
77 | 77 | ||
78 | 78 | ||
79 | 79 | func getKeyItem (supp,title) = ("item_" + toBase58String(sha256(toBytes((supp + title))))) | |
80 | 80 | ||
81 | 81 | ||
82 | 82 | func getValueItemSupp (item) = getStrByKey(getKeyItemSupp(item)) | |
83 | 83 | ||
84 | 84 | ||
85 | 85 | func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item)) | |
86 | 86 | ||
87 | 87 | ||
88 | 88 | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt") | |
89 | 89 | ||
90 | 90 | ||
91 | 91 | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) | |
92 | 92 | ||
93 | 93 | ||
94 | 94 | func getKeySuppBalance (supp) = (supp + "_balance") | |
95 | 95 | ||
96 | 96 | ||
97 | 97 | func getValueSuppBalance (supp) = getNumberByKey(getKeySuppBalance(supp)) | |
98 | 98 | ||
99 | 99 | ||
100 | 100 | @Callable(i) | |
101 | - | func | |
101 | + | func voteReveal (item,vote,salt) = { | |
102 | 102 | let user = toBase58String(i.caller.bytes) | |
103 | - | let commits = getValueCommitsCount(item) | |
104 | 103 | let status = getValueItemStatus(item) | |
105 | - | if ((commits >= VOTERS)) | |
106 | - | then throw("reahced max voters") | |
107 | - | else if ((getValueCommit(item, user) != NONE)) | |
108 | - | then throw("user already voted") | |
109 | - | else if ((getKeyItemSupp(item) == NONE)) | |
110 | - | then throw("item does not exist") | |
111 | - | else if (if ((status != NONE)) | |
112 | - | then (status != VOTING) | |
104 | + | let newVoteCount = (getValueVoteCount(item, vote) + 1) | |
105 | + | if ((toBase58String(sha256(toBytes((vote + salt)))) != getValueCommit(item, user))) | |
106 | + | then throw("reveal data is not valid") | |
107 | + | else if ((VOTERS > getValueCommitsCount(item))) | |
108 | + | then throw("max num of votes hasn't reached yet") | |
109 | + | else if ((getValueReveal(item, user) != NONE)) | |
110 | + | then throw("user has already participated") | |
111 | + | else if (if ((status != VOTING)) | |
112 | + | then (status != REVEAL) | |
113 | 113 | else false) | |
114 | - | then throw("vote is not possible") | |
115 | - | else WriteSet([DataEntry(getKeyCommit(item, user), hash), DataEntry(getKeyCommitsCount(item), (commits + 1)), DataEntry(getKeyItemStatus(item), if ((commits == VOTERS)) | |
116 | - | then REVEAL | |
117 | - | else VOTING)]) | |
114 | + | then throw("wrong status") | |
115 | + | else if (if ((vote != FEATURED)) | |
116 | + | then (vote != DELISTED) | |
117 | + | else false) | |
118 | + | then throw("wrong vote") | |
119 | + | else if (if ((status == FEATURED)) | |
120 | + | then true | |
121 | + | else (status == DELISTED)) | |
122 | + | then throw("vote has finished") | |
123 | + | else WriteSet([DataEntry(getKeyReveal(item, user), vote), DataEntry(getKeyVoteCount(item, vote), newVoteCount), DataEntry(getKeyItemStatus(item), if ((newVoteCount >= QUORUM)) | |
124 | + | then vote | |
125 | + | else REVEAL)]) | |
118 | 126 | } | |
119 | 127 | ||
120 | 128 |
github/deemru/w8io/169f3d6 37.15 ms ◑