tx · 8jmkyYve2ey2uqgxv62N2sSstm4jUoBKbW8Pthdjgeqd 3MtTheYx7F8GojnQXdBq5njwKSWwWDR8Yx3: -0.01400000 Waves 2020.11.23 12:40 [1277863] smart account 3MtTheYx7F8GojnQXdBq5njwKSWwWDR8Yx3 > SELF 0.00000000 Waves
{ "type": 13, "id": "8jmkyYve2ey2uqgxv62N2sSstm4jUoBKbW8Pthdjgeqd", "fee": 1400000, "feeAssetId": null, "timestamp": 1606124418281, "version": 2, "chainId": 84, "sender": "3MtTheYx7F8GojnQXdBq5njwKSWwWDR8Yx3", "senderPublicKey": "24o2mnMP6y64dijDFoZKhDpV73e1gCFKxQcZ6X9q3z1B", "proofs": [ "4DNZQ5AchL54kKqP4xG2NZSXeVxGx8GYFWjo7oHg3yyPQUrJHkp51dmEYbnDD8E57FuAb85fiHwKe1a3bhER1BEH" ], "script": "base64:AAIEAAAAAAAAABYIAhIDCgEIEgUKAwgBCBIAEgQKAggIAAAAIAAAAAARYWNjb3VudDFQdWJsaWNLZXkBAAAAIPeNeDDs4TWVhR1bzOk94lFsHOraL9B/FRj0XfVMj0hOAAAAABFhY2NvdW50MlB1YmxpY0tleQEAAAAgG1e/aEwKrtMkcq9WyiLLAHtKPJgLd/oAoUXcKuUDIhUAAAAADm90aGVyUHVibGljS2V5AQAAACDnblGJprjxGAm9jEz8V5M0TOEG6bhNvbMQquBNrx0dWgAAAAAETk9ORQIAAAAEbm9uZQAAAAAGVk9URVJTAAAAAAAAAAADAAAAAAZRVU9SVU0AAAAAAAAAAAIAAAAABlZPVElORwIAAAAGdm90aW5nAAAAAAZSRVZFQUwCAAAABnJldmVhbAAAAAAIRkVBVFVSRUQCAAAACGZlYXR1cmVkAAAAAAhERUxJU1RFRAIAAAAIZGVsaXN0ZWQBAAAADmdldE51bWJlckJ5S2V5AAAAAQAAAANrZXkEAAAAA251bQQAAAAHJG1hdGNoMAkABBoAAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtY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VElORwUAAAADbmlsAAAAAQAAAAJ0eAEAAAAGdmVyaWZ5AAAAAAZnX9N8", "height": 1277863, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 55hNEsKebyqGS8vCw8oeiuQCqf4PRUB5yBvh7WwQxZQG Next: 7XpYiUDLYrdNCBVLJUF7udpMq3jKJdEvvmjxfhmrCnRv Diff:
Old | New | Differences | |
---|---|---|---|
8 | 8 | let otherPublicKey = base58'GaQkBG6yLLAarb8wvPrEKnQhFqWomD2ZGT1T4vVx24qw' | |
9 | 9 | ||
10 | 10 | let NONE = "none" | |
11 | + | ||
12 | + | let VOTERS = 3 | |
13 | + | ||
14 | + | let QUORUM = 2 | |
15 | + | ||
16 | + | let VOTING = "voting" | |
17 | + | ||
18 | + | let REVEAL = "reveal" | |
19 | + | ||
20 | + | let FEATURED = "featured" | |
21 | + | ||
22 | + | let DELISTED = "delisted" | |
11 | 23 | ||
12 | 24 | func getNumberByKey (key) = { | |
13 | 25 | let num = match getInteger(this, key) { | |
61 | 73 | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
62 | 74 | ||
63 | 75 | ||
76 | + | func getKeyCommit (item,user) = (((item + "_") + user) + "_commit") | |
77 | + | ||
78 | + | ||
79 | + | func getValueCommit (item,user) = getStrByKey(getKeyCommit(item, user)) | |
80 | + | ||
81 | + | ||
82 | + | func getKeyCommitsCount (item) = (item + "_comcnt") | |
83 | + | ||
84 | + | ||
85 | + | func getValueCommitsCount (item) = getNumberByKey(getKeyCommitsCount(item)) | |
86 | + | ||
87 | + | ||
88 | + | func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal") | |
89 | + | ||
90 | + | ||
91 | + | func getValueReveal (item,user) = getStrByKey(getKeyReveal(item, user)) | |
92 | + | ||
93 | + | ||
94 | + | func getKeyItemStatus (item) = (item + "_status") | |
95 | + | ||
96 | + | ||
97 | + | func getValueItemStatus (item) = getStrByKey(getKeyItemStatus(item)) | |
98 | + | ||
99 | + | ||
100 | + | func getKeyVoteCount (item,vote) = ((item + "_res:") + vote) | |
101 | + | ||
102 | + | ||
103 | + | func getValueVoteCount (item,vote) = getNumberByKey(getKeyVoteCount(item, vote)) | |
104 | + | ||
105 | + | ||
64 | 106 | @Callable(i) | |
65 | 107 | func purchase (item) = { | |
66 | 108 | let pmt = value(i.payments) | |
107 | 149 | } | |
108 | 150 | ||
109 | 151 | ||
152 | + | ||
153 | + | @Callable(i) | |
154 | + | func voteCommit (item,hash) = { | |
155 | + | let user = toBase58String(i.caller.bytes) | |
156 | + | let commits = getValueCommitsCount(item) | |
157 | + | let status = getValueItemStatus(item) | |
158 | + | if ((commits >= VOTERS)) | |
159 | + | then throw("reached max num of voters") | |
160 | + | else if ((getValueCommit(item, user) != NONE)) | |
161 | + | then throw("user has already participated") | |
162 | + | else if ((getKeyItemSupplier(item) == NONE)) | |
163 | + | then throw("item does not exist") | |
164 | + | else if (if ((status != NONE)) | |
165 | + | then (status != VOTING) | |
166 | + | else false) | |
167 | + | then throw("voting is not possible") | |
168 | + | else [StringEntry(getKeyCommit(item, user), hash), IntegerEntry(getKeyCommitsCount(item), (commits + 1)), StringEntry(getKeyItemStatus(item), if ((commits == VOTERS)) | |
169 | + | then REVEAL | |
170 | + | else VOTING)] | |
171 | + | } | |
172 | + | ||
173 | + | ||
110 | 174 | @Verifier(tx) | |
111 | 175 | func verify () = true | |
112 | 176 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 4 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let account1PublicKey = base58'HfLpRhXtnuCabRyNT6z7soaXcbUpwLUhjyBCVQ4szwzd' | |
5 | 5 | ||
6 | 6 | let account2PublicKey = base58'2qjcWuL7QitmuhkSTM7CnNxurCYXuqJ9ubswLBGmXfDv' | |
7 | 7 | ||
8 | 8 | let otherPublicKey = base58'GaQkBG6yLLAarb8wvPrEKnQhFqWomD2ZGT1T4vVx24qw' | |
9 | 9 | ||
10 | 10 | let NONE = "none" | |
11 | + | ||
12 | + | let VOTERS = 3 | |
13 | + | ||
14 | + | let QUORUM = 2 | |
15 | + | ||
16 | + | let VOTING = "voting" | |
17 | + | ||
18 | + | let REVEAL = "reveal" | |
19 | + | ||
20 | + | let FEATURED = "featured" | |
21 | + | ||
22 | + | let DELISTED = "delisted" | |
11 | 23 | ||
12 | 24 | func getNumberByKey (key) = { | |
13 | 25 | let num = match getInteger(this, key) { | |
14 | 26 | case a: Int => | |
15 | 27 | a | |
16 | 28 | case _ => | |
17 | 29 | 0 | |
18 | 30 | } | |
19 | 31 | num | |
20 | 32 | } | |
21 | 33 | ||
22 | 34 | ||
23 | 35 | func getStrByKey (key) = { | |
24 | 36 | let str = match getString(this, key) { | |
25 | 37 | case a: String => | |
26 | 38 | a | |
27 | 39 | case _ => | |
28 | 40 | NONE | |
29 | 41 | } | |
30 | 42 | str | |
31 | 43 | } | |
32 | 44 | ||
33 | 45 | ||
34 | 46 | func getKeyItemPrice (item) = (item + "_price") | |
35 | 47 | ||
36 | 48 | ||
37 | 49 | func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item)) | |
38 | 50 | ||
39 | 51 | ||
40 | 52 | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt") | |
41 | 53 | ||
42 | 54 | ||
43 | 55 | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) | |
44 | 56 | ||
45 | 57 | ||
46 | 58 | func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title))))) | |
47 | 59 | ||
48 | 60 | ||
49 | 61 | func getKeyItemData (item) = (item + "_data") | |
50 | 62 | ||
51 | 63 | ||
52 | 64 | func getKeyItemSupplier (item) = (item + "_owner") | |
53 | 65 | ||
54 | 66 | ||
55 | 67 | func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item)) | |
56 | 68 | ||
57 | 69 | ||
58 | 70 | func getKeyBalanceSupplier (account) = (account + "_balance") | |
59 | 71 | ||
60 | 72 | ||
61 | 73 | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
62 | 74 | ||
63 | 75 | ||
76 | + | func getKeyCommit (item,user) = (((item + "_") + user) + "_commit") | |
77 | + | ||
78 | + | ||
79 | + | func getValueCommit (item,user) = getStrByKey(getKeyCommit(item, user)) | |
80 | + | ||
81 | + | ||
82 | + | func getKeyCommitsCount (item) = (item + "_comcnt") | |
83 | + | ||
84 | + | ||
85 | + | func getValueCommitsCount (item) = getNumberByKey(getKeyCommitsCount(item)) | |
86 | + | ||
87 | + | ||
88 | + | func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal") | |
89 | + | ||
90 | + | ||
91 | + | func getValueReveal (item,user) = getStrByKey(getKeyReveal(item, user)) | |
92 | + | ||
93 | + | ||
94 | + | func getKeyItemStatus (item) = (item + "_status") | |
95 | + | ||
96 | + | ||
97 | + | func getValueItemStatus (item) = getStrByKey(getKeyItemStatus(item)) | |
98 | + | ||
99 | + | ||
100 | + | func getKeyVoteCount (item,vote) = ((item + "_res:") + vote) | |
101 | + | ||
102 | + | ||
103 | + | func getValueVoteCount (item,vote) = getNumberByKey(getKeyVoteCount(item, vote)) | |
104 | + | ||
105 | + | ||
64 | 106 | @Callable(i) | |
65 | 107 | func purchase (item) = { | |
66 | 108 | let pmt = value(i.payments) | |
67 | 109 | if (isDefined(pmt[0].assetId)) | |
68 | 110 | then throw("WAVES tokens only") | |
69 | 111 | else { | |
70 | 112 | let userAddress = toBase58String(i.caller.bytes) | |
71 | 113 | let price = getValueItemPrice(item) | |
72 | 114 | let supplierAddress = getValueItemSupplier(item) | |
73 | 115 | if ((price > pmt[0].amount)) | |
74 | 116 | then throw("purchase less than item price") | |
75 | 117 | else if ((pmt[0].amount > price)) | |
76 | 118 | then throw("purchase amount higher than item price") | |
77 | 119 | else if ((size(pmt) > 1)) | |
78 | 120 | then throw("single item only") | |
79 | 121 | else if ((supplierAddress == NONE)) | |
80 | 122 | then throw("supplier doesn't exist") | |
81 | 123 | else [IntegerEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), IntegerEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt[0].amount))] | |
82 | 124 | } | |
83 | 125 | } | |
84 | 126 | ||
85 | 127 | ||
86 | 128 | ||
87 | 129 | @Callable(i) | |
88 | 130 | func addItem (title,price,data) = { | |
89 | 131 | let supplierAddress = toBase58String(i.caller.bytes) | |
90 | 132 | let item = getKeyItem(supplierAddress, title) | |
91 | 133 | if ((0 >= price)) | |
92 | 134 | then throw("purchase amount cannot be less than item price") | |
93 | 135 | else if ((getValueItemSupplier(item) != NONE)) | |
94 | 136 | then throw("an item already exist") | |
95 | 137 | else [StringEntry(getKeyItemSupplier(item), supplierAddress), IntegerEntry(getKeyItemPrice(item), price), StringEntry(getKeyItemData(item), data)] | |
96 | 138 | } | |
97 | 139 | ||
98 | 140 | ||
99 | 141 | ||
100 | 142 | @Callable(i) | |
101 | 143 | func withdraw () = { | |
102 | 144 | let supplierAddress = toBase58String(i.caller.bytes) | |
103 | 145 | let balance = getValueBalanceSupplier(supplierAddress) | |
104 | 146 | if ((0 >= balance)) | |
105 | 147 | then throw("insufficient balance") | |
106 | 148 | else [IntegerEntry(getKeyBalanceSupplier(supplierAddress), 0), ScriptTransfer(addressFromStringValue(supplierAddress), balance, unit)] | |
107 | 149 | } | |
108 | 150 | ||
109 | 151 | ||
152 | + | ||
153 | + | @Callable(i) | |
154 | + | func voteCommit (item,hash) = { | |
155 | + | let user = toBase58String(i.caller.bytes) | |
156 | + | let commits = getValueCommitsCount(item) | |
157 | + | let status = getValueItemStatus(item) | |
158 | + | if ((commits >= VOTERS)) | |
159 | + | then throw("reached max num of voters") | |
160 | + | else if ((getValueCommit(item, user) != NONE)) | |
161 | + | then throw("user has already participated") | |
162 | + | else if ((getKeyItemSupplier(item) == NONE)) | |
163 | + | then throw("item does not exist") | |
164 | + | else if (if ((status != NONE)) | |
165 | + | then (status != VOTING) | |
166 | + | else false) | |
167 | + | then throw("voting is not possible") | |
168 | + | else [StringEntry(getKeyCommit(item, user), hash), IntegerEntry(getKeyCommitsCount(item), (commits + 1)), StringEntry(getKeyItemStatus(item), if ((commits == VOTERS)) | |
169 | + | then REVEAL | |
170 | + | else VOTING)] | |
171 | + | } | |
172 | + | ||
173 | + | ||
110 | 174 | @Verifier(tx) | |
111 | 175 | func verify () = true | |
112 | 176 |
github/deemru/w8io/169f3d6 29.80 ms ◑