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