tx · 752eT2Co8GFow7ozvXL4xyUAWij8Y86tdqKofbUUvmQ1 3N1MvvKPNWqQ9JWYV1vWE84GnMKP3mENpSg: -0.01400000 Waves 2019.06.26 02:28 [558307] smart account 3N1MvvKPNWqQ9JWYV1vWE84GnMKP3mENpSg > SELF 0.00000000 Waves
{ "type": 13, "id": "752eT2Co8GFow7ozvXL4xyUAWij8Y86tdqKofbUUvmQ1", "fee": 1400000, "feeAssetId": null, "timestamp": 1561505355772, "version": 1, "sender": "3N1MvvKPNWqQ9JWYV1vWE84GnMKP3mENpSg", "senderPublicKey": "GBcKAM5muVn8dBji3B7ciEqt4XzrT4CBrAKXoTVfbw7", "proofs": [ "42aSVef2FVZ4hhpp5XLsWTnjq8G6pow4yELj1gbE1x4euogoaC8TcLEetkjSfpMsCwA37BegQYrRrxS5mGnQ5mz4" ], "script": "base64:AAIDAAAAAAAAAAAAAAAbAAAAAAROT05FAgAAAARub25lAAAAAAZWT1RFUlMAAAAAAAAAAAMAAAAABlFVT1JVTQAAAAAAAAAAAgAAAAAGVk9USU5HAgAAAAZ2b3RpbmcAAAAABlJFVkVBTAIAAAAGcmV2ZWFsAQAAAA5nZXROdW1iZXJCeUtleQAAAAEAAAADa2V5BAAAAANudW0EAAAAByRtYXRjaDAJAAQaAAAAAgUAAAAEdGhpcwUAAAADa2V5AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAANJbnQEAAAAAWEFAAAAByRtYXRjaDAFAAAAAWEAAAAAAAAAAAAFAAAAA251bQEAAAALZ2V0U3RyQnlLZXkAAAABAAAAA2tleQQAAAADc3RyBAAAAAckbWF0Y2gwCQAEHQAAAAIFAAAABHRoaXMFAAAAA2tleQMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAAGU3RyaW5nBAAAAAFhBQAAAAckbWF0Y2gwBQAAAAFhBQAAAAROT05FBQAAAANzdHIBAAAAD2dldEtleUl0ZW1QcmljZQAAAAEAAAAEaXRlbQkAASwAAAACBQAAAARpdGVtAgAAAAZ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VmFsdWVDb21taXQAAAACBQAAAARpdGVtBQAAAAR1c2VyBQAAAAROT05FCQAAAgAAAAECAAAAHVVzZXIgaGFzIGFscmVhZHkgcGFydGljaXBhdGVkAwkAAAAAAAACCQEAAAASZ2V0S2V5SXRlbVN1cHBsaWVyAAAAAQUAAAAEaXRlbQUAAAAETk9ORQkAAAIAAAABAgAAABNJdGVtIGRvZXMgbm90IGV4aXN0AwMJAQAAAAIhPQAAAAIFAAAABnN0YXR1cwUAAAAETk9ORQkBAAAAAiE9AAAAAgUAAAAGc3RhdHVzBQAAAAZWT1RJTkcHCQAAAgAAAAECAAAAFlZvdGluZyBpcyBub3QgcG9zc2libGUJAQAAAAhXcml0ZVNldAAAAAEJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAQAAAAxnZXRLZXlDb21taXQAAAACBQAAAARpdGVtBQAAAAR1c2VyBQAAAARoYXNoCQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACCQEAAAASZ2V0S2V5Q29tbWl0c0NvdW50AAAAAQUAAAAEaXRlbQkAAGQAAAACBQAAAAdjb21taXRzAAAAAAAAAAABCQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACCQEAAAAQZ2V0S2V5SXRlbVN0YXR1cwAAAAEFAAAABGl0ZW0DCQAAAAAAAAIFAAAAB2NvbW1pdHMFAAAABlZPVEVSUwUAAAAGUkVWRUFMBQAAAAZWT1RJTkcFAAAAA25pbAAAAAEAAAACdHgBAAAABnZlcmlmeQAAAAAJAAH0AAAAAwgFAAAAAnR4AAAACWJvZHlCeXRlcwkAAZEAAAACCAUAAAACdHgAAAAGcHJvb2ZzAAAAAAAAAAAACAUAAAACdHgAAAAPc2VuZGVyUHVibGljS2V5egI6wg==", "chainId": 84, "height": 558307, "spentComplexity": 0 } View: original | compacted Prev: BqFxuN1Eh7KdG6MYLp1B8ACeqaWWiXa6jXVyQvYw2xYH Next: EALXEC9wXp8w3Yb74H7jeuEBCvFbGG8hAxYPqGrTkYjr 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" | |
5 | 13 | ||
6 | 14 | func getNumberByKey (key) = { | |
7 | 15 | let num = match getInteger(this, key) { | |
55 | 63 | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
56 | 64 | ||
57 | 65 | ||
66 | + | func getKeyCommit (item,user) = (((item + "_") + user) + "_commit") | |
67 | + | ||
68 | + | ||
69 | + | func getValueCommit (item,user) = getStrByKey(getKeyCommit(item, user)) | |
70 | + | ||
71 | + | ||
72 | + | func getKeyCommitsCount (item) = (item + "_comcnt") | |
73 | + | ||
74 | + | ||
75 | + | func getValueCommitsCount (item) = getNumberByKey(getKeyCommitsCount(item)) | |
76 | + | ||
77 | + | ||
78 | + | func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal") | |
79 | + | ||
80 | + | ||
81 | + | func getValueReveal (item,user) = getStrByKey(getKeyReveal(item, user)) | |
82 | + | ||
83 | + | ||
84 | + | func getKeyItemStatus (item) = (item + "_status") | |
85 | + | ||
86 | + | ||
87 | + | func getValueItemStatus (item) = getStrByKey(getKeyItemStatus(item)) | |
88 | + | ||
89 | + | ||
90 | + | func getKeyVoteCount (item,vote) = ((item + "_res:") + vote) | |
91 | + | ||
92 | + | ||
93 | + | func getValueVoteCount (item,vote) = getNumberByKey(getKeyVoteCount(item, vote)) | |
94 | + | ||
95 | + | ||
58 | 96 | @Callable(i) | |
59 | 97 | func addItem (title,price,data) = { | |
60 | 98 | let supplierAddress = toBase58String(i.caller.bytes) | |
99 | 137 | } | |
100 | 138 | ||
101 | 139 | ||
140 | + | ||
141 | + | @Callable(i) | |
142 | + | func voteCommit (item,hash) = { | |
143 | + | let user = toBase58String(i.caller.bytes) | |
144 | + | let commits = getValueCommitsCount(item) | |
145 | + | let status = getValueItemStatus(item) | |
146 | + | if ((commits >= VOTERS)) | |
147 | + | then throw("Reached max numbers of voters") | |
148 | + | else if ((getValueCommit(item, user) != NONE)) | |
149 | + | then throw("User has already participated") | |
150 | + | else if ((getKeyItemSupplier(item) == NONE)) | |
151 | + | then throw("Item does not exist") | |
152 | + | else if (if ((status != NONE)) | |
153 | + | then (status != VOTING) | |
154 | + | else false) | |
155 | + | then throw("Voting is not possible") | |
156 | + | else WriteSet([DataEntry(getKeyCommit(item, user), hash), DataEntry(getKeyCommitsCount(item), (commits + 1)), DataEntry(getKeyItemStatus(item), if ((commits == VOTERS)) | |
157 | + | then REVEAL | |
158 | + | else VOTING)]) | |
159 | + | } | |
160 | + | ||
161 | + | ||
102 | 162 | @Verifier(tx) | |
103 | 163 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
104 | 164 |
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" | |
5 | 13 | ||
6 | 14 | func getNumberByKey (key) = { | |
7 | 15 | let num = match getInteger(this, key) { | |
8 | 16 | case a: Int => | |
9 | 17 | a | |
10 | 18 | case _ => | |
11 | 19 | 0 | |
12 | 20 | } | |
13 | 21 | num | |
14 | 22 | } | |
15 | 23 | ||
16 | 24 | ||
17 | 25 | func getStrByKey (key) = { | |
18 | 26 | let str = match getString(this, key) { | |
19 | 27 | case a: String => | |
20 | 28 | a | |
21 | 29 | case _ => | |
22 | 30 | NONE | |
23 | 31 | } | |
24 | 32 | str | |
25 | 33 | } | |
26 | 34 | ||
27 | 35 | ||
28 | 36 | func getKeyItemPrice (item) = (item + "_price") | |
29 | 37 | ||
30 | 38 | ||
31 | 39 | func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item)) | |
32 | 40 | ||
33 | 41 | ||
34 | 42 | func getKeyUserItemCounter (user,item) = ((item + "_user") + "_cnt") | |
35 | 43 | ||
36 | 44 | ||
37 | 45 | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) | |
38 | 46 | ||
39 | 47 | ||
40 | 48 | func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title))))) | |
41 | 49 | ||
42 | 50 | ||
43 | 51 | func getKeyItemData (item) = (item + "_data") | |
44 | 52 | ||
45 | 53 | ||
46 | 54 | func getKeyItemSupplier (item) = (item + "_owner") | |
47 | 55 | ||
48 | 56 | ||
49 | 57 | func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item)) | |
50 | 58 | ||
51 | 59 | ||
52 | 60 | func getKeyBalanceSupplier (account) = (account + "_balance") | |
53 | 61 | ||
54 | 62 | ||
55 | 63 | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
56 | 64 | ||
57 | 65 | ||
66 | + | func getKeyCommit (item,user) = (((item + "_") + user) + "_commit") | |
67 | + | ||
68 | + | ||
69 | + | func getValueCommit (item,user) = getStrByKey(getKeyCommit(item, user)) | |
70 | + | ||
71 | + | ||
72 | + | func getKeyCommitsCount (item) = (item + "_comcnt") | |
73 | + | ||
74 | + | ||
75 | + | func getValueCommitsCount (item) = getNumberByKey(getKeyCommitsCount(item)) | |
76 | + | ||
77 | + | ||
78 | + | func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal") | |
79 | + | ||
80 | + | ||
81 | + | func getValueReveal (item,user) = getStrByKey(getKeyReveal(item, user)) | |
82 | + | ||
83 | + | ||
84 | + | func getKeyItemStatus (item) = (item + "_status") | |
85 | + | ||
86 | + | ||
87 | + | func getValueItemStatus (item) = getStrByKey(getKeyItemStatus(item)) | |
88 | + | ||
89 | + | ||
90 | + | func getKeyVoteCount (item,vote) = ((item + "_res:") + vote) | |
91 | + | ||
92 | + | ||
93 | + | func getValueVoteCount (item,vote) = getNumberByKey(getKeyVoteCount(item, vote)) | |
94 | + | ||
95 | + | ||
58 | 96 | @Callable(i) | |
59 | 97 | func addItem (title,price,data) = { | |
60 | 98 | let supplierAddress = toBase58String(i.caller.bytes) | |
61 | 99 | let item = getKeyItem(supplierAddress, title) | |
62 | 100 | if ((0 >= price)) | |
63 | 101 | then throw("Purchase amount cannot be less that item price") | |
64 | 102 | else if ((getValueItemSupplier(item) != NONE)) | |
65 | 103 | then throw("This item already exist") | |
66 | 104 | else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddress), DataEntry(getKeyItemPrice(item), price), DataEntry(getKeyItemData(item), data)]) | |
67 | 105 | } | |
68 | 106 | ||
69 | 107 | ||
70 | 108 | ||
71 | 109 | @Callable(i) | |
72 | 110 | func purchase (item) = { | |
73 | 111 | let pmt = extract(i.payment) | |
74 | 112 | if (isDefined(pmt.assetId)) | |
75 | 113 | then throw("Waves token only at this moment") | |
76 | 114 | else { | |
77 | 115 | let userAddress = toBase58String(i.caller.bytes) | |
78 | 116 | let price = getValueItemPrice(item) | |
79 | 117 | let supplierAddress = getValueItemSupplier(item) | |
80 | 118 | if ((price > pmt.amount)) | |
81 | 119 | then throw("Purchase amount can not be less than item price") | |
82 | 120 | else if ((pmt.amount > price)) | |
83 | 121 | then throw("Purchase amount can not be higher than item price") | |
84 | 122 | else if ((supplierAddress == NONE)) | |
85 | 123 | then throw("Supplier does not exist") | |
86 | 124 | else WriteSet([DataEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), DataEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))]) | |
87 | 125 | } | |
88 | 126 | } | |
89 | 127 | ||
90 | 128 | ||
91 | 129 | ||
92 | 130 | @Callable(i) | |
93 | 131 | func withdraw () = { | |
94 | 132 | let supplierAddress = toBase58String(i.caller.bytes) | |
95 | 133 | let balance = getValueBalanceSupplier(supplierAddress) | |
96 | 134 | if ((0 >= balance)) | |
97 | 135 | then throw("Insufficient Balance") | |
98 | 136 | else ScriptResult(WriteSet([DataEntry(getKeyBalanceSupplier(supplierAddress), 0)]), TransferSet([ScriptTransfer(addressFromStringValue(supplierAddress), balance, unit)])) | |
99 | 137 | } | |
100 | 138 | ||
101 | 139 | ||
140 | + | ||
141 | + | @Callable(i) | |
142 | + | func voteCommit (item,hash) = { | |
143 | + | let user = toBase58String(i.caller.bytes) | |
144 | + | let commits = getValueCommitsCount(item) | |
145 | + | let status = getValueItemStatus(item) | |
146 | + | if ((commits >= VOTERS)) | |
147 | + | then throw("Reached max numbers of voters") | |
148 | + | else if ((getValueCommit(item, user) != NONE)) | |
149 | + | then throw("User has already participated") | |
150 | + | else if ((getKeyItemSupplier(item) == NONE)) | |
151 | + | then throw("Item does not exist") | |
152 | + | else if (if ((status != NONE)) | |
153 | + | then (status != VOTING) | |
154 | + | else false) | |
155 | + | then throw("Voting is not possible") | |
156 | + | else WriteSet([DataEntry(getKeyCommit(item, user), hash), DataEntry(getKeyCommitsCount(item), (commits + 1)), DataEntry(getKeyItemStatus(item), if ((commits == VOTERS)) | |
157 | + | then REVEAL | |
158 | + | else VOTING)]) | |
159 | + | } | |
160 | + | ||
161 | + | ||
102 | 162 | @Verifier(tx) | |
103 | 163 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
104 | 164 |
github/deemru/w8io/169f3d6 55.46 ms ◑