tx · 5E3iA3mmGDQhoFLTmV5ChfParNXddyYRwFcU8ji6Pi8K 3Mrik3RqY2jPfkkG7R7UiHLBXGGa3jfMpyT: -0.01400000 Waves 2019.08.28 00:27 [650142] smart account 3Mrik3RqY2jPfkkG7R7UiHLBXGGa3jfMpyT > SELF 0.00000000 Waves
{ "type": 13, "id": "5E3iA3mmGDQhoFLTmV5ChfParNXddyYRwFcU8ji6Pi8K", "fee": 1400000, "feeAssetId": null, "timestamp": 1566941242074, "version": 1, "sender": "3Mrik3RqY2jPfkkG7R7UiHLBXGGa3jfMpyT", "senderPublicKey": "Di8Ucr8vDr6jZNa27iAQxGMYEW9WSuF6MCBaM3fe9coP", "proofs": [ "59JNTQfAGQpDiohuHHMgwuMuZkRLmthJ2Yum2TFZHZ4U6JgXP5qFCN2vQFJnPzE8UHNKJPLk6EAnPYRsKcxErMov" ], "script": "base64:AAIDAAAAAAAAAAAAAAAdAAAAAAROT05FAgAAAARub25lAAAAAAZWT1RFUlMAAAAAAAAAAAMAAAAABlFVT1JVTQAAAAAAAAAAAgAAAAAGVk9USU5HAgAAAAZ2b3RpbmcAAAAABlJFVkVBTAIAAAAGcmV2ZWFsAAAAAAhGRUFUVVJFRAIAAAAIZmVhdHVyZWQAAAAACERFTElTVEVEAgAAAAhkZWxpc3RlZAEAAAAOZ2V0TnVtYmVyQnlLZXkAAAABAAAAA2tleQQAAAADbnVtBAAAAAckbWF0Y2gwCQAEGgAAAAIFAAAABHRoaXMFAAAAA2tleQMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAADSW50BAAAAAFhBQAAAAckbWF0Y2gwBQAAAAFhAAAAAAAAAAAABQAAAANudW0BAAAAC2dldFN0ckJ5S2V5AAAAAQAAAANrZXkEAAAAA3N0cgQAAAAHJG1hdGNoMAkABB0AAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAABlN0cmluZwQAAAABYQUAAAAHJG1hdGNoMAUAAAABYQUAAAAETk9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k9URVJTCQAAAgAAAAECAAAAHHJlYWNoZWQgbWF4IG51bWJlciBvZiB2b3RlcnMDCQEAAAACIT0AAAACCQEAAAAOZ2V0VmFsdWVDb21taXQAAAACBQAAAARpdGVtBQAAAAR1c2VyBQAAAAROT05FCQAAAgAAAAECAAAAHXVzZXIgaGFzIHBhcnRpY2lwYXRlZCBhbHJlYWR5AwkAAAAAAAACCQEAAAASZ2V0S2V5SXRlbVN1cHBsaWVyAAAAAQUAAAAEaXRlbQUAAAAETk9ORQkAAAIAAAABAgAAABNpdGVtIGRvZXNuJ3QgZXhpc3RzAwMJAQAAAAIhPQAAAAIFAAAABnN0YXR1cwUAAAAETk9ORQkBAAAAAiE9AAAAAgUAAAAGc3RhdHVzBQAAAAZWT1RJTkcHCQAAAgAAAAECAAAAFnZvdGluZyBpcyBub3QgcG9zc2libGUJAQAAAAhXcml0ZVNldAAAAAEJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAQAAAAxnZXRLZXlDb21taXQAAAACBQAAAARpdGVtBQAAAAR1c2VyBQAAAARoYXNoCQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACCQEAAAARZ2V0S2V5Q29tbWl0Q291bnQAAAABBQAAAARpdGVtCQAAZAAAAAIFAAAAB2NvbW1pdHMAAAAAAAAAAAEJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAQAAABBnZXRLZXlJdGVtU3RhdHVzAAAAAQUAAAAEaXRlbQMJAAAAAAAAAgUAAAAHY29tbWl0cwkAAGUAAAACBQAAAAZWT1RFUlMAAAAAAAAAAAEFAAAABlJFVkVBTAUAAAAGVk9USU5HBQAAAANuaWwAAAAALK7foQ==", "chainId": 84, "height": 650142, "spentComplexity": 0 } View: original | compacted Prev: 2KTtPtvqHXAVTPviVruN7Qjkc8DkubBjAWKJnM9xb5Ve Next: 8eP6mHWecBPbeTfkeMpKTWCUnK5veAg1z2j1HzbTrFiH Diff:
Old | New | Differences | |
---|---|---|---|
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let NONE = "none" | |
5 | + | ||
6 | + | let VOTERS = 3 | |
7 | + | ||
8 | + | let QUORUM = 2 | |
9 | + | ||
10 | + | let VOTING = "voting" | |
11 | + | ||
12 | + | let REVEAL = "reveal" | |
13 | + | ||
14 | + | let FEATURED = "featured" | |
15 | + | ||
16 | + | let DELISTED = "delisted" | |
5 | 17 | ||
6 | 18 | func getNumberByKey (key) = { | |
7 | 19 | let num = match getInteger(this, key) { | |
43 | 55 | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt") | |
44 | 56 | ||
45 | 57 | ||
58 | + | func getKeyCommit (item,user) = (((item + "_") + user) + "_commit") | |
59 | + | ||
60 | + | ||
61 | + | func getKeyCommitCount (item) = (item + "_comcnt") | |
62 | + | ||
63 | + | ||
64 | + | func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal") | |
65 | + | ||
66 | + | ||
67 | + | func getKeyItemStatus (item) = (item + "_status") | |
68 | + | ||
69 | + | ||
70 | + | func getKeyVoteCount (item,vote) = ((item + "_res:") + vote) | |
71 | + | ||
72 | + | ||
46 | 73 | func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item)) | |
47 | 74 | ||
48 | 75 | ||
53 | 80 | ||
54 | 81 | ||
55 | 82 | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) | |
83 | + | ||
84 | + | ||
85 | + | func getValueCommit (item,user) = getStrByKey(getKeyCommit(item, user)) | |
86 | + | ||
87 | + | ||
88 | + | func getValueCommitCount (item) = getNumberByKey(getKeyCommitCount(item)) | |
89 | + | ||
90 | + | ||
91 | + | func getValueReveal (item,user) = getStrByKey(getKeyReveal(item, user)) | |
92 | + | ||
93 | + | ||
94 | + | func getValueItemStatus (item) = getStrByKey(getKeyItemStatus(item)) | |
95 | + | ||
96 | + | ||
97 | + | func getValueVoteCount (item,vote) = getNumberByKey(getKeyVoteCount(item, vote)) | |
56 | 98 | ||
57 | 99 | ||
58 | 100 | @Callable(i) | |
99 | 141 | } | |
100 | 142 | ||
101 | 143 | ||
144 | + | ||
145 | + | @Callable(i) | |
146 | + | func voteCommit (item,hash) = { | |
147 | + | let user = toBase58String(i.caller.bytes) | |
148 | + | let commits = getValueCommitCount(item) | |
149 | + | let status = getValueItemStatus(item) | |
150 | + | if ((commits == VOTERS)) | |
151 | + | then throw("reached max number of voters") | |
152 | + | else if ((getValueCommit(item, user) != NONE)) | |
153 | + | then throw("user has participated already") | |
154 | + | else if ((getKeyItemSupplier(item) == NONE)) | |
155 | + | then throw("item doesn't exists") | |
156 | + | else if (if ((status != NONE)) | |
157 | + | then (status != VOTING) | |
158 | + | else false) | |
159 | + | then throw("voting is not possible") | |
160 | + | else WriteSet([DataEntry(getKeyCommit(item, user), hash), DataEntry(getKeyCommitCount(item), (commits + 1)), DataEntry(getKeyItemStatus(item), if ((commits == (VOTERS - 1))) | |
161 | + | then REVEAL | |
162 | + | else VOTING)]) | |
163 | + | } | |
164 | + | ||
165 | + |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let NONE = "none" | |
5 | + | ||
6 | + | let VOTERS = 3 | |
7 | + | ||
8 | + | let QUORUM = 2 | |
9 | + | ||
10 | + | let VOTING = "voting" | |
11 | + | ||
12 | + | let REVEAL = "reveal" | |
13 | + | ||
14 | + | let FEATURED = "featured" | |
15 | + | ||
16 | + | let DELISTED = "delisted" | |
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 | 40 | func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title))))) | |
29 | 41 | ||
30 | 42 | ||
31 | 43 | func getKeyItemPrice (item) = (item + "_price") | |
32 | 44 | ||
33 | 45 | ||
34 | 46 | func getKeyItemData (item) = (item + "_data") | |
35 | 47 | ||
36 | 48 | ||
37 | 49 | func getKeyItemSupplier (item) = (item + "_owner") | |
38 | 50 | ||
39 | 51 | ||
40 | 52 | func getKeySupplierBalance (account) = (account + "_balance") | |
41 | 53 | ||
42 | 54 | ||
43 | 55 | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt") | |
44 | 56 | ||
45 | 57 | ||
58 | + | func getKeyCommit (item,user) = (((item + "_") + user) + "_commit") | |
59 | + | ||
60 | + | ||
61 | + | func getKeyCommitCount (item) = (item + "_comcnt") | |
62 | + | ||
63 | + | ||
64 | + | func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal") | |
65 | + | ||
66 | + | ||
67 | + | func getKeyItemStatus (item) = (item + "_status") | |
68 | + | ||
69 | + | ||
70 | + | func getKeyVoteCount (item,vote) = ((item + "_res:") + vote) | |
71 | + | ||
72 | + | ||
46 | 73 | func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item)) | |
47 | 74 | ||
48 | 75 | ||
49 | 76 | func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item)) | |
50 | 77 | ||
51 | 78 | ||
52 | 79 | func getValueSupplierBalance (account) = getNumberByKey(getKeySupplierBalance(account)) | |
53 | 80 | ||
54 | 81 | ||
55 | 82 | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) | |
83 | + | ||
84 | + | ||
85 | + | func getValueCommit (item,user) = getStrByKey(getKeyCommit(item, user)) | |
86 | + | ||
87 | + | ||
88 | + | func getValueCommitCount (item) = getNumberByKey(getKeyCommitCount(item)) | |
89 | + | ||
90 | + | ||
91 | + | func getValueReveal (item,user) = getStrByKey(getKeyReveal(item, user)) | |
92 | + | ||
93 | + | ||
94 | + | func getValueItemStatus (item) = getStrByKey(getKeyItemStatus(item)) | |
95 | + | ||
96 | + | ||
97 | + | func getValueVoteCount (item,vote) = getNumberByKey(getKeyVoteCount(item, vote)) | |
56 | 98 | ||
57 | 99 | ||
58 | 100 | @Callable(i) | |
59 | 101 | func addItem (title,price,data) = { | |
60 | 102 | let supplierAddress = toBase58String(i.caller.bytes) | |
61 | 103 | let item = getKeyItem(supplierAddress, title) | |
62 | 104 | if ((0 >= price)) | |
63 | 105 | then throw("Purchase amount cannot be less than or equal 0") | |
64 | 106 | else if ((getValueItemSupplier(item) != NONE)) | |
65 | 107 | then throw("Item exists already") | |
66 | 108 | else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddress), DataEntry(getKeyItemPrice(item), price), DataEntry(getKeyItemData(item), data)]) | |
67 | 109 | } | |
68 | 110 | ||
69 | 111 | ||
70 | 112 | ||
71 | 113 | @Callable(i) | |
72 | 114 | func purchase (item) = { | |
73 | 115 | let pmt = extract(i.payment) | |
74 | 116 | if (isDefined(pmt.assetId)) | |
75 | 117 | then throw("WAVES only at the moment") | |
76 | 118 | else { | |
77 | 119 | let userAddress = toBase58String(i.caller.bytes) | |
78 | 120 | let price = getValueItemPrice(item) | |
79 | 121 | let supplierAddress = getValueItemSupplier(item) | |
80 | 122 | if ((price > pmt.amount)) | |
81 | 123 | then throw("purchase amount cannot be less than item price") | |
82 | 124 | else if ((pmt.amount > price)) | |
83 | 125 | then throw("purchase amount cannot be higher than item price") | |
84 | 126 | else if ((supplierAddress == NONE)) | |
85 | 127 | then throw("supplier doesn't exists") | |
86 | 128 | else WriteSet([DataEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), DataEntry(getKeySupplierBalance(supplierAddress), (getValueSupplierBalance(supplierAddress) + pmt.amount))]) | |
87 | 129 | } | |
88 | 130 | } | |
89 | 131 | ||
90 | 132 | ||
91 | 133 | ||
92 | 134 | @Callable(i) | |
93 | 135 | func withdraw () = { | |
94 | 136 | let supplierAddress = toBase58String(i.caller.bytes) | |
95 | 137 | let balance = getValueSupplierBalance(supplierAddress) | |
96 | 138 | if ((0 >= balance)) | |
97 | 139 | then throw("insufficient funds") | |
98 | 140 | else ScriptResult(WriteSet([DataEntry(getKeySupplierBalance(supplierAddress), 0)]), TransferSet([ScriptTransfer(addressFromStringValue(supplierAddress), balance, unit)])) | |
99 | 141 | } | |
100 | 142 | ||
101 | 143 | ||
144 | + | ||
145 | + | @Callable(i) | |
146 | + | func voteCommit (item,hash) = { | |
147 | + | let user = toBase58String(i.caller.bytes) | |
148 | + | let commits = getValueCommitCount(item) | |
149 | + | let status = getValueItemStatus(item) | |
150 | + | if ((commits == VOTERS)) | |
151 | + | then throw("reached max number of voters") | |
152 | + | else if ((getValueCommit(item, user) != NONE)) | |
153 | + | then throw("user has participated already") | |
154 | + | else if ((getKeyItemSupplier(item) == NONE)) | |
155 | + | then throw("item doesn't exists") | |
156 | + | else if (if ((status != NONE)) | |
157 | + | then (status != VOTING) | |
158 | + | else false) | |
159 | + | then throw("voting is not possible") | |
160 | + | else WriteSet([DataEntry(getKeyCommit(item, user), hash), DataEntry(getKeyCommitCount(item), (commits + 1)), DataEntry(getKeyItemStatus(item), if ((commits == (VOTERS - 1))) | |
161 | + | then REVEAL | |
162 | + | else VOTING)]) | |
163 | + | } | |
164 | + | ||
165 | + |
github/deemru/w8io/026f985 72.01 ms ◑