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:AAIDAAAAAAAAAAAAAAARAAAAAAVQUklDRQAAAAAABfXhAAAAAAALUEFURU5UUFJJQ0UAAAAAAAvrwgAAAAAABk9SQUNMRQIAAAAGT1JBQ0xFAAAAAANXSU4CAAAAA1dJTgAAAAAETE9TRQIAAAAETE9TRQAAAAAETk9ORQIAAAAEbm9uZQEAAAAOZ2V0TnVtYmVyQnlLZXkAAAABAAAAA2tleQQAAAADbnVtBAAAAAckbWF0Y2gwCQAEGgAAAAIFAAAABHRoaXMFAAAAA2tleQMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAADSW50BAAAAAFhBQAAAAckbWF0Y2gwBQAAAAFhAAAAAAAAAAAABQAAAANudW0BAAAAC2dldFN0ckJ5S2V5AAAAAQAAAANrZXkEAAAAA3N0cgQAAAAHJG1hdGNoMAkABB0AAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAABlN0cmluZwQAAAABYQUAAAAHJG1hdGNoMAUAAAABYQUAAAAETk9ORQUAAAADc3RyAQAAABF2YWxpZGF0ZVR3b0Nvb3JkcwAAAAQAAAACeDE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IFAAAABWxvc2VyCQAAAgAAAAECAAAAIndpbm5lciBhbmQgbG9zZXIgbXVzdCBiZSBkaWZmZXJlbnQDCQEAAAACIT0AAAACCQEAAAALZ2V0U3RyQnlLZXkAAAABBQAAAARnYW1lBQAAAAROT05FCQAAAgAAAAECAAAAIXRoaXMgZ2FtZSBoYXMgYWxyZWFkeSBiZWVuIHBsYXllZAkBAAAACFdyaXRlU2V0AAAAAQkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgUAAAAEZ2FtZQkAASwAAAACCQABLAAAAAIJAAEsAAAAAgUAAAAGd2lubmVyAgAAAAUtV0lOOwUAAAAFbG9zZXICAAAABS1MT1NFCQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACCQEAAAAOZ2V0S2V5V2luQ291bnQAAAABBQAAAAZ3aW5uZXIJAABkAAAAAgkBAAAAEGdldFZhbHVlV2luQ291bnQAAAABBQAAAAZ3aW5uZXIAAAAAAAAAAAEJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAQAAAA9nZXRLZXlMb3NlQ291bnQAAAABBQAAAAVsb3NlcgkAAGQAAAACCQEAAAARZ2V0VmFsdWVMb3NlQ291bnQAAAABBQAAAAVsb3NlcgAAAAAAAAAAAQUAAAADbmlsAAAAAMX/6Ns=", "chainId": 84, "height": 666824, "spentComplexity": 0 } View: original | compacted Prev: 6psbdMeFfJR6eAioCQJUxPHHKkWB91G7cpW64MxpxPyM Next: 3v3mSXL11AzLcPvND97Fu21HynTi13rj5LPV7qngSAJy Diff:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# 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 | + | ||
4 | 14 | let NONE = "none" | |
5 | 15 | ||
6 | 16 | func getNumberByKey (key) = { | |
25 | 35 | } | |
26 | 36 | ||
27 | 37 | ||
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 | |
29 | 45 | ||
30 | 46 | ||
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 | |
32 | 58 | ||
33 | 59 | ||
34 | - | func | |
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)) | |
35 | 61 | ||
36 | 62 | ||
37 | - | func | |
63 | + | func getKeyBalanceUser (account) = (account + "_balance") | |
38 | 64 | ||
39 | 65 | ||
40 | - | func | |
66 | + | func getValueBalanceUser (account) = getNumberByKey(getKeyBalanceUser(account)) | |
41 | 67 | ||
42 | 68 | ||
43 | - | func | |
69 | + | func getKeyWinCount (user) = (user + "_wincnt") | |
44 | 70 | ||
45 | 71 | ||
46 | - | func | |
72 | + | func getValueWinCount (user) = getNumberByKey(getKeyWinCount(user)) | |
47 | 73 | ||
48 | 74 | ||
49 | - | func | |
75 | + | func getKeyLoseCount (user) = (user + "_losecnt") | |
50 | 76 | ||
51 | 77 | ||
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)) | |
98 | 79 | ||
99 | 80 | ||
100 | 81 | @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 | + | } | |
109 | 96 | } | |
110 | 97 | ||
111 | 98 | ||
112 | 99 | ||
113 | 100 | @Callable(i) | |
114 | - | func | |
101 | + | func buyPatent (x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6) = { | |
115 | 102 | let pmt = extract(i.payment) | |
116 | 103 | if (isDefined(pmt.assetId)) | |
117 | 104 | then throw("can use WAVES only at the moment") | |
118 | 105 | else { | |
119 | 106 | 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))]) | |
129 | 115 | } | |
130 | 116 | } | |
131 | 117 | ||
133 | 119 | ||
134 | 120 | @Callable(i) | |
135 | 121 | func withdraw () = { | |
136 | - | let | |
137 | - | let balance = | |
122 | + | let userAddress = toBase58String(i.caller.bytes) | |
123 | + | let balance = getValueBalanceUser(userAddress) | |
138 | 124 | if ((0 >= balance)) | |
139 | 125 | then throw("insufficient balance") | |
140 | - | else ScriptResult(WriteSet([DataEntry( | |
126 | + | else ScriptResult(WriteSet([DataEntry(getKeyBalanceUser(userAddress), 0)]), TransferSet([ScriptTransfer(addressFromStringValue(userAddress), balance, unit)])) | |
141 | 127 | } | |
142 | 128 | ||
143 | 129 | ||
144 | 130 | ||
145 | 131 | @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))]) | |
193 | 141 | } | |
194 | 142 | ||
195 | 143 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# 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 | + | ||
4 | 14 | let NONE = "none" | |
5 | 15 | ||
6 | 16 | func getNumberByKey (key) = { | |
7 | 17 | let num = match getInteger(this, key) { | |
8 | 18 | case a: Int => | |
9 | 19 | a | |
10 | 20 | case _ => | |
11 | 21 | 0 | |
12 | 22 | } | |
13 | 23 | num | |
14 | 24 | } | |
15 | 25 | ||
16 | 26 | ||
17 | 27 | func getStrByKey (key) = { | |
18 | 28 | let str = match getString(this, key) { | |
19 | 29 | case a: String => | |
20 | 30 | a | |
21 | 31 | case _ => | |
22 | 32 | NONE | |
23 | 33 | } | |
24 | 34 | str | |
25 | 35 | } | |
26 | 36 | ||
27 | 37 | ||
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 | |
29 | 45 | ||
30 | 46 | ||
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 | |
32 | 58 | ||
33 | 59 | ||
34 | - | func | |
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)) | |
35 | 61 | ||
36 | 62 | ||
37 | - | func | |
63 | + | func getKeyBalanceUser (account) = (account + "_balance") | |
38 | 64 | ||
39 | 65 | ||
40 | - | func | |
66 | + | func getValueBalanceUser (account) = getNumberByKey(getKeyBalanceUser(account)) | |
41 | 67 | ||
42 | 68 | ||
43 | - | func | |
69 | + | func getKeyWinCount (user) = (user + "_wincnt") | |
44 | 70 | ||
45 | 71 | ||
46 | - | func | |
72 | + | func getValueWinCount (user) = getNumberByKey(getKeyWinCount(user)) | |
47 | 73 | ||
48 | 74 | ||
49 | - | func | |
75 | + | func getKeyLoseCount (user) = (user + "_losecnt") | |
50 | 76 | ||
51 | 77 | ||
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)) | |
98 | 79 | ||
99 | 80 | ||
100 | 81 | @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 | + | } | |
109 | 96 | } | |
110 | 97 | ||
111 | 98 | ||
112 | 99 | ||
113 | 100 | @Callable(i) | |
114 | - | func | |
101 | + | func buyPatent (x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6) = { | |
115 | 102 | let pmt = extract(i.payment) | |
116 | 103 | if (isDefined(pmt.assetId)) | |
117 | 104 | then throw("can use WAVES only at the moment") | |
118 | 105 | else { | |
119 | 106 | 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))]) | |
129 | 115 | } | |
130 | 116 | } | |
131 | 117 | ||
132 | 118 | ||
133 | 119 | ||
134 | 120 | @Callable(i) | |
135 | 121 | func withdraw () = { | |
136 | - | let | |
137 | - | let balance = | |
122 | + | let userAddress = toBase58String(i.caller.bytes) | |
123 | + | let balance = getValueBalanceUser(userAddress) | |
138 | 124 | if ((0 >= balance)) | |
139 | 125 | then throw("insufficient balance") | |
140 | - | else ScriptResult(WriteSet([DataEntry( | |
126 | + | else ScriptResult(WriteSet([DataEntry(getKeyBalanceUser(userAddress), 0)]), TransferSet([ScriptTransfer(addressFromStringValue(userAddress), balance, unit)])) | |
141 | 127 | } | |
142 | 128 | ||
143 | 129 | ||
144 | 130 | ||
145 | 131 | @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))]) | |
193 | 141 | } | |
194 | 142 | ||
195 | 143 |
github/deemru/w8io/169f3d6 53.62 ms ◑