tx · 6XrBMkW3qGNtboWKiRPah4igymgyYB1ryPzCbBUYiSJr 3N7F9XheSTc6k2vUnsjVCsFindHj81HmxfA: -0.01000010 Waves 2021.07.21 16:12 [1623425] smart account 3N7F9XheSTc6k2vUnsjVCsFindHj81HmxfA > SELF 0.00000000 Waves
{ "type": 13, "id": "6XrBMkW3qGNtboWKiRPah4igymgyYB1ryPzCbBUYiSJr", "fee": 1000010, "feeAssetId": null, "timestamp": 1626873155354, "version": 2, "chainId": 84, "sender": "3N7F9XheSTc6k2vUnsjVCsFindHj81HmxfA", "senderPublicKey": "4qepWZQYcT9hermD7tjKav2Subii1HMGQ3EhqpyPL7KJ", "proofs": [ "5JRjr9uCDA3ny8QRAQ1wed2pnCaFqtKwtHPkyhqorYQdW4x7W7qa33QGTvXefN2K7bSJ8nnrEGggmLNTPcd4r5dw" ], "script": "base64:AAIFAAAAAAAAAA8IAhIECgIICBIFCgMICAgAAAAUAAAAAAZWT1RFUlMAAAAAAAAAAAMAAAAABlFVT1JVTQAAAAAAAAAAAgAAAAAGVk9USU5HAgAAAAZ2b3RpbmcAAAAABlJFVkVBTAIAAAAGcmV2ZWFsAAAAAAhGRUFUVVJFRAIAAAAIZmVhdHVyZWQAAAAACERFTElTVEVEAgAAAAhkZWxpc3RlZAAAAAAETk9ORQIAAAAEbm9uZQEAAAAOZ2V0TnVtYmVyQnlLZXkAAAABAAAAA2tleQQAAAADbnVtBAAAAAckbWF0Y2gwCQAEGgAAAAIFAAAABHRoaXMFAAAAA2tleQMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAADSW50BAAAAAFhBQAAAAckbWF0Y2gwBQAAAAFhAAAAAAAAAAAABQAAAANudW0BAAAAC2dldFN0ckJ5S2V5AAAAAQAAAANrZXkEAAAAA3N0cgQAAAAHJG1hdGNoMAkABB0AAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAABlN0cmluZwQAAAABYQUAAAAHJG1hdGNoMAUAAAAB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AAAROT05FCQAAAgAAAAECAAAAHXVzZXIgaGFzIGFscmVhZHkgcGFydGljaXBhdGVkAwMJAQAAAAIhPQAAAAIFAAAABnN0YXR1cwUAAAAGVk9USU5HCQEAAAACIT0AAAACBQAAAAZzdGF0dXMFAAAABlJFVkVBTAcJAAACAAAAAQIAAAAMd3Jvbmcgc3RhdHVzAwMJAQAAAAIhPQAAAAIFAAAABHZvdGUFAAAACEZFQVRVUkVECQEAAAACIT0AAAACBQAAAAR2b3RlBQAAAAhERUxJU1RFRAcJAAACAAAAAQIAAAARdm90ZSBoYXMgZmluaXNoZWQJAARMAAAAAgkBAAAAC1N0cmluZ0VudHJ5AAAAAgkBAAAADGdldEtleVJldmVhbAAAAAIFAAAABGl0ZW0FAAAABHVzZXIFAAAABHZvdGUJAARMAAAAAgkBAAAADEludGVnZXJFbnRyeQAAAAIJAQAAAA9nZXRLZXlWb3RlQ291bnQAAAACBQAAAARpdGVtBQAAAAR2b3RlBQAAAAxuZXdWb3RlQ291bnQJAARMAAAAAgkBAAAAC1N0cmluZ0VudHJ5AAAAAgkBAAAAEGdldEtleUl0ZW1TdGF0dXMAAAABBQAAAARpdGVtAwkAAGcAAAACBQAAAAxuZXdWb3RlQ291bnQFAAAABlFVT1JVTQUAAAAEdm90ZQUAAAAGUkVWRUFMBQAAAANuaWwAAAAAO/VmGg==", "height": 1623425, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: FtEJZ8fwGtH5vsrm2ukBvT5yr7qsSUT2VN3wCWKVKqXb Next: none Diff:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | + | let VOTERS = 3 | |
5 | + | ||
6 | + | let QUORUM = 2 | |
7 | + | ||
8 | + | let VOTING = "voting" | |
9 | + | ||
10 | + | let REVEAL = "reveal" | |
11 | + | ||
12 | + | let FEATURED = "featured" | |
13 | + | ||
14 | + | let DELISTED = "delisted" | |
15 | + | ||
4 | 16 | let NONE = "none" | |
5 | 17 | ||
6 | 18 | func getNumberByKey (key) = { | |
25 | 37 | } | |
26 | 38 | ||
27 | 39 | ||
28 | - | func getKeyItemPrice (item) = (item + "_price") | |
29 | - | ||
30 | - | ||
31 | - | func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item)) | |
32 | - | ||
33 | - | ||
34 | - | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt") | |
35 | - | ||
36 | - | ||
37 | - | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) | |
38 | - | ||
39 | - | ||
40 | - | func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title))))) | |
41 | - | ||
42 | - | ||
43 | - | func getKeyItemData (item) = (item + "_data") | |
44 | - | ||
45 | - | ||
46 | 40 | func getKeyItemSupplier (item) = (item + "_data") | |
47 | 41 | ||
48 | 42 | ||
49 | - | func | |
43 | + | func getKeyCommit (item,user) = (((item + "_") + user) + "_commit") | |
50 | 44 | ||
51 | 45 | ||
52 | - | func | |
46 | + | func getValueCommit (item,user) = getStrByKey(getKeyCommit(item, user)) | |
53 | 47 | ||
54 | 48 | ||
55 | - | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
49 | + | func getKeyCommitsCount (item) = (item + "_comcnt") | |
50 | + | ||
51 | + | ||
52 | + | func getValueCommitsCount (item) = getNumberByKey(getKeyCommitsCount(item)) | |
53 | + | ||
54 | + | ||
55 | + | func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal") | |
56 | + | ||
57 | + | ||
58 | + | func getValueReveal (item,user) = getStrByKey(getKeyReveal(item, user)) | |
59 | + | ||
60 | + | ||
61 | + | func getKeyItemStatus (item) = (item + "_status") | |
62 | + | ||
63 | + | ||
64 | + | func getValueItemStatus (item) = getStrByKey(getKeyItemStatus(item)) | |
65 | + | ||
66 | + | ||
67 | + | func getKeyVoteCount (item,vote) = ((item + "_res:") + vote) | |
68 | + | ||
69 | + | ||
70 | + | func getValueVoteCount (item,vote) = getNumberByKey(getKeyVoteCount(item, vote)) | |
56 | 71 | ||
57 | 72 | ||
58 | 73 | @Callable(i) | |
59 | - | func addItem (title,price,data) = { | |
60 | - | let supplierAddress = toBase58String(i.caller.bytes) | |
61 | - | let item = getKeyItem(supplierAddress, title) | |
62 | - | if ((0 >= price)) | |
63 | - | then throw("purchase amount cannot be less than item price") | |
64 | - | else if ((getValueItemSupplier(item) != NONE)) | |
65 | - | then throw("an item is already exist") | |
66 | - | else [StringEntry(getKeyItemSupplier(item), supplierAddress), IntegerEntry(getKeyItemPrice(item), price), StringEntry(getKeyItemData(item), data)] | |
74 | + | func voteCommit (item,hash) = { | |
75 | + | let user = toBase58String(i.caller.bytes) | |
76 | + | let commits = getValueCommitsCount(item) | |
77 | + | let status = getValueItemStatus(item) | |
78 | + | if ((commits >= VOTERS)) | |
79 | + | then throw("osiągnięto maksymaną liczbę głosujących") | |
80 | + | else if ((getValueCommit(item, user) != NONE)) | |
81 | + | then throw("użtykownik już głosuje") | |
82 | + | else if ((getKeyItemSupplier(item) == NONE)) | |
83 | + | then throw("nie istnieje taki przedmiot") | |
84 | + | else if (if ((status != NONE)) | |
85 | + | then (status != VOTING) | |
86 | + | else false) | |
87 | + | then throw("głosowanie nie jest możliwe") | |
88 | + | else [StringEntry(getKeyCommit(item, user), hash), IntegerEntry(getKeyCommitsCount(item), (commits + 1)), StringEntry(getKeyItemStatus(item), if ((commits == VOTERS)) | |
89 | + | then REVEAL | |
90 | + | else VOTING)] | |
67 | 91 | } | |
68 | 92 | ||
69 | 93 | ||
70 | 94 | ||
71 | 95 | @Callable(i) | |
72 | - | func purchase (item) = { | |
73 | - | let pmt = i.payments[0] | |
74 | - | if (isDefined(pmt.assetId)) | |
75 | - | then throw("WAVES token only at the moment") | |
76 | - | else { | |
77 | - | let userAddress = toBase58String(i.caller.bytes) | |
78 | - | let price = getValueItemPrice(item) | |
79 | - | let supplierAddres = getValueItemSupplier(item) | |
80 | - | if ((price > pmt.amount)) | |
81 | - | then throw("purchase amunt cannot be less than item price") | |
82 | - | else if ((pmt.amount > price)) | |
83 | - | then throw("purchase amount cannot be higher than item price") | |
84 | - | else if ((supplierAddres == NONE)) | |
85 | - | then throw("Supplier address doesn't exist") | |
86 | - | else [IntegerEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), IntegerEntry(getKeyBalanceSupplier(supplierAddres), (getValueBalanceSupplier(supplierAddres) + pmt.amount))] | |
87 | - | } | |
88 | - | } | |
89 | - | ||
90 | - | ||
91 | - | ||
92 | - | @Callable(i) | |
93 | - | func withdraw () = { | |
94 | - | let supplierAddress = toBase58String(i.caller.bytes) | |
95 | - | let balance = getValueBalanceSupplier(supplierAddress) | |
96 | - | if ((0 >= balance)) | |
97 | - | then throw("za mało środków") | |
98 | - | else [IntegerEntry(getKeyBalanceSupplier(supplierAddress), 0), ScriptTransfer(addressFromStringValue(supplierAddress), balance, unit)] | |
96 | + | func voteReveal (item,vote,salt) = { | |
97 | + | let user = toBase58String(i.caller.bytes) | |
98 | + | let status = getValueItemStatus(item) | |
99 | + | let newVoteCount = (getValueVoteCount(item, vote) + 1) | |
100 | + | if ((toBase58String(sha256(toBytes((vote + salt)))) != getValueCommit(item, user))) | |
101 | + | then throw("reveal data is not valid") | |
102 | + | else if ((VOTERS > getValueCommitsCount(item))) | |
103 | + | then throw("max number of voters hasn't reached yet") | |
104 | + | else if ((getValueReveal(item, user) != NONE)) | |
105 | + | then throw("user has already participated") | |
106 | + | else if (if ((status != VOTING)) | |
107 | + | then (status != REVEAL) | |
108 | + | else false) | |
109 | + | then throw("wrong status") | |
110 | + | else if (if ((vote != FEATURED)) | |
111 | + | then (vote != DELISTED) | |
112 | + | else false) | |
113 | + | then throw("vote has finished") | |
114 | + | else [StringEntry(getKeyReveal(item, user), vote), IntegerEntry(getKeyVoteCount(item, vote), newVoteCount), StringEntry(getKeyItemStatus(item), if ((newVoteCount >= QUORUM)) | |
115 | + | then vote | |
116 | + | else REVEAL)] | |
99 | 117 | } | |
100 | 118 | ||
101 | 119 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | + | let VOTERS = 3 | |
5 | + | ||
6 | + | let QUORUM = 2 | |
7 | + | ||
8 | + | let VOTING = "voting" | |
9 | + | ||
10 | + | let REVEAL = "reveal" | |
11 | + | ||
12 | + | let FEATURED = "featured" | |
13 | + | ||
14 | + | let DELISTED = "delisted" | |
15 | + | ||
4 | 16 | let NONE = "none" | |
5 | 17 | ||
6 | 18 | func getNumberByKey (key) = { | |
7 | 19 | let num = match getInteger(this, key) { | |
8 | 20 | case a: Int => | |
9 | 21 | a | |
10 | 22 | case _ => | |
11 | 23 | 0 | |
12 | 24 | } | |
13 | 25 | num | |
14 | 26 | } | |
15 | 27 | ||
16 | 28 | ||
17 | 29 | func getStrByKey (key) = { | |
18 | 30 | let str = match getString(this, key) { | |
19 | 31 | case a: String => | |
20 | 32 | a | |
21 | 33 | case _ => | |
22 | 34 | NONE | |
23 | 35 | } | |
24 | 36 | str | |
25 | 37 | } | |
26 | 38 | ||
27 | 39 | ||
28 | - | func getKeyItemPrice (item) = (item + "_price") | |
29 | - | ||
30 | - | ||
31 | - | func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item)) | |
32 | - | ||
33 | - | ||
34 | - | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt") | |
35 | - | ||
36 | - | ||
37 | - | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) | |
38 | - | ||
39 | - | ||
40 | - | func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title))))) | |
41 | - | ||
42 | - | ||
43 | - | func getKeyItemData (item) = (item + "_data") | |
44 | - | ||
45 | - | ||
46 | 40 | func getKeyItemSupplier (item) = (item + "_data") | |
47 | 41 | ||
48 | 42 | ||
49 | - | func | |
43 | + | func getKeyCommit (item,user) = (((item + "_") + user) + "_commit") | |
50 | 44 | ||
51 | 45 | ||
52 | - | func | |
46 | + | func getValueCommit (item,user) = getStrByKey(getKeyCommit(item, user)) | |
53 | 47 | ||
54 | 48 | ||
55 | - | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
49 | + | func getKeyCommitsCount (item) = (item + "_comcnt") | |
50 | + | ||
51 | + | ||
52 | + | func getValueCommitsCount (item) = getNumberByKey(getKeyCommitsCount(item)) | |
53 | + | ||
54 | + | ||
55 | + | func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal") | |
56 | + | ||
57 | + | ||
58 | + | func getValueReveal (item,user) = getStrByKey(getKeyReveal(item, user)) | |
59 | + | ||
60 | + | ||
61 | + | func getKeyItemStatus (item) = (item + "_status") | |
62 | + | ||
63 | + | ||
64 | + | func getValueItemStatus (item) = getStrByKey(getKeyItemStatus(item)) | |
65 | + | ||
66 | + | ||
67 | + | func getKeyVoteCount (item,vote) = ((item + "_res:") + vote) | |
68 | + | ||
69 | + | ||
70 | + | func getValueVoteCount (item,vote) = getNumberByKey(getKeyVoteCount(item, vote)) | |
56 | 71 | ||
57 | 72 | ||
58 | 73 | @Callable(i) | |
59 | - | func addItem (title,price,data) = { | |
60 | - | let supplierAddress = toBase58String(i.caller.bytes) | |
61 | - | let item = getKeyItem(supplierAddress, title) | |
62 | - | if ((0 >= price)) | |
63 | - | then throw("purchase amount cannot be less than item price") | |
64 | - | else if ((getValueItemSupplier(item) != NONE)) | |
65 | - | then throw("an item is already exist") | |
66 | - | else [StringEntry(getKeyItemSupplier(item), supplierAddress), IntegerEntry(getKeyItemPrice(item), price), StringEntry(getKeyItemData(item), data)] | |
74 | + | func voteCommit (item,hash) = { | |
75 | + | let user = toBase58String(i.caller.bytes) | |
76 | + | let commits = getValueCommitsCount(item) | |
77 | + | let status = getValueItemStatus(item) | |
78 | + | if ((commits >= VOTERS)) | |
79 | + | then throw("osiągnięto maksymaną liczbę głosujących") | |
80 | + | else if ((getValueCommit(item, user) != NONE)) | |
81 | + | then throw("użtykownik już głosuje") | |
82 | + | else if ((getKeyItemSupplier(item) == NONE)) | |
83 | + | then throw("nie istnieje taki przedmiot") | |
84 | + | else if (if ((status != NONE)) | |
85 | + | then (status != VOTING) | |
86 | + | else false) | |
87 | + | then throw("głosowanie nie jest możliwe") | |
88 | + | else [StringEntry(getKeyCommit(item, user), hash), IntegerEntry(getKeyCommitsCount(item), (commits + 1)), StringEntry(getKeyItemStatus(item), if ((commits == VOTERS)) | |
89 | + | then REVEAL | |
90 | + | else VOTING)] | |
67 | 91 | } | |
68 | 92 | ||
69 | 93 | ||
70 | 94 | ||
71 | 95 | @Callable(i) | |
72 | - | func purchase (item) = { | |
73 | - | let pmt = i.payments[0] | |
74 | - | if (isDefined(pmt.assetId)) | |
75 | - | then throw("WAVES token only at the moment") | |
76 | - | else { | |
77 | - | let userAddress = toBase58String(i.caller.bytes) | |
78 | - | let price = getValueItemPrice(item) | |
79 | - | let supplierAddres = getValueItemSupplier(item) | |
80 | - | if ((price > pmt.amount)) | |
81 | - | then throw("purchase amunt cannot be less than item price") | |
82 | - | else if ((pmt.amount > price)) | |
83 | - | then throw("purchase amount cannot be higher than item price") | |
84 | - | else if ((supplierAddres == NONE)) | |
85 | - | then throw("Supplier address doesn't exist") | |
86 | - | else [IntegerEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), IntegerEntry(getKeyBalanceSupplier(supplierAddres), (getValueBalanceSupplier(supplierAddres) + pmt.amount))] | |
87 | - | } | |
88 | - | } | |
89 | - | ||
90 | - | ||
91 | - | ||
92 | - | @Callable(i) | |
93 | - | func withdraw () = { | |
94 | - | let supplierAddress = toBase58String(i.caller.bytes) | |
95 | - | let balance = getValueBalanceSupplier(supplierAddress) | |
96 | - | if ((0 >= balance)) | |
97 | - | then throw("za mało środków") | |
98 | - | else [IntegerEntry(getKeyBalanceSupplier(supplierAddress), 0), ScriptTransfer(addressFromStringValue(supplierAddress), balance, unit)] | |
96 | + | func voteReveal (item,vote,salt) = { | |
97 | + | let user = toBase58String(i.caller.bytes) | |
98 | + | let status = getValueItemStatus(item) | |
99 | + | let newVoteCount = (getValueVoteCount(item, vote) + 1) | |
100 | + | if ((toBase58String(sha256(toBytes((vote + salt)))) != getValueCommit(item, user))) | |
101 | + | then throw("reveal data is not valid") | |
102 | + | else if ((VOTERS > getValueCommitsCount(item))) | |
103 | + | then throw("max number of voters hasn't reached yet") | |
104 | + | else if ((getValueReveal(item, user) != NONE)) | |
105 | + | then throw("user has already participated") | |
106 | + | else if (if ((status != VOTING)) | |
107 | + | then (status != REVEAL) | |
108 | + | else false) | |
109 | + | then throw("wrong status") | |
110 | + | else if (if ((vote != FEATURED)) | |
111 | + | then (vote != DELISTED) | |
112 | + | else false) | |
113 | + | then throw("vote has finished") | |
114 | + | else [StringEntry(getKeyReveal(item, user), vote), IntegerEntry(getKeyVoteCount(item, vote), newVoteCount), StringEntry(getKeyItemStatus(item), if ((newVoteCount >= QUORUM)) | |
115 | + | then vote | |
116 | + | else REVEAL)] | |
99 | 117 | } | |
100 | 118 | ||
101 | 119 |
github/deemru/w8io/169f3d6 28.31 ms ◑