tx · 7RPAk3EXUsHh4JT5gidXNXCAmAVF7GybCNjvukDwidg6

3N86zk6P6pyxFnu5o1U62pZeiRQ6Q1b3Lgb:  -0.01000010 Waves

2021.07.08 14:11 [1604546] smart account 3N86zk6P6pyxFnu5o1U62pZeiRQ6Q1b3Lgb > SELF 0.00000000 Waves

{ "type": 13, "id": "7RPAk3EXUsHh4JT5gidXNXCAmAVF7GybCNjvukDwidg6", "fee": 1000010, "feeAssetId": null, "timestamp": 1625742730683, "version": 2, "chainId": 84, "sender": "3N86zk6P6pyxFnu5o1U62pZeiRQ6Q1b3Lgb", "senderPublicKey": "J5UWSH8o2ZgSCRmahKoyq3Zzf9CSXEJtFQjoxuiqw8jN", "proofs": [ "5BaayzCcyB219CQoNYcVvQ5iACMmnuiwmwLDT6QuY2oNzhV8gg3hokM6MaKyXGvnzcsjZFvxiVRzmTHgBWmaEzPo" ], "script": "base64:AAIFAAAAAAAAAkQIAhIFCgMIAQgSAwoBCBIAGgoKAmExEgROT05FGhQKAmEyEg5nZXROdW1iZXJCeUtleRoJCgJhMxIDa2V5GgkKAmE0EgNudW0aDQoCYTUSByRtYXRjaDAaBwoCYTYSAWEaEQoCYTcSC2dldFN0ckJ5S2V5GgkKAmE4EgNzdHIaFQoCYTkSD2dldEtleUl0ZW1QcmljZRoKCgJiMRIEaXRlbRoXCgJiMhIRZ2V0VmFsdWVJdGVtUHJpY2UaGwoCYjMSFWdldEtleVVzZXJJdGVtQ291bnRlchoKCgJiNBIEdXNlchodCgJiNRIXZ2V0VmFsdWVVc2VySXRlbUNvdW50ZXIaEAoCYjYSCmdldEtleUl0ZW0aDgoCYjcSCHN1cHBsaWVyGgsKAmI4EgV0aXRsZRoUCgJiORIOZ2V0S2V5SXRlbURhdGEaGAoCYzESEmdldEtleUl0ZW1TdXBwbGllchoaCgJjMhIUZ2V0VmFsdWVJdGVtU3VwcGxpZXIaGwoCYzMSFWdldEtleUJhbGFuY2VTdXBwbGllchoNCgJjNBIHYWNjb3VudBodC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": 1604546, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: HorArUdbYmWxDgaJbJs9ervRgaAqYnhNagh8cUaNVYo Next: 99uJVYqixKRVEV7pCvK1LsqQ6NeWsQyEGf8hxt78eNVp Diff:
OldNewDifferences
11 {-# STDLIB_VERSION 5 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# 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-
164 let NONE = "none"
175
186 func getNumberByKey (key) = {
3725 }
3826
3927
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+
4046 func getKeyItemSupplier (item) = (item + "_data")
4147
4248
43-func getKeyCommit (item,user) = (((item + "_") + user) + "_commit")
49+func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item))
4450
4551
46-func getValueCommit (item,user) = getStrByKey(getKeyCommit(item, user))
52+func getKeyBalanceSupplier (account) = (account + "_balance")
4753
4854
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))
55+func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account))
7156
7257
7358 @Callable(i)
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)]
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)]
9167 }
9268
9369
9470
9571 @Callable(i)
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)]
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)]
11799 }
118100
119101
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 5 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# 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-
164 let NONE = "none"
175
186 func getNumberByKey (key) = {
197 let num = match getInteger(this, key) {
208 case a: Int =>
219 a
2210 case _ =>
2311 0
2412 }
2513 num
2614 }
2715
2816
2917 func getStrByKey (key) = {
3018 let str = match getString(this, key) {
3119 case a: String =>
3220 a
3321 case _ =>
3422 NONE
3523 }
3624 str
3725 }
3826
3927
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+
4046 func getKeyItemSupplier (item) = (item + "_data")
4147
4248
43-func getKeyCommit (item,user) = (((item + "_") + user) + "_commit")
49+func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item))
4450
4551
46-func getValueCommit (item,user) = getStrByKey(getKeyCommit(item, user))
52+func getKeyBalanceSupplier (account) = (account + "_balance")
4753
4854
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))
55+func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account))
7156
7257
7358 @Callable(i)
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)]
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)]
9167 }
9268
9369
9470
9571 @Callable(i)
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)]
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)]
11799 }
118100
119101

github/deemru/w8io/873ac7e 
33.23 ms