tx · AwG6a8kcj9emHZ9zD2Z2c4FDSZNRkf7jse5LBEhkV8yD 3Muk1sJxqTRQUdoV7YMZQftoSB2UQbmMzZJ: -0.01400000 Waves 2019.06.27 13:07 [560397] smart account 3Muk1sJxqTRQUdoV7YMZQftoSB2UQbmMzZJ > SELF 0.00000000 Waves
{ "type": 13, "id": "AwG6a8kcj9emHZ9zD2Z2c4FDSZNRkf7jse5LBEhkV8yD", "fee": 1400000, "feeAssetId": null, "timestamp": 1561630058176, "version": 1, "sender": "3Muk1sJxqTRQUdoV7YMZQftoSB2UQbmMzZJ", "senderPublicKey": "BRZbA97MFrfkt23NfC8j9hncCP4riz5MBgPe8xgE8ABD", "proofs": [ "5uir6SjXHp4mwMCurwdGiH6DDy8A2wxzFD357bEPsohV166vWz1JpSnCa2KB56YnXERs38f2penkSAWKGVvVNi3f" ], "script": "base64:AAIDAAAAAAAAAAAAAAAdAAAAAAROT05FAgAAAARub25lAAAAAAZWT1RFUlMAAAAAAAAAAAMAAAAABlFVT1JVTQAAAAAAAAAAAgAAAAAGVk9USU5HAgAAAAZ2b3RpbmcAAAAABlJFVkVBTAIAAAAGcmV2ZWFsAAAAAAhGRUFUVVJFRAIAAAAIZmVhdHVyZWQAAAAACERFTElTVEVEAgAAAAhkZWxpc3RlZAEAAAAOZ2V0TnVtYmVyQnlLZXkAAAABAAAAA2tleQQAAAADbnVtBAAAAAckbWF0Y2gwCQAEGgAAAAIFAAAABHRoaXMFAAAAA2tleQMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAADSW50BAAAAAFhBQAAAAckbWF0Y2gwBQAAAAFhAAAAAAAAAAAABQAAAANudW0BAAAAC2dldFN0ckJ5S2V5AAAAAQAAAANrZXkEAAAAA3N0cgQAAAAHJG1hdGNoMAkABB0AAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAABlN0cmluZwQAAAABYQUAAAAHJG1hdGNoMAUAAAABYQUAAAAETk9ORQUAAAADc3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QAAZAAAAAIFAAAAB2NvbW1pdHMAAAAAAAAAAAEJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAQAAABBnZXRLZXlJdGVtU3RhdHVzAAAAAQUAAAAEaXRlbQMJAAAAAAAAAgUAAAAHY29tbWl0cwUAAAAGVk9URVJTBQAAAAZSRVZFQUwFAAAABlZPVElORwUAAAADbmlsAAAAAWkBAAAACHdpdGhkcmF3AAAAAAQAAAAPc3VwcGxpZXJBZGRyZXNzCQACWAAAAAEICAUAAAABaQAAAAZjYWxsZXIAAAAFYnl0ZXMEAAAAB2JhbGFuY2UJAQAAABdnZXRWYWx1ZUJhbGFuY2VTdXBwbGllcgAAAAEFAAAAD3N1cHBsaWVyQWRkcmVzcwMJAABnAAAAAgAAAAAAAAAAAAUAAAAHYmFsYW5jZQkAAAIAAAABAgAAABRpbnN1ZmZpY2llbnQgYmFsYW5jZQkBAAAADFNjcmlwdFJlc3VsdAAAAAIJAQAAAAhXcml0ZVNldAAAAAEJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAQAAABVnZXRLZXlCYWxhbmNlU3VwcGxpZXIAAAABBQAAAA9zdXBwbGllckFkZHJlc3MAAAAAAAAAAAAFAAAAA25pbAkBAAAAC1RyYW5zZmVyU2V0AAAAAQkABEwAAAACCQEAAAAOU2NyaXB0VHJhbnNmZXIAAAADCQEAAAAcQGV4dHJVc2VyKGFkZHJlc3NGcm9tU3RyaW5nKQAAAAEFAAAAD3N1cHBsaWVyQWRkcmVzcwUAAAAHYmFsYW5jZQUAAAAEdW5pdAUAAAADbmlsAAAAAKN4mBA=", "chainId": 84, "height": 560397, "spentComplexity": 0 } View: original | compacted Prev: 3GiKiUgi3S3fuRvXDodc57LZrhJbnEFTxXUeqKiG7YG6 Next: DD4JBJWQ5cLm96hbTUQjwWoMfmSom3VUKAtZG6yfNomq Diff:
Old | New | Differences | |
---|---|---|---|
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let NONE = "none" | |
5 | + | ||
6 | + | let VOTERS = 3 | |
7 | + | ||
8 | + | let QUORUM = 2 | |
9 | + | ||
10 | + | let VOTING = "voting" | |
11 | + | ||
12 | + | let REVEAL = "reveal" | |
13 | + | ||
14 | + | let FEATURED = "featured" | |
15 | + | ||
16 | + | let DELISTED = "delisted" | |
5 | 17 | ||
6 | 18 | func getNumberByKey (key) = { | |
7 | 19 | let num = match getInteger(this, key) { | |
55 | 67 | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
56 | 68 | ||
57 | 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 getValurReveal (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)) | |
98 | + | ||
99 | + | ||
58 | 100 | @Callable(i) | |
59 | 101 | func addItem (title,price,data) = { | |
60 | 102 | let supplierAddress = toBase58String(i.caller.bytes) | |
90 | 132 | ||
91 | 133 | ||
92 | 134 | @Callable(i) | |
135 | + | func voteCommit (item,hash) = { | |
136 | + | let user = toBase58String(i.caller.bytes) | |
137 | + | let commits = getValueCommitsCount(item) | |
138 | + | let status = getValueItemStatus(item) | |
139 | + | if ((commits >= VOTERS)) | |
140 | + | then throw("reached max num of voters") | |
141 | + | else if ((getValueCommit(item, user) != NONE)) | |
142 | + | then throw("user has already participated") | |
143 | + | else if ((getKeyItemSupplier(item) == NONE)) | |
144 | + | then throw("item does not exist") | |
145 | + | else if (if ((status != NONE)) | |
146 | + | then (status != VOTING) | |
147 | + | else false) | |
148 | + | then throw("voting is not possible") | |
149 | + | else WriteSet([DataEntry(getKeyCommit(item, user), hash), DataEntry(getKeyCommitsCount(item), (commits + 1)), DataEntry(getKeyItemStatus(item), if ((commits == VOTERS)) | |
150 | + | then REVEAL | |
151 | + | else VOTING)]) | |
152 | + | } | |
153 | + | ||
154 | + | ||
155 | + | ||
156 | + | @Callable(i) | |
93 | 157 | func withdraw () = { | |
94 | 158 | let supplierAddress = toBase58String(i.caller.bytes) | |
95 | 159 | let balance = getValueBalanceSupplier(supplierAddress) |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let NONE = "none" | |
5 | + | ||
6 | + | let VOTERS = 3 | |
7 | + | ||
8 | + | let QUORUM = 2 | |
9 | + | ||
10 | + | let VOTING = "voting" | |
11 | + | ||
12 | + | let REVEAL = "reveal" | |
13 | + | ||
14 | + | let FEATURED = "featured" | |
15 | + | ||
16 | + | let DELISTED = "delisted" | |
5 | 17 | ||
6 | 18 | func getNumberByKey (key) = { | |
7 | 19 | let num = match getInteger(this, key) { | |
8 | 20 | case a: Int => | |
9 | 21 | a | |
10 | 22 | case _ => | |
11 | 23 | 0 | |
12 | 24 | } | |
13 | 25 | num | |
14 | 26 | } | |
15 | 27 | ||
16 | 28 | ||
17 | 29 | func getStrByKey (key) = { | |
18 | 30 | let str = match getString(this, key) { | |
19 | 31 | case a: String => | |
20 | 32 | a | |
21 | 33 | case _ => | |
22 | 34 | NONE | |
23 | 35 | } | |
24 | 36 | str | |
25 | 37 | } | |
26 | 38 | ||
27 | 39 | ||
28 | 40 | func getKeyItemPrice (item) = (item + "_price") | |
29 | 41 | ||
30 | 42 | ||
31 | 43 | func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item)) | |
32 | 44 | ||
33 | 45 | ||
34 | 46 | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt") | |
35 | 47 | ||
36 | 48 | ||
37 | 49 | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) | |
38 | 50 | ||
39 | 51 | ||
40 | 52 | func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title))))) | |
41 | 53 | ||
42 | 54 | ||
43 | 55 | func getKeyItemData (item) = (item + "_data") | |
44 | 56 | ||
45 | 57 | ||
46 | 58 | func getKeyItemSupplier (item) = (item + "_owner") | |
47 | 59 | ||
48 | 60 | ||
49 | 61 | func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item)) | |
50 | 62 | ||
51 | 63 | ||
52 | 64 | func getKeyBalanceSupplier (account) = (account + "_balance") | |
53 | 65 | ||
54 | 66 | ||
55 | 67 | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
56 | 68 | ||
57 | 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 getValurReveal (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)) | |
98 | + | ||
99 | + | ||
58 | 100 | @Callable(i) | |
59 | 101 | func addItem (title,price,data) = { | |
60 | 102 | let supplierAddress = toBase58String(i.caller.bytes) | |
61 | 103 | let item = getKeyItem(supplierAddress, title) | |
62 | 104 | if ((0 >= price)) | |
63 | 105 | then throw("purchase amount cannot be less than item price") | |
64 | 106 | else if ((getValueItemSupplier(item) != NONE)) | |
65 | 107 | then throw("an item is already exist") | |
66 | 108 | else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddress), DataEntry(getKeyItemPrice(item), price), DataEntry(getKeyItemData(item), data)]) | |
67 | 109 | } | |
68 | 110 | ||
69 | 111 | ||
70 | 112 | ||
71 | 113 | @Callable(i) | |
72 | 114 | func purchase (item) = { | |
73 | 115 | let pmt = extract(i.payment) | |
74 | 116 | if (isDefined(pmt.assetId)) | |
75 | 117 | then throw("WAVES tokens only at the moment") | |
76 | 118 | else { | |
77 | 119 | let userAddress = toBase58String(i.caller.bytes) | |
78 | 120 | let price = getValueItemPrice(item) | |
79 | 121 | let supplierAddress = getValueItemSupplier(item) | |
80 | 122 | if ((price > pmt.amount)) | |
81 | 123 | then throw("purchase amount cannot be less than item price") | |
82 | 124 | else if ((pmt.amount > price)) | |
83 | 125 | then throw("purchase amount cannot be higher than item price") | |
84 | 126 | else if ((supplierAddress == NONE)) | |
85 | 127 | then throw("supplier does not exist") | |
86 | 128 | else WriteSet([DataEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), DataEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))]) | |
87 | 129 | } | |
88 | 130 | } | |
89 | 131 | ||
90 | 132 | ||
91 | 133 | ||
92 | 134 | @Callable(i) | |
135 | + | func voteCommit (item,hash) = { | |
136 | + | let user = toBase58String(i.caller.bytes) | |
137 | + | let commits = getValueCommitsCount(item) | |
138 | + | let status = getValueItemStatus(item) | |
139 | + | if ((commits >= VOTERS)) | |
140 | + | then throw("reached max num of voters") | |
141 | + | else if ((getValueCommit(item, user) != NONE)) | |
142 | + | then throw("user has already participated") | |
143 | + | else if ((getKeyItemSupplier(item) == NONE)) | |
144 | + | then throw("item does not exist") | |
145 | + | else if (if ((status != NONE)) | |
146 | + | then (status != VOTING) | |
147 | + | else false) | |
148 | + | then throw("voting is not possible") | |
149 | + | else WriteSet([DataEntry(getKeyCommit(item, user), hash), DataEntry(getKeyCommitsCount(item), (commits + 1)), DataEntry(getKeyItemStatus(item), if ((commits == VOTERS)) | |
150 | + | then REVEAL | |
151 | + | else VOTING)]) | |
152 | + | } | |
153 | + | ||
154 | + | ||
155 | + | ||
156 | + | @Callable(i) | |
93 | 157 | func withdraw () = { | |
94 | 158 | let supplierAddress = toBase58String(i.caller.bytes) | |
95 | 159 | let balance = getValueBalanceSupplier(supplierAddress) | |
96 | 160 | if ((0 >= balance)) | |
97 | 161 | then throw("insufficient balance") | |
98 | 162 | else ScriptResult(WriteSet([DataEntry(getKeyBalanceSupplier(supplierAddress), 0)]), TransferSet([ScriptTransfer(addressFromStringValue(supplierAddress), balance, unit)])) | |
99 | 163 | } | |
100 | 164 | ||
101 | 165 |
github/deemru/w8io/169f3d6 29.49 ms ◑