tx · s1J5YMir3DTPfLVXYLGjYeatr3SK4QW9EeUEaeCa3f1

3N18S8xfWJYHVuGfJcpcPVh7LsnqR9hKTcc:  -0.01400000 Waves

2019.09.08 10:47 [666824] smart account 3N18S8xfWJYHVuGfJcpcPVh7LsnqR9hKTcc > SELF 0.00000000 Waves

{ "type": 13, "id": "s1J5YMir3DTPfLVXYLGjYeatr3SK4QW9EeUEaeCa3f1", "fee": 1400000, "feeAssetId": null, "timestamp": 1567928736412, "version": 1, "sender": "3N18S8xfWJYHVuGfJcpcPVh7LsnqR9hKTcc", "senderPublicKey": "9cETBksYN8YMHGvDB6BEqmH9HScpCMBRZwnjCviRQ9aA", "proofs": [ "4CNm5CWGPQ4k6YnEXXpmJQjq7wc3cTbSBaHc8YcnPLXLcBu8Y1z9xXmrk45LNcx9W3mwDQkGzxkMitZ2wEfayee" ], "script": "base64:AAIDAAAAAAAAAAAAAAARAAAAAAVQUklDRQAAAAAABfXhAAAAAAALUEFURU5UUFJJQ0UAAAAAAAvrwgAAAAAABk9SQUNMRQIAAAAGT1JBQ0xFAAAAAANXSU4CAAAAA1dJTgAAAAAETE9TRQIAAAAETE9TRQAAAAAETk9ORQIAAAAEbm9uZQEAAAAOZ2V0TnVtYmVyQnlLZXkAAAABAAAAA2tleQQAAAADbnVtBAAAAAckbWF0Y2gwCQAEGgAAAAIFAAAABHRoaXMFAAAAA2tleQMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAADSW50BAAAAAFhBQAAAAckbWF0Y2gwBQAAAAFhAAAAAAAAAAAABQAAAANudW0BAAAAC2dldFN0ckJ5S2V5AAAAAQAAAANrZXkEAAAAA3N0cgQAAAAHJG1hdGNoMAkABB0AAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAABlN0cmluZwQAAAABYQUAAAAHJG1hdGNoMAUAAAABYQUAAAAETk9ORQUAAAADc3RyAQAAABF2YWxpZGF0ZVR3b0Nvb3JkcwAAAAQAAAACeD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XIFAAAABWxvc2VyCQAAAgAAAAECAAAAIndpbm5lciBhbmQgbG9zZXIgbXVzdCBiZSBkaWZmZXJlbnQDCQEAAAACIT0AAAACCQEAAAALZ2V0U3RyQnlLZXkAAAABBQAAAARnYW1lBQAAAAROT05FCQAAAgAAAAECAAAAIXRoaXMgZ2FtZSBoYXMgYWxyZWFkeSBiZWVuIHBsYXllZAkBAAAACFdyaXRlU2V0AAAAAQkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgUAAAAEZ2FtZQkAASwAAAACCQABLAAAAAIJAAEsAAAAAgUAAAAGd2lubmVyAgAAAAUtV0lOOwUAAAAFbG9zZXICAAAABS1MT1NFCQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACCQEAAAAOZ2V0S2V5V2luQ291bnQAAAABBQAAAAZ3aW5uZXIJAABkAAAAAgkBAAAAEGdldFZhbHVlV2luQ291bnQAAAABBQAAAAZ3aW5uZXIAAAAAAAAAAAEJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAQAAAA9nZXRLZXlMb3NlQ291bnQAAAABBQAAAAVsb3NlcgkAAGQAAAACCQEAAAARZ2V0VmFsdWVMb3NlQ291bnQAAAABBQAAAAVsb3NlcgAAAAAAAAAAAQUAAAADbmlsAAAAAMX/6Ns=", "chainId": 84, "height": 666824, "spentComplexity": 0 } View: original | compacted Prev: 6psbdMeFfJR6eAioCQJUxPHHKkWB91G7cpW64MxpxPyM Next: 3v3mSXL11AzLcPvND97Fu21HynTi13rj5LPV7qngSAJy Diff:
OldNewDifferences
11 {-# STDLIB_VERSION 3 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4+let PRICE = 100000000
5+
6+let PATENTPRICE = 200000000
7+
8+let ORACLE = "ORACLE"
9+
10+let WIN = "WIN"
11+
12+let LOSE = "LOSE"
13+
414 let NONE = "none"
515
616 func getNumberByKey (key) = {
2535 }
2636
2737
28-func getKeyItemPrice (item) = (item + "_price")
38+func validateTwoCoords (x1,y1,x2,y2) = if ((x2 > x1))
39+ then false
40+ else if (if ((x1 == x2))
41+ then (y2 > y1)
42+ else false)
43+ then false
44+ else true
2945
3046
31-func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item))
47+func validateCoords (x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6) = if (!(validateTwoCoords(x1, x2, y1, y2)))
48+ then false
49+ else if (!(validateTwoCoords(x2, x3, y2, y3)))
50+ then false
51+ else if (!(validateTwoCoords(x3, x4, y3, y4)))
52+ then false
53+ else if (!(validateTwoCoords(x4, x5, y4, y5)))
54+ then false
55+ else if (!(validateTwoCoords(x5, x6, y5, y6)))
56+ then false
57+ else true
3258
3359
34-func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt")
60+func genKeyFromCoords (x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6) = (((((((((((toString(x1) + toString(y1)) + toString(x2)) + toString(y2)) + toString(x3)) + toString(y3)) + toString(x4)) + toString(y4)) + toString(x5)) + toString(y5)) + toString(x6)) + toString(y6))
3561
3662
37-func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item))
63+func getKeyBalanceUser (account) = (account + "_balance")
3864
3965
40-func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title)))))
66+func getValueBalanceUser (account) = getNumberByKey(getKeyBalanceUser(account))
4167
4268
43-func getKeyItemData (item) = (item + "_data")
69+func getKeyWinCount (user) = (user + "_wincnt")
4470
4571
46-func getKeyItemSupplier (item) = (item + "_supplier")
72+func getValueWinCount (user) = getNumberByKey(getKeyWinCount(user))
4773
4874
49-func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item))
75+func getKeyLoseCount (user) = (user + "_losecnt")
5076
5177
52-func getKeyBalanceSupplier (account) = (account + "_balance")
53-
54-
55-func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account))
56-
57-
58-let VOTERS = 3
59-
60-let QUORUM = 2
61-
62-let VOTING = "voting"
63-
64-let REVEAL = "reveal"
65-
66-let FEATURED = "featured"
67-
68-let DELISTED = "delisted"
69-
70-func getKeyCommit (item,user) = (((item + "_") + user) + "_commit")
71-
72-
73-func getValueCommit (item,user) = getStrByKey(getKeyCommit(item, user))
74-
75-
76-func getKeyCommitsCount (item) = (item + "_comcnt")
77-
78-
79-func getValueCommitsCount (item) = getNumberByKey(getKeyCommitsCount(item))
80-
81-
82-func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal")
83-
84-
85-func getValueReveal (item,user) = getStrByKey(getKeyReveal(item, user))
86-
87-
88-func getKeyItemStatus (item) = (item + "_status")
89-
90-
91-func getValueItemStatus (item) = getStrByKey(getKeyItemStatus(item))
92-
93-
94-func getKeyVoteCount (item,vote) = ((item + "_res:") + vote)
95-
96-
97-func getValueVoteCount (item,vote) = getNumberByKey(getKeyVoteCount(item, vote))
78+func getValueLoseCount (user) = getNumberByKey(getKeyLoseCount(user))
9879
9980
10081 @Callable(i)
101-func addItem (title,price,data) = {
102- let supplierAddress = toBase58String(i.caller.bytes)
103- let item = getKeyItem(supplierAddress, title)
104- if ((0 >= price))
105- then throw("purchase amount cannot be less than item price")
106- else if ((getValueItemSupplier(item) != NONE))
107- then throw("an item is already exists")
108- else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddress), DataEntry(getKeyItemPrice(item), price), DataEntry(getKeyItemData(item), data)])
82+func patent (x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6) = {
83+ let pmt = extract(i.payment)
84+ if (isDefined(pmt.assetId))
85+ then throw("can use WAVES only at the moment")
86+ else {
87+ let userAddress = toBase58String(i.caller.bytes)
88+ if ((pmt.amount != PRICE))
89+ then throw("purchase amount cannot be not equal to the price")
90+ else if (validateCoords(x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6))
91+ then throw("invalid coordinates order")
92+ else if ((getStrByKey(genKeyFromCoords(x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6)) != NONE))
93+ then throw("this patent is already exists")
94+ else WriteSet([DataEntry(genKeyFromCoords(x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6), userAddress)])
95+ }
10996 }
11097
11198
11299
113100 @Callable(i)
114-func purchase (item) = {
101+func buyPatent (x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6) = {
115102 let pmt = extract(i.payment)
116103 if (isDefined(pmt.assetId))
117104 then throw("can use WAVES only at the moment")
118105 else {
119106 let userAddress = toBase58String(i.caller.bytes)
120- let price = getValueItemPrice(item)
121- let supplierAddress = getValueItemSupplier(item)
122- if ((price > pmt.amount))
123- then throw("purchase amount cannot be less than item price")
124- else if ((pmt.amount > price))
125- then throw("purchase amount cannot be higher than item price")
126- else if ((supplierAddress == NONE))
127- then throw("supplier address does not exists")
128- else WriteSet([DataEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), DataEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))])
107+ let patentOwnerAddress = getStrByKey(genKeyFromCoords(x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6))
108+ if ((pmt.amount != PATENTPRICE))
109+ then throw("purchase amount cannot be not equal to the price")
110+ else if (validateCoords(x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6))
111+ then throw("invalid coordinates order")
112+ else if ((patentOwnerAddress == NONE))
113+ then throw("there is no such patent")
114+ else WriteSet([DataEntry(genKeyFromCoords(x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6), userAddress), DataEntry(getKeyBalanceUser(patentOwnerAddress), (getValueBalanceUser(patentOwnerAddress) + pmt.amount))])
129115 }
130116 }
131117
133119
134120 @Callable(i)
135121 func withdraw () = {
136- let supplierAddress = toBase58String(i.caller.bytes)
137- let balance = getValueBalanceSupplier(supplierAddress)
122+ let userAddress = toBase58String(i.caller.bytes)
123+ let balance = getValueBalanceUser(userAddress)
138124 if ((0 >= balance))
139125 then throw("insufficient balance")
140- else ScriptResult(WriteSet([DataEntry(getKeyBalanceSupplier(supplierAddress), 0)]), TransferSet([ScriptTransfer(addressFromStringValue(supplierAddress), balance, unit)]))
126+ else ScriptResult(WriteSet([DataEntry(getKeyBalanceUser(userAddress), 0)]), TransferSet([ScriptTransfer(addressFromStringValue(userAddress), balance, unit)]))
141127 }
142128
143129
144130
145131 @Callable(i)
146-func voteCommit (item,hash) = {
147- let user = toBase58String(i.caller.bytes)
148- let commits = getValueCommitsCount(item)
149- let status = getValueItemStatus(item)
150- if ((commits > VOTERS))
151- then throw("reached max num of voters")
152- else if ((getValueCommit(item, user) != NONE))
153- then throw("user has already participated")
154- else if ((getValueItemSupplier(item) == NONE))
155- then throw("item does not exist")
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(getKeyCommitsCount(item), (commits + 1)), DataEntry(getKeyItemStatus(item), if ((commits == VOTERS))
161- then REVEAL
162- else VOTING)])
163- }
164-
165-
166-
167-@Callable(i)
168-func voteReveal (item,vote,salt) = {
169- let user = toBase58String(i.caller.bytes)
170- let status = getValueItemStatus(item)
171- let newVoteCount = (getValueVoteCount(item, vote) + 1)
172- if ((toBase58String(sha256(toBytes((vote + salt)))) != getValueCommit(item, user)))
173- then throw("reveal data is not valid")
174- else if ((VOTERS > getValueCommitsCount(item)))
175- then throw("max num of voters hasn't reached yet")
176- else if ((getValueReveal(item, user) != NONE))
177- then throw("user has already participated")
178- else if (if ((status != VOTING))
179- then (status != REVEAL)
180- else false)
181- then throw("wrong status")
182- else if (if ((vote != FEATURED))
183- then (vote != DELISTED)
184- else false)
185- then throw("wrong vote")
186- else if (if ((status == FEATURED))
187- then true
188- else (status == DELISTED))
189- then throw("vote has finished")
190- else WriteSet([DataEntry(getKeyReveal(item, user), vote), DataEntry(getKeyVoteCount(item, vote), newVoteCount), DataEntry(getKeyItemStatus(item), if ((newVoteCount >= QUORUM))
191- then vote
192- else REVEAL)])
132+func endGame (game,winner,loser) = {
133+ let oracleAddres = toBase58String(i.caller.bytes)
134+ if ((oracleAddres != ORACLE))
135+ then throw("only oracle can inform about games results")
136+ else if ((winner == loser))
137+ then throw("winner and loser must be different")
138+ else if ((getStrByKey(game) != NONE))
139+ then throw("this game has already been played")
140+ else WriteSet([DataEntry(game, (((winner + "-WIN;") + loser) + "-LOSE")), DataEntry(getKeyWinCount(winner), (getValueWinCount(winner) + 1)), DataEntry(getKeyLoseCount(loser), (getValueLoseCount(loser) + 1))])
193141 }
194142
195143
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 3 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4+let PRICE = 100000000
5+
6+let PATENTPRICE = 200000000
7+
8+let ORACLE = "ORACLE"
9+
10+let WIN = "WIN"
11+
12+let LOSE = "LOSE"
13+
414 let NONE = "none"
515
616 func getNumberByKey (key) = {
717 let num = match getInteger(this, key) {
818 case a: Int =>
919 a
1020 case _ =>
1121 0
1222 }
1323 num
1424 }
1525
1626
1727 func getStrByKey (key) = {
1828 let str = match getString(this, key) {
1929 case a: String =>
2030 a
2131 case _ =>
2232 NONE
2333 }
2434 str
2535 }
2636
2737
28-func getKeyItemPrice (item) = (item + "_price")
38+func validateTwoCoords (x1,y1,x2,y2) = if ((x2 > x1))
39+ then false
40+ else if (if ((x1 == x2))
41+ then (y2 > y1)
42+ else false)
43+ then false
44+ else true
2945
3046
31-func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item))
47+func validateCoords (x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6) = if (!(validateTwoCoords(x1, x2, y1, y2)))
48+ then false
49+ else if (!(validateTwoCoords(x2, x3, y2, y3)))
50+ then false
51+ else if (!(validateTwoCoords(x3, x4, y3, y4)))
52+ then false
53+ else if (!(validateTwoCoords(x4, x5, y4, y5)))
54+ then false
55+ else if (!(validateTwoCoords(x5, x6, y5, y6)))
56+ then false
57+ else true
3258
3359
34-func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt")
60+func genKeyFromCoords (x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6) = (((((((((((toString(x1) + toString(y1)) + toString(x2)) + toString(y2)) + toString(x3)) + toString(y3)) + toString(x4)) + toString(y4)) + toString(x5)) + toString(y5)) + toString(x6)) + toString(y6))
3561
3662
37-func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item))
63+func getKeyBalanceUser (account) = (account + "_balance")
3864
3965
40-func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title)))))
66+func getValueBalanceUser (account) = getNumberByKey(getKeyBalanceUser(account))
4167
4268
43-func getKeyItemData (item) = (item + "_data")
69+func getKeyWinCount (user) = (user + "_wincnt")
4470
4571
46-func getKeyItemSupplier (item) = (item + "_supplier")
72+func getValueWinCount (user) = getNumberByKey(getKeyWinCount(user))
4773
4874
49-func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item))
75+func getKeyLoseCount (user) = (user + "_losecnt")
5076
5177
52-func getKeyBalanceSupplier (account) = (account + "_balance")
53-
54-
55-func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account))
56-
57-
58-let VOTERS = 3
59-
60-let QUORUM = 2
61-
62-let VOTING = "voting"
63-
64-let REVEAL = "reveal"
65-
66-let FEATURED = "featured"
67-
68-let DELISTED = "delisted"
69-
70-func getKeyCommit (item,user) = (((item + "_") + user) + "_commit")
71-
72-
73-func getValueCommit (item,user) = getStrByKey(getKeyCommit(item, user))
74-
75-
76-func getKeyCommitsCount (item) = (item + "_comcnt")
77-
78-
79-func getValueCommitsCount (item) = getNumberByKey(getKeyCommitsCount(item))
80-
81-
82-func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal")
83-
84-
85-func getValueReveal (item,user) = getStrByKey(getKeyReveal(item, user))
86-
87-
88-func getKeyItemStatus (item) = (item + "_status")
89-
90-
91-func getValueItemStatus (item) = getStrByKey(getKeyItemStatus(item))
92-
93-
94-func getKeyVoteCount (item,vote) = ((item + "_res:") + vote)
95-
96-
97-func getValueVoteCount (item,vote) = getNumberByKey(getKeyVoteCount(item, vote))
78+func getValueLoseCount (user) = getNumberByKey(getKeyLoseCount(user))
9879
9980
10081 @Callable(i)
101-func addItem (title,price,data) = {
102- let supplierAddress = toBase58String(i.caller.bytes)
103- let item = getKeyItem(supplierAddress, title)
104- if ((0 >= price))
105- then throw("purchase amount cannot be less than item price")
106- else if ((getValueItemSupplier(item) != NONE))
107- then throw("an item is already exists")
108- else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddress), DataEntry(getKeyItemPrice(item), price), DataEntry(getKeyItemData(item), data)])
82+func patent (x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6) = {
83+ let pmt = extract(i.payment)
84+ if (isDefined(pmt.assetId))
85+ then throw("can use WAVES only at the moment")
86+ else {
87+ let userAddress = toBase58String(i.caller.bytes)
88+ if ((pmt.amount != PRICE))
89+ then throw("purchase amount cannot be not equal to the price")
90+ else if (validateCoords(x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6))
91+ then throw("invalid coordinates order")
92+ else if ((getStrByKey(genKeyFromCoords(x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6)) != NONE))
93+ then throw("this patent is already exists")
94+ else WriteSet([DataEntry(genKeyFromCoords(x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6), userAddress)])
95+ }
10996 }
11097
11198
11299
113100 @Callable(i)
114-func purchase (item) = {
101+func buyPatent (x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6) = {
115102 let pmt = extract(i.payment)
116103 if (isDefined(pmt.assetId))
117104 then throw("can use WAVES only at the moment")
118105 else {
119106 let userAddress = toBase58String(i.caller.bytes)
120- let price = getValueItemPrice(item)
121- let supplierAddress = getValueItemSupplier(item)
122- if ((price > pmt.amount))
123- then throw("purchase amount cannot be less than item price")
124- else if ((pmt.amount > price))
125- then throw("purchase amount cannot be higher than item price")
126- else if ((supplierAddress == NONE))
127- then throw("supplier address does not exists")
128- else WriteSet([DataEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), DataEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))])
107+ let patentOwnerAddress = getStrByKey(genKeyFromCoords(x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6))
108+ if ((pmt.amount != PATENTPRICE))
109+ then throw("purchase amount cannot be not equal to the price")
110+ else if (validateCoords(x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6))
111+ then throw("invalid coordinates order")
112+ else if ((patentOwnerAddress == NONE))
113+ then throw("there is no such patent")
114+ else WriteSet([DataEntry(genKeyFromCoords(x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6), userAddress), DataEntry(getKeyBalanceUser(patentOwnerAddress), (getValueBalanceUser(patentOwnerAddress) + pmt.amount))])
129115 }
130116 }
131117
132118
133119
134120 @Callable(i)
135121 func withdraw () = {
136- let supplierAddress = toBase58String(i.caller.bytes)
137- let balance = getValueBalanceSupplier(supplierAddress)
122+ let userAddress = toBase58String(i.caller.bytes)
123+ let balance = getValueBalanceUser(userAddress)
138124 if ((0 >= balance))
139125 then throw("insufficient balance")
140- else ScriptResult(WriteSet([DataEntry(getKeyBalanceSupplier(supplierAddress), 0)]), TransferSet([ScriptTransfer(addressFromStringValue(supplierAddress), balance, unit)]))
126+ else ScriptResult(WriteSet([DataEntry(getKeyBalanceUser(userAddress), 0)]), TransferSet([ScriptTransfer(addressFromStringValue(userAddress), balance, unit)]))
141127 }
142128
143129
144130
145131 @Callable(i)
146-func voteCommit (item,hash) = {
147- let user = toBase58String(i.caller.bytes)
148- let commits = getValueCommitsCount(item)
149- let status = getValueItemStatus(item)
150- if ((commits > VOTERS))
151- then throw("reached max num of voters")
152- else if ((getValueCommit(item, user) != NONE))
153- then throw("user has already participated")
154- else if ((getValueItemSupplier(item) == NONE))
155- then throw("item does not exist")
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(getKeyCommitsCount(item), (commits + 1)), DataEntry(getKeyItemStatus(item), if ((commits == VOTERS))
161- then REVEAL
162- else VOTING)])
163- }
164-
165-
166-
167-@Callable(i)
168-func voteReveal (item,vote,salt) = {
169- let user = toBase58String(i.caller.bytes)
170- let status = getValueItemStatus(item)
171- let newVoteCount = (getValueVoteCount(item, vote) + 1)
172- if ((toBase58String(sha256(toBytes((vote + salt)))) != getValueCommit(item, user)))
173- then throw("reveal data is not valid")
174- else if ((VOTERS > getValueCommitsCount(item)))
175- then throw("max num of voters hasn't reached yet")
176- else if ((getValueReveal(item, user) != NONE))
177- then throw("user has already participated")
178- else if (if ((status != VOTING))
179- then (status != REVEAL)
180- else false)
181- then throw("wrong status")
182- else if (if ((vote != FEATURED))
183- then (vote != DELISTED)
184- else false)
185- then throw("wrong vote")
186- else if (if ((status == FEATURED))
187- then true
188- else (status == DELISTED))
189- then throw("vote has finished")
190- else WriteSet([DataEntry(getKeyReveal(item, user), vote), DataEntry(getKeyVoteCount(item, vote), newVoteCount), DataEntry(getKeyItemStatus(item), if ((newVoteCount >= QUORUM))
191- then vote
192- else REVEAL)])
132+func endGame (game,winner,loser) = {
133+ let oracleAddres = toBase58String(i.caller.bytes)
134+ if ((oracleAddres != ORACLE))
135+ then throw("only oracle can inform about games results")
136+ else if ((winner == loser))
137+ then throw("winner and loser must be different")
138+ else if ((getStrByKey(game) != NONE))
139+ then throw("this game has already been played")
140+ else WriteSet([DataEntry(game, (((winner + "-WIN;") + loser) + "-LOSE")), DataEntry(getKeyWinCount(winner), (getValueWinCount(winner) + 1)), DataEntry(getKeyLoseCount(loser), (getValueLoseCount(loser) + 1))])
193141 }
194142
195143

github/deemru/w8io/3ef1775 
57.78 ms