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:AAIDAAAAAAAAABsIARIAEgMKAQESBQoDCAEIEgMKAQgSBAoCCAgAAAAdAAAAAAROT05FAgAAAARub25lAAAAAAZWT1RFUlMAAAAAAAAAAAMAAAAABlFVT1JVTQAAAAAAAAAAAgAAAAAGVk9USU5HAgAAAAZ2b3RpbmcAAAAABlJFVkVBTAIAAAAGcmV2ZWFsAAAAAAhGRUFUVVJFRAIAAAAIZmVhdHVyZWQAAAAACERFTElTVEVEAgAAAAhkZWxpc3RlZAEAAAAOZ2V0TnVtYmVyQnlLZXkAAAABAAAAA2tleQQAAAADbnVtBAAAAAckbWF0Y2gwCQAEGgAAAAIFAAAABHRoaXMFAAAAA2tleQMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAADSW50BAAAAAFhBQAAAAckbWF0Y2gwBQAAAAFhAAAAAAAAAAAABQAAAANudW0BAAAAC2dldFN0ckJ5S2V5AAAAAQAAAANrZXkEAAAAA3N0cgQAAAAHJG1hdGNoMAkABB0AAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAABlN0cmluZwQAAAABYQUA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ycwMJAQAAAAIhPQAAAAIJAQAAAA5nZXRWYWx1ZUNvbW1pdAAAAAIFAAAABGl0ZW0FAAAABHVzZXIFAAAABE5PTkUJAAACAAAAAQIAAAAddXNlciBoYXMgYWxyZWFkeSBwYXJ0aWNpcGF0ZWQDCQAAAAAAAAIJAQAAABJnZXRLZXlJdGVtU3VwcGxpZXIAAAABBQAAAARpdGVtBQAAAAROT05FCQAAAgAAAAECAAAAE2l0ZW0gZG9lcyBub3QgZXhpc3QDAwkBAAAAAiE9AAAAAgUAAAAGc3RhdHVzBQAAAAROT05FCQEAAAACIT0AAAACBQAAAAZzdGF0dXMFAAAABlZPVElORwcJAAACAAAAAQIAAAAWdm90aW5nIGlzIG5vdCBwb3NzaWJsZQkBAAAACFdyaXRlU2V0AAAAAQkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgkBAAAADGdldEtleUNvbW1pdAAAAAIFAAAABGl0ZW0FAAAABHVzZXIFAAAABGhhc2gJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAQAAABJnZXRLZXlDb21taXRzQ291bnQAAAABBQAAAARpdGVtCQAAZAAAAAIFAAAAB2NvbW1pdHMAAAAAAAAAAAEJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAQAAABBnZXRLZXlJdGVtU3RhdHVzAAAAAQUAAAAEaXRlbQMJAAAAAAAAAgUAAAAHY29tbWl0cwUAAAAGVk9URVJTBQAAAAZSRVZFQUwFAAAABlZPVElORwUAAAADbmlsAAAAAALT8r0=", "chainId": 84, "height": 769590, "spentComplexity": 0 } View: original | compacted Prev: D41TLMtkcGZvmDMKpiW65tFGTht3f45Rao9FGtFJuk3r Next: FbSw7a8c85bkSpU2acvUEje6n1Q7PTAko4mK8j64e3LS Diff:
OldNewDifferences
4444
4545
4646 func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt")
47+
48+
49+func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item))
4750
4851
4952 func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title)))))
153156
154157
155158 @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)
156180 func voteCommit (item,hash) = {
157181 let user = toBase58String(i.caller.bytes)
158182 let commits = getValueCommitsCount(item)
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 3 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let NONE = "none"
55
66 let VOTERS = 3
77
88 let QUORUM = 2
99
1010 let VOTING = "voting"
1111
1212 let REVEAL = "reveal"
1313
1414 let FEATURED = "featured"
1515
1616 let DELISTED = "delisted"
1717
1818 func getNumberByKey (key) = {
1919 let num = match getInteger(this, key) {
2020 case a: Int =>
2121 a
2222 case _ =>
2323 0
2424 }
2525 num
2626 }
2727
2828
2929 func getStrByKey (key) = {
3030 let str = match getString(this, key) {
3131 case a: String =>
3232 a
3333 case _ =>
3434 NONE
3535 }
3636 str
3737 }
3838
3939
4040 func getKeyItemPrice (item) = (item + "_price")
4141
4242
4343 func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item))
4444
4545
4646 func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt")
47+
48+
49+func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item))
4750
4851
4952 func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title)))))
5053
5154
5255 func getKeyItemData (item) = (item + "_data")
5356
5457
5558 func getKeyItemSupplier (item) = (item + "_owner")
5659
5760
5861 func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item))
5962
6063
6164 func getKeyBalanceSupplier (account) = (account + "_balance")
6265
6366
6467 func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account))
6568
6669
6770 func getKeyCommit (item,user) = (((item + "_") + user) + "_commit")
6871
6972
7073 func getValueCommit (item,user) = getStrByKey(getKeyCommit(item, user))
7174
7275
7376 func getKeyCommitsCount (item) = (item + "_comctn")
7477
7578
7679 func getValueCommitsCount (item) = getNumberByKey(getKeyCommitsCount(item))
7780
7881
7982 func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal")
8083
8184
8285 func getValueReveal (item,user) = getStrByKey(getKeyReveal(item, user))
8386
8487
8588 func getKeyItemStatus (item) = (item + "_status")
8689
8790
8891 func getValueItemStatus (item) = getStrByKey(getKeyItemStatus(item))
8992
9093
9194 func getKeyVoteCount (item,vote) = ((item + "_res:") + vote)
9295
9396
9497 func getValueVoteCount (item,vote) = getNumberByKey(getKeyVoteCount(item, vote))
9598
9699
97100 @Callable(i)
98101 func deposit () = {
99102 let pmt = extract(i.payment)
100103 if (isDefined(pmt.assetId))
101104 then throw("can hold waves only at the moment")
102105 else {
103106 let currentKey = toBase58String(i.caller.bytes)
104107 let currentAmount = match getInteger(this, currentKey) {
105108 case a: Int =>
106109 a
107110 case _ =>
108111 0
109112 }
110113 let wlStsCurr = match getString(this, ("wl_sts_" + currentKey)) {
111114 case a: String =>
112115 a
113116 case _ =>
114117 throw("User has not been whitelisted")
115118 }
116119 let newAmount = (currentAmount + pmt.amount)
117120 WriteSet([DataEntry(currentKey, newAmount)])
118121 }
119122 }
120123
121124
122125
123126 @Callable(i)
124127 func withdraw (amount) = {
125128 let currentKey = toBase58String(i.caller.bytes)
126129 let currentAmount = match getInteger(this, currentKey) {
127130 case a: Int =>
128131 a
129132 case _ =>
130133 0
131134 }
132135 let newAmount = (currentAmount - amount)
133136 if ((0 > amount))
134137 then throw("Can't withdraw negative amount")
135138 else if ((0 > newAmount))
136139 then throw("Not enough balance")
137140 else ScriptResult(WriteSet([DataEntry(currentKey, newAmount)]), TransferSet([ScriptTransfer(i.caller, amount, unit)]))
138141 }
139142
140143
141144
142145 @Callable(i)
143146 func addItem (title,price,data) = {
144147 let supplierAddress = toBase58String(i.caller.bytes)
145148 let item = getKeyItem(supplierAddress, title)
146149 if ((0 >= price))
147150 then throw("purchase amount cannot be less than item price")
148151 else if ((getValueItemSupplier(item) != NONE))
149152 then throw("an item is already exist")
150153 else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddress), DataEntry(getKeyItemPrice(item), price), DataEntry(getKeyItemData(item), data)])
151154 }
152155
153156
154157
155158 @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)
156180 func voteCommit (item,hash) = {
157181 let user = toBase58String(i.caller.bytes)
158182 let commits = getValueCommitsCount(item)
159183 let status = getValueItemStatus(item)
160184 if ((commits >= VOTERS))
161185 then throw("reached max num of voters")
162186 else if ((getValueCommit(item, user) != NONE))
163187 then throw("user has already participated")
164188 else if ((getKeyItemSupplier(item) == NONE))
165189 then throw("item does not exist")
166190 else if (if ((status != NONE))
167191 then (status != VOTING)
168192 else false)
169193 then throw("voting is not possible")
170194 else WriteSet([DataEntry(getKeyCommit(item, user), hash), DataEntry(getKeyCommitsCount(item), (commits + 1)), DataEntry(getKeyItemStatus(item), if ((commits == VOTERS))
171195 then REVEAL
172196 else VOTING)])
173197 }
174198
175199

github/deemru/w8io/169f3d6 
51.37 ms