tx · DwFK241mEgQAXuVhGhBdwJkQdwmeZ1X8F3iTQ4RvM2uu 3MpjwMAGCaNqNFRa34foE5sTfV6zb76bYja: -0.01000010 Waves 2021.07.07 16:25 [1603236] smart account 3MpjwMAGCaNqNFRa34foE5sTfV6zb76bYja > SELF 0.00000000 Waves
{ "type": 13, "id": "DwFK241mEgQAXuVhGhBdwJkQdwmeZ1X8F3iTQ4RvM2uu", "fee": 1000010, "feeAssetId": null, "timestamp": 1625664396862, "version": 2, "chainId": 84, "sender": "3MpjwMAGCaNqNFRa34foE5sTfV6zb76bYja", "senderPublicKey": "7Cy4wXHvgCRHP6MMhu9tTdayLHr9P9Dc342DVcCoCPzm", "proofs": [ "2eubo4X9P3Y8SPKtkit4cX83XTknwLgLiGpP2tfeC5KdVf6VZtJRxmC7vkUZefV61ci7zHYE5AApZ2JHR2BhcDiT" ], "script": "base64:AAIFAAAAAAAAAZYIAhIECgIICBoMCgJhMRIGVk9URVJTGgwKAmEyEgZWT1RJTkcaDAoCYTMSBlJFVkVBTBoKCgJhNBIETk9ORRoUCgJhNRIOZ2V0TnVtYmVyQnlLZXkaCQoCYTYSA2tleRoJCgJhNxIDbnVtGg0KAmE4EgckbWF0Y2gwGgcKAmE5EgFhGhEKAmIxEgtnZXRTdHJCeUtleRoJCgJiMhIDc3RyGhgKAmIzEhJnZXRLZXlJdGVtU3VwcGxpZXIaCgoCYjQSBGl0ZW0aEgoCYjUSDGdldEtleUNvbW1pdBoKCgJiNhIEdXNlchoUCgJiNxIOZ2V0VmFsdWVDb21taXQaGAoCYjgSEmdldEtleUNvbW1pdHNDb3VudBoaCgJiORIUZ2V0VmFsdWVDb21taXRzQ291bnQaFgoCYzESEGdldEtleUl0ZW1TdGF0dXMaGAoCYzISEmdldFZhbHVlSXRlbVN0YXR1cxoHCgJjMxIBaRoKCgJjNBIEaGFzaBoNCgJjNRIHY29tbWl0cxoMCgJjNhIGc3RhdHVzAAAADQAAAAACYTEAAAAAAAAAAAMAAAAAAmEyA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AACYTEJAAACAAAAAQIAAAAtb3NpxIVnbmnEmXRvIG1ha3N5bWFuxIUgbGljemLEmSBnxYJvc3VqxIVjeWNoAwkBAAAAAiE9AAAAAgkBAAAAAmI3AAAAAgUAAAACYjQFAAAAAmI2BQAAAAJhNAkAAAIAAAABAgAAABl1xbx0eWtvd25payBqdcW8IGfFgm9zdWplAwkAAAAAAAACCQEAAAACYjMAAAABBQAAAAJiNAUAAAACYTQJAAACAAAAAQIAAAAbbmllIGlzdG5pZWplIHRha2kgcHJ6ZWRtaW90AwMJAQAAAAIhPQAAAAIFAAAAAmM2BQAAAAJhNAkBAAAAAiE9AAAAAgUAAAACYzYFAAAAAmEyBwkAAAIAAAABAgAAAB1nxYJvc293YW5pZSBuaWUgamVzdCBtb8W8bGl3ZQkABEwAAAACCQEAAAALU3RyaW5nRW50cnkAAAACCQEAAAACYjUAAAACBQAAAAJiNAUAAAACYjYFAAAAAmM0CQAETAAAAAIJAQAAAAxJbnRlZ2VyRW50cnkAAAACCQEAAAACYjgAAAABBQAAAAJiNAkAAGQAAAACBQAAAAJjNQAAAAAAAAAAAQkABEwAAAACCQEAAAALU3RyaW5nRW50cnkAAAACCQEAAAACYzEAAAABBQAAAAJiNAMJAAAAAAAAAgUAAAACYzUFAAAAAmExBQAAAAJhMwUAAAACYTIFAAAAA25pbAAAAABVf4Sj", "height": 1603236, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 4CjRN7imG9WC5doaVq3ZMiJGGHKcUTHEqNNRyp5Ve5yY Next: 8YVQTvj68zepSUv9UznKyuNaQGYJYwQPRxwvoDivMJA Diff:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | + | let VOTERS = 3 | |
5 | + | ||
6 | + | let VOTING = "voting" | |
7 | + | ||
8 | + | let REVEAL = "reveal" | |
9 | + | ||
4 | 10 | let NONE = "none" | |
5 | 11 | ||
6 | 12 | func getNumberByKey (key) = { | |
25 | 31 | } | |
26 | 32 | ||
27 | 33 | ||
28 | - | func getKeyItemPrice (item) = (item + "_price") | |
29 | - | ||
30 | - | ||
31 | - | func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item)) | |
32 | - | ||
33 | - | ||
34 | - | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt") | |
35 | - | ||
36 | - | ||
37 | - | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) | |
38 | - | ||
39 | - | ||
40 | - | func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title))))) | |
41 | - | ||
42 | - | ||
43 | - | func getKeyItemData (item) = (item + "_data") | |
44 | - | ||
45 | - | ||
46 | 34 | func getKeyItemSupplier (item) = (item + "_data") | |
47 | 35 | ||
48 | 36 | ||
49 | - | func | |
37 | + | func getKeyCommit (item,user) = (((item + "_") + user) + "_commit") | |
50 | 38 | ||
51 | 39 | ||
52 | - | func | |
40 | + | func getValueCommit (item,user) = getStrByKey(getKeyCommit(item, user)) | |
53 | 41 | ||
54 | 42 | ||
55 | - | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
43 | + | func getKeyCommitsCount (item) = (item + "_comcnt") | |
44 | + | ||
45 | + | ||
46 | + | func getValueCommitsCount (item) = getNumberByKey(getKeyCommitsCount(item)) | |
47 | + | ||
48 | + | ||
49 | + | func getKeyItemStatus (item) = (item + "_status") | |
50 | + | ||
51 | + | ||
52 | + | func getValueItemStatus (item) = getStrByKey(getKeyItemStatus(item)) | |
56 | 53 | ||
57 | 54 | ||
58 | 55 | @Callable(i) | |
59 | - | func addItem (title,price,data) = { | |
60 | - | let supplierAddress = toBase58String(i.caller.bytes) | |
61 | - | let item = getKeyItem(supplierAddress, title) | |
62 | - | if ((0 >= price)) | |
63 | - | then throw("purchase amount cannot be less than item price") | |
64 | - | else if ((getValueItemSupplier(item) != NONE)) | |
65 | - | then throw("an item is already exist") | |
66 | - | else [StringEntry(getKeyItemSupplier(item), supplierAddress), IntegerEntry(getKeyItemPrice(item), price), StringEntry(getKeyItemData(item), data)] | |
67 | - | } | |
68 | - | ||
69 | - | ||
70 | - | ||
71 | - | @Callable(i) | |
72 | - | func purchase (item) = { | |
73 | - | let pmt = i.payments[0] | |
74 | - | if (isDefined(pmt.assetId)) | |
75 | - | then throw("WAVES token only at the moment") | |
76 | - | else { | |
77 | - | let userAddress = toBase58String(i.caller.bytes) | |
78 | - | let price = getValueItemPrice(item) | |
79 | - | let supplierAddres = getValueItemSupplier(item) | |
80 | - | if ((price > pmt.amount)) | |
81 | - | then throw("purchase amunt cannot be less than item price") | |
82 | - | else if ((pmt.amount > price)) | |
83 | - | then throw("purchase amount cannot be higher than item price") | |
84 | - | else if ((supplierAddres == NONE)) | |
85 | - | then throw("Supplier address doesn't exist") | |
86 | - | else [IntegerEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), IntegerEntry(getKeyBalanceSupplier(supplierAddres), (getValueBalanceSupplier(supplierAddres) + pmt.amount))] | |
87 | - | } | |
88 | - | } | |
89 | - | ||
90 | - | ||
91 | - | ||
92 | - | @Callable(i) | |
93 | - | func withdraw () = { | |
94 | - | let supplierAddress = toBase58String(i.caller.bytes) | |
95 | - | let balance = getValueBalanceSupplier(supplierAddress) | |
96 | - | if ((0 >= balance)) | |
97 | - | then throw("za mało środków") | |
98 | - | else [IntegerEntry(getKeyBalanceSupplier(supplierAddress), 0), ScriptTransfer(addressFromStringValue(supplierAddress), balance, unit)] | |
56 | + | func voteCommit (item,hash) = { | |
57 | + | let user = toBase58String(i.caller.bytes) | |
58 | + | let commits = getValueCommitsCount(item) | |
59 | + | let status = getValueItemStatus(item) | |
60 | + | if ((commits >= VOTERS)) | |
61 | + | then throw("osiągnięto maksymaną liczbę głosujących") | |
62 | + | else if ((getValueCommit(item, user) != NONE)) | |
63 | + | then throw("użtykownik już głosuje") | |
64 | + | else if ((getKeyItemSupplier(item) == NONE)) | |
65 | + | then throw("nie istnieje taki przedmiot") | |
66 | + | else if (if ((status != NONE)) | |
67 | + | then (status != VOTING) | |
68 | + | else false) | |
69 | + | then throw("głosowanie nie jest możliwe") | |
70 | + | else [StringEntry(getKeyCommit(item, user), hash), IntegerEntry(getKeyCommitsCount(item), (commits + 1)), StringEntry(getKeyItemStatus(item), if ((commits == VOTERS)) | |
71 | + | then REVEAL | |
72 | + | else VOTING)] | |
99 | 73 | } | |
100 | 74 | ||
101 | 75 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | + | let VOTERS = 3 | |
5 | + | ||
6 | + | let VOTING = "voting" | |
7 | + | ||
8 | + | let REVEAL = "reveal" | |
9 | + | ||
4 | 10 | let NONE = "none" | |
5 | 11 | ||
6 | 12 | func getNumberByKey (key) = { | |
7 | 13 | let num = match getInteger(this, key) { | |
8 | 14 | case a: Int => | |
9 | 15 | a | |
10 | 16 | case _ => | |
11 | 17 | 0 | |
12 | 18 | } | |
13 | 19 | num | |
14 | 20 | } | |
15 | 21 | ||
16 | 22 | ||
17 | 23 | func getStrByKey (key) = { | |
18 | 24 | let str = match getString(this, key) { | |
19 | 25 | case a: String => | |
20 | 26 | a | |
21 | 27 | case _ => | |
22 | 28 | NONE | |
23 | 29 | } | |
24 | 30 | str | |
25 | 31 | } | |
26 | 32 | ||
27 | 33 | ||
28 | - | func getKeyItemPrice (item) = (item + "_price") | |
29 | - | ||
30 | - | ||
31 | - | func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item)) | |
32 | - | ||
33 | - | ||
34 | - | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt") | |
35 | - | ||
36 | - | ||
37 | - | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) | |
38 | - | ||
39 | - | ||
40 | - | func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title))))) | |
41 | - | ||
42 | - | ||
43 | - | func getKeyItemData (item) = (item + "_data") | |
44 | - | ||
45 | - | ||
46 | 34 | func getKeyItemSupplier (item) = (item + "_data") | |
47 | 35 | ||
48 | 36 | ||
49 | - | func | |
37 | + | func getKeyCommit (item,user) = (((item + "_") + user) + "_commit") | |
50 | 38 | ||
51 | 39 | ||
52 | - | func | |
40 | + | func getValueCommit (item,user) = getStrByKey(getKeyCommit(item, user)) | |
53 | 41 | ||
54 | 42 | ||
55 | - | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
43 | + | func getKeyCommitsCount (item) = (item + "_comcnt") | |
44 | + | ||
45 | + | ||
46 | + | func getValueCommitsCount (item) = getNumberByKey(getKeyCommitsCount(item)) | |
47 | + | ||
48 | + | ||
49 | + | func getKeyItemStatus (item) = (item + "_status") | |
50 | + | ||
51 | + | ||
52 | + | func getValueItemStatus (item) = getStrByKey(getKeyItemStatus(item)) | |
56 | 53 | ||
57 | 54 | ||
58 | 55 | @Callable(i) | |
59 | - | func addItem (title,price,data) = { | |
60 | - | let supplierAddress = toBase58String(i.caller.bytes) | |
61 | - | let item = getKeyItem(supplierAddress, title) | |
62 | - | if ((0 >= price)) | |
63 | - | then throw("purchase amount cannot be less than item price") | |
64 | - | else if ((getValueItemSupplier(item) != NONE)) | |
65 | - | then throw("an item is already exist") | |
66 | - | else [StringEntry(getKeyItemSupplier(item), supplierAddress), IntegerEntry(getKeyItemPrice(item), price), StringEntry(getKeyItemData(item), data)] | |
67 | - | } | |
68 | - | ||
69 | - | ||
70 | - | ||
71 | - | @Callable(i) | |
72 | - | func purchase (item) = { | |
73 | - | let pmt = i.payments[0] | |
74 | - | if (isDefined(pmt.assetId)) | |
75 | - | then throw("WAVES token only at the moment") | |
76 | - | else { | |
77 | - | let userAddress = toBase58String(i.caller.bytes) | |
78 | - | let price = getValueItemPrice(item) | |
79 | - | let supplierAddres = getValueItemSupplier(item) | |
80 | - | if ((price > pmt.amount)) | |
81 | - | then throw("purchase amunt cannot be less than item price") | |
82 | - | else if ((pmt.amount > price)) | |
83 | - | then throw("purchase amount cannot be higher than item price") | |
84 | - | else if ((supplierAddres == NONE)) | |
85 | - | then throw("Supplier address doesn't exist") | |
86 | - | else [IntegerEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), IntegerEntry(getKeyBalanceSupplier(supplierAddres), (getValueBalanceSupplier(supplierAddres) + pmt.amount))] | |
87 | - | } | |
88 | - | } | |
89 | - | ||
90 | - | ||
91 | - | ||
92 | - | @Callable(i) | |
93 | - | func withdraw () = { | |
94 | - | let supplierAddress = toBase58String(i.caller.bytes) | |
95 | - | let balance = getValueBalanceSupplier(supplierAddress) | |
96 | - | if ((0 >= balance)) | |
97 | - | then throw("za mało środków") | |
98 | - | else [IntegerEntry(getKeyBalanceSupplier(supplierAddress), 0), ScriptTransfer(addressFromStringValue(supplierAddress), balance, unit)] | |
56 | + | func voteCommit (item,hash) = { | |
57 | + | let user = toBase58String(i.caller.bytes) | |
58 | + | let commits = getValueCommitsCount(item) | |
59 | + | let status = getValueItemStatus(item) | |
60 | + | if ((commits >= VOTERS)) | |
61 | + | then throw("osiągnięto maksymaną liczbę głosujących") | |
62 | + | else if ((getValueCommit(item, user) != NONE)) | |
63 | + | then throw("użtykownik już głosuje") | |
64 | + | else if ((getKeyItemSupplier(item) == NONE)) | |
65 | + | then throw("nie istnieje taki przedmiot") | |
66 | + | else if (if ((status != NONE)) | |
67 | + | then (status != VOTING) | |
68 | + | else false) | |
69 | + | then throw("głosowanie nie jest możliwe") | |
70 | + | else [StringEntry(getKeyCommit(item, user), hash), IntegerEntry(getKeyCommitsCount(item), (commits + 1)), StringEntry(getKeyItemStatus(item), if ((commits == VOTERS)) | |
71 | + | then REVEAL | |
72 | + | else VOTING)] | |
99 | 73 | } | |
100 | 74 | ||
101 | 75 |
github/deemru/w8io/169f3d6 33.06 ms ◑