tx · 7hFmwEj7tsA1GPPDmqEX7hzjYL2U2T7T2acC183P1CJT 3MzvMg5dRiLMVdHJ3v4AfeCXttmaSPHdoVN: -0.01400000 Waves 2019.11.17 22:59 [769590] smart account 3MzvMg5dRiLMVdHJ3v4AfeCXttmaSPHdoVN > SELF 0.00000000 Waves
{ "type": 13, "id": "7hFmwEj7tsA1GPPDmqEX7hzjYL2U2T7T2acC183P1CJT", "fee": 1400000, "feeAssetId": null, "timestamp": 1574020832361, "version": 1, "sender": "3MzvMg5dRiLMVdHJ3v4AfeCXttmaSPHdoVN", "senderPublicKey": "GvoCzLxrhCgZzNLksqhf43ehht8jTASRqtGBmXaNn7Jq", "proofs": [ "3rLXqGgRkaueNM5vQNe14nSx7cGTmjPS4AS2ycXcgrdwK4PSmqgxkPRLXJ8KrzmYypwF8Mb77UkwVn3LWrZPec3z" ], "script": "base64:AAIDAAAAAAAAABsIARIAEgMKAQESBQoDCAEIEgMKAQgSBAoCCAgAAAAdAAAAAAROT05FAgAAAARub25lAAAAAAZWT1RFUlMAAAAAAAAAAAMAAAAABlFVT1JVTQAAAAAAAAAAAgAAAAAGVk9USU5HAgAAAAZ2b3RpbmcAAAAABlJFVkVBTAIAAAAGcmV2ZWFsAAAAAAhGRUFUVVJFRAIAAAAIZmVhdHVyZWQAAAAACERFTElTVEVEAgAAAAhkZWxpc3RlZAEAAAAOZ2V0TnVtYmVyQnlLZXkAAAABAAAAA2tleQQAAAADbnVtBAAAAAckbWF0Y2gwCQAEGgAAAAIFAAAABHRoaXMFAAAAA2tleQMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAADSW50BAAAAAFhBQAAAAckbWF0Y2gwBQAAAAFhAAAAAAAAAAAABQAAAANudW0BAAAAC2dldFN0ckJ5S2V5AAAAAQAAAANrZXkEAAAAA3N0cgQAAAAHJG1hdGNoMAkABB0AAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAABlN0cmluZwQAAAABYQUAA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wMJAQAAAAIhPQAAAAIJAQAAAA5nZXRWYWx1ZUNvbW1pdAAAAAIFAAAABGl0ZW0FAAAABHVzZXIFAAAABE5PTkUJAAACAAAAAQIAAAAddXNlciBoYXMgYWxyZWFkeSBwYXJ0aWNpcGF0ZWQDCQAAAAAAAAIJAQAAABJnZXRLZXlJdGVtU3VwcGxpZXIAAAABBQAAAARpdGVtBQAAAAROT05FCQAAAgAAAAECAAAAE2l0ZW0gZG9lcyBub3QgZXhpc3QDAwkBAAAAAiE9AAAAAgUAAAAGc3RhdHVzBQAAAAROT05FCQEAAAACIT0AAAACBQAAAAZzdGF0dXMFAAAABlZPVElORwcJAAACAAAAAQIAAAAWdm90aW5nIGlzIG5vdCBwb3NzaWJsZQkBAAAACFdyaXRlU2V0AAAAAQkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgkBAAAADGdldEtleUNvbW1pdAAAAAIFAAAABGl0ZW0FAAAABHVzZXIFAAAABGhhc2gJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAQAAABJnZXRLZXlDb21taXRzQ291bnQAAAABBQAAAARpdGVtCQAAZAAAAAIFAAAAB2NvbW1pdHMAAAAAAAAAAAEJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAQAAABBnZXRLZXlJdGVtU3RhdHVzAAAAAQUAAAAEaXRlbQMJAAAAAAAAAgUAAAAHY29tbWl0cwUAAAAGVk9URVJTBQAAAAZSRVZFQUwFAAAABlZPVElORwUAAAADbmlsAAAAAALT8r0=", "chainId": 84, "height": 769590, "spentComplexity": 0 } View: original | compacted Prev: D41TLMtkcGZvmDMKpiW65tFGTht3f45Rao9FGtFJuk3r Next: FbSw7a8c85bkSpU2acvUEje6n1Q7PTAko4mK8j64e3LS Diff:
Old | New | Differences | |
---|---|---|---|
44 | 44 | ||
45 | 45 | ||
46 | 46 | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt") | |
47 | + | ||
48 | + | ||
49 | + | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) | |
47 | 50 | ||
48 | 51 | ||
49 | 52 | func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title))))) | |
153 | 156 | ||
154 | 157 | ||
155 | 158 | @Callable(i) | |
159 | + | func purchase (item) = { | |
160 | + | let pmt = extract(i.payment) | |
161 | + | if (isDefined(pmt.assetId)) | |
162 | + | then throw("WAVES tokens only at the moment") | |
163 | + | else { | |
164 | + | let userAddress = toBase58String(i.caller.bytes) | |
165 | + | let price = getValueItemPrice(item) | |
166 | + | let supplierAddress = getValueItemSupplier(item) | |
167 | + | if ((price > pmt.amount)) | |
168 | + | then throw("purchase amount cannot be less than item price") | |
169 | + | else if ((pmt.amount > price)) | |
170 | + | then throw("purchase amount cannot be higher than item price") | |
171 | + | else if ((supplierAddress == NONE)) | |
172 | + | then throw("supplier does not exist") | |
173 | + | else WriteSet([DataEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), DataEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))]) | |
174 | + | } | |
175 | + | } | |
176 | + | ||
177 | + | ||
178 | + | ||
179 | + | @Callable(i) | |
156 | 180 | func voteCommit (item,hash) = { | |
157 | 181 | let user = toBase58String(i.caller.bytes) | |
158 | 182 | let commits = getValueCommitsCount(item) |
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 getNumberByKey (key) = { | |
19 | 19 | let num = match getInteger(this, key) { | |
20 | 20 | case a: Int => | |
21 | 21 | a | |
22 | 22 | case _ => | |
23 | 23 | 0 | |
24 | 24 | } | |
25 | 25 | num | |
26 | 26 | } | |
27 | 27 | ||
28 | 28 | ||
29 | 29 | func getStrByKey (key) = { | |
30 | 30 | let str = match getString(this, key) { | |
31 | 31 | case a: String => | |
32 | 32 | a | |
33 | 33 | case _ => | |
34 | 34 | NONE | |
35 | 35 | } | |
36 | 36 | str | |
37 | 37 | } | |
38 | 38 | ||
39 | 39 | ||
40 | 40 | func getKeyItemPrice (item) = (item + "_price") | |
41 | 41 | ||
42 | 42 | ||
43 | 43 | func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item)) | |
44 | 44 | ||
45 | 45 | ||
46 | 46 | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt") | |
47 | + | ||
48 | + | ||
49 | + | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) | |
47 | 50 | ||
48 | 51 | ||
49 | 52 | func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title))))) | |
50 | 53 | ||
51 | 54 | ||
52 | 55 | func getKeyItemData (item) = (item + "_data") | |
53 | 56 | ||
54 | 57 | ||
55 | 58 | func getKeyItemSupplier (item) = (item + "_owner") | |
56 | 59 | ||
57 | 60 | ||
58 | 61 | func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item)) | |
59 | 62 | ||
60 | 63 | ||
61 | 64 | func getKeyBalanceSupplier (account) = (account + "_balance") | |
62 | 65 | ||
63 | 66 | ||
64 | 67 | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
65 | 68 | ||
66 | 69 | ||
67 | 70 | func getKeyCommit (item,user) = (((item + "_") + user) + "_commit") | |
68 | 71 | ||
69 | 72 | ||
70 | 73 | func getValueCommit (item,user) = getStrByKey(getKeyCommit(item, user)) | |
71 | 74 | ||
72 | 75 | ||
73 | 76 | func getKeyCommitsCount (item) = (item + "_comctn") | |
74 | 77 | ||
75 | 78 | ||
76 | 79 | func getValueCommitsCount (item) = getNumberByKey(getKeyCommitsCount(item)) | |
77 | 80 | ||
78 | 81 | ||
79 | 82 | func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal") | |
80 | 83 | ||
81 | 84 | ||
82 | 85 | func getValueReveal (item,user) = getStrByKey(getKeyReveal(item, user)) | |
83 | 86 | ||
84 | 87 | ||
85 | 88 | func getKeyItemStatus (item) = (item + "_status") | |
86 | 89 | ||
87 | 90 | ||
88 | 91 | func getValueItemStatus (item) = getStrByKey(getKeyItemStatus(item)) | |
89 | 92 | ||
90 | 93 | ||
91 | 94 | func getKeyVoteCount (item,vote) = ((item + "_res:") + vote) | |
92 | 95 | ||
93 | 96 | ||
94 | 97 | func getValueVoteCount (item,vote) = getNumberByKey(getKeyVoteCount(item, vote)) | |
95 | 98 | ||
96 | 99 | ||
97 | 100 | @Callable(i) | |
98 | 101 | func deposit () = { | |
99 | 102 | let pmt = extract(i.payment) | |
100 | 103 | if (isDefined(pmt.assetId)) | |
101 | 104 | then throw("can hold waves only at the moment") | |
102 | 105 | else { | |
103 | 106 | let currentKey = toBase58String(i.caller.bytes) | |
104 | 107 | let currentAmount = match getInteger(this, currentKey) { | |
105 | 108 | case a: Int => | |
106 | 109 | a | |
107 | 110 | case _ => | |
108 | 111 | 0 | |
109 | 112 | } | |
110 | 113 | let wlStsCurr = match getString(this, ("wl_sts_" + currentKey)) { | |
111 | 114 | case a: String => | |
112 | 115 | a | |
113 | 116 | case _ => | |
114 | 117 | throw("User has not been whitelisted") | |
115 | 118 | } | |
116 | 119 | let newAmount = (currentAmount + pmt.amount) | |
117 | 120 | WriteSet([DataEntry(currentKey, newAmount)]) | |
118 | 121 | } | |
119 | 122 | } | |
120 | 123 | ||
121 | 124 | ||
122 | 125 | ||
123 | 126 | @Callable(i) | |
124 | 127 | func withdraw (amount) = { | |
125 | 128 | let currentKey = toBase58String(i.caller.bytes) | |
126 | 129 | let currentAmount = match getInteger(this, currentKey) { | |
127 | 130 | case a: Int => | |
128 | 131 | a | |
129 | 132 | case _ => | |
130 | 133 | 0 | |
131 | 134 | } | |
132 | 135 | let newAmount = (currentAmount - amount) | |
133 | 136 | if ((0 > amount)) | |
134 | 137 | then throw("Can't withdraw negative amount") | |
135 | 138 | else if ((0 > newAmount)) | |
136 | 139 | then throw("Not enough balance") | |
137 | 140 | else ScriptResult(WriteSet([DataEntry(currentKey, newAmount)]), TransferSet([ScriptTransfer(i.caller, amount, unit)])) | |
138 | 141 | } | |
139 | 142 | ||
140 | 143 | ||
141 | 144 | ||
142 | 145 | @Callable(i) | |
143 | 146 | func addItem (title,price,data) = { | |
144 | 147 | let supplierAddress = toBase58String(i.caller.bytes) | |
145 | 148 | let item = getKeyItem(supplierAddress, title) | |
146 | 149 | if ((0 >= price)) | |
147 | 150 | then throw("purchase amount cannot be less than item price") | |
148 | 151 | else if ((getValueItemSupplier(item) != NONE)) | |
149 | 152 | then throw("an item is already exist") | |
150 | 153 | else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddress), DataEntry(getKeyItemPrice(item), price), DataEntry(getKeyItemData(item), data)]) | |
151 | 154 | } | |
152 | 155 | ||
153 | 156 | ||
154 | 157 | ||
155 | 158 | @Callable(i) | |
159 | + | func purchase (item) = { | |
160 | + | let pmt = extract(i.payment) | |
161 | + | if (isDefined(pmt.assetId)) | |
162 | + | then throw("WAVES tokens only at the moment") | |
163 | + | else { | |
164 | + | let userAddress = toBase58String(i.caller.bytes) | |
165 | + | let price = getValueItemPrice(item) | |
166 | + | let supplierAddress = getValueItemSupplier(item) | |
167 | + | if ((price > pmt.amount)) | |
168 | + | then throw("purchase amount cannot be less than item price") | |
169 | + | else if ((pmt.amount > price)) | |
170 | + | then throw("purchase amount cannot be higher than item price") | |
171 | + | else if ((supplierAddress == NONE)) | |
172 | + | then throw("supplier does not exist") | |
173 | + | else WriteSet([DataEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), DataEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))]) | |
174 | + | } | |
175 | + | } | |
176 | + | ||
177 | + | ||
178 | + | ||
179 | + | @Callable(i) | |
156 | 180 | func voteCommit (item,hash) = { | |
157 | 181 | let user = toBase58String(i.caller.bytes) | |
158 | 182 | let commits = getValueCommitsCount(item) | |
159 | 183 | let status = getValueItemStatus(item) | |
160 | 184 | if ((commits >= VOTERS)) | |
161 | 185 | then throw("reached max num of voters") | |
162 | 186 | else if ((getValueCommit(item, user) != NONE)) | |
163 | 187 | then throw("user has already participated") | |
164 | 188 | else if ((getKeyItemSupplier(item) == NONE)) | |
165 | 189 | then throw("item does not exist") | |
166 | 190 | else if (if ((status != NONE)) | |
167 | 191 | then (status != VOTING) | |
168 | 192 | else false) | |
169 | 193 | then throw("voting is not possible") | |
170 | 194 | else WriteSet([DataEntry(getKeyCommit(item, user), hash), DataEntry(getKeyCommitsCount(item), (commits + 1)), DataEntry(getKeyItemStatus(item), if ((commits == VOTERS)) | |
171 | 195 | then REVEAL | |
172 | 196 | else VOTING)]) | |
173 | 197 | } | |
174 | 198 | ||
175 | 199 |
github/deemru/w8io/169f3d6 51.37 ms ◑