tx · GHW7a3uPTqoVsjsSsVqXxaUB1F5sMfeFbaFrqL61PVZA 3MpjwMAGCaNqNFRa34foE5sTfV6zb76bYja: -0.01000010 Waves 2021.07.08 14:11 [1604546] smart account 3MpjwMAGCaNqNFRa34foE5sTfV6zb76bYja > SELF 0.00000000 Waves
{ "type": 13, "id": "GHW7a3uPTqoVsjsSsVqXxaUB1F5sMfeFbaFrqL61PVZA", "fee": 1000010, "feeAssetId": null, "timestamp": 1625742718100, "version": 2, "chainId": 84, "sender": "3MpjwMAGCaNqNFRa34foE5sTfV6zb76bYja", "senderPublicKey": "7Cy4wXHvgCRHP6MMhu9tTdayLHr9P9Dc342DVcCoCPzm", "proofs": [ "39B6tVbS8VmAfgHZjWpy3ME57YS5c2RoJxG23t4MJ9xUn5NeA3kb6skRxgaLwfDRckYVKQ2K3QCCrprbtEvFyBGx" ], "script": "base64:AAIFAAAAAAAAAkQIAhIFCgMIAQgSAwoBCBIAGgoKAmExEgROT05FGhQKAmEyEg5nZXROdW1iZXJCeUtleRoJCgJhMxIDa2V5GgkKAmE0EgNudW0aDQoCYTUSByRtYXRjaDAaBwoCYTYSAWEaEQoCYTcSC2dldFN0ckJ5S2V5GgkKAmE4EgNzdHIaFQoCYTkSD2dldEtleUl0ZW1QcmljZRoKCgJiMRIEaXRlbRoXCgJiMhIRZ2V0VmFsdWVJdGVtUHJpY2UaGwoCYjMSFWdldEtleVVzZXJJdGVtQ291bnRlchoKCgJiNBIEdXNlchodCgJiNRIXZ2V0VmFsdWVVc2VySXRlbUNvdW50ZXIaEAoCYjYSCmdldEtleUl0ZW0aDgoCYjcSCHN1cHBsaWVyGgsKAmI4EgV0aXRsZRoUCgJiORIOZ2V0S2V5SXRlbURhdGEaGAoCYzESEmdldEtleUl0ZW1TdXBwbGllchoaCgJjMhIUZ2V0VmFsdWVJdGVtU3VwcGxpZXIaGwoCYzMSFWdldEtleUJhbGFuY2VTdXBwbGllchoNCgJjNBIHYWNjb3VudBodCgJjNRIXZ2V0V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": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 8YVQTvj68zepSUv9UznKyuNaQGYJYwQPRxwvoDivMJA Next: 7Lfcqsp3pnmuFur37TzNQydAqcHybAbQi9hDGHxP4JKT 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 QUORUM = 2 | |
7 | - | ||
8 | - | let VOTING = "voting" | |
9 | - | ||
10 | - | let REVEAL = "reveal" | |
11 | - | ||
12 | - | let FEATURED = "featured" | |
13 | - | ||
14 | - | let DELISTED = "delisted" | |
15 | - | ||
16 | 4 | let NONE = "none" | |
17 | 5 | ||
18 | 6 | func getNumberByKey (key) = { | |
37 | 25 | } | |
38 | 26 | ||
39 | 27 | ||
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 | + | ||
40 | 46 | func getKeyItemSupplier (item) = (item + "_data") | |
41 | 47 | ||
42 | 48 | ||
43 | - | func | |
49 | + | func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item)) | |
44 | 50 | ||
45 | 51 | ||
46 | - | func | |
52 | + | func getKeyBalanceSupplier (account) = (account + "_balance") | |
47 | 53 | ||
48 | 54 | ||
49 | - | func getKeyCommitsCount (item) = (item + "_comcnt") | |
50 | - | ||
51 | - | ||
52 | - | func getValueCommitsCount (item) = getNumberByKey(getKeyCommitsCount(item)) | |
53 | - | ||
54 | - | ||
55 | - | func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal") | |
56 | - | ||
57 | - | ||
58 | - | func getValueReveal (item,user) = getStrByKey(getKeyReveal(item, user)) | |
59 | - | ||
60 | - | ||
61 | - | func getKeyItemStatus (item) = (item + "_status") | |
62 | - | ||
63 | - | ||
64 | - | func getValueItemStatus (item) = getStrByKey(getKeyItemStatus(item)) | |
65 | - | ||
66 | - | ||
67 | - | func getKeyVoteCount (item,vote) = ((item + "_res:") + vote) | |
68 | - | ||
69 | - | ||
70 | - | func getValueVoteCount (item,vote) = getNumberByKey(getKeyVoteCount(item, vote)) | |
55 | + | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
71 | 56 | ||
72 | 57 | ||
73 | 58 | @Callable(i) | |
74 | - | func voteCommit (item,hash) = { | |
75 | - | let user = toBase58String(i.caller.bytes) | |
76 | - | let commits = getValueCommitsCount(item) | |
77 | - | let status = getValueItemStatus(item) | |
78 | - | if ((commits >= VOTERS)) | |
79 | - | then throw("osiągnięto maksymaną liczbę głosujących") | |
80 | - | else if ((getValueCommit(item, user) != NONE)) | |
81 | - | then throw("użtykownik już głosuje") | |
82 | - | else if ((getKeyItemSupplier(item) == NONE)) | |
83 | - | then throw("nie istnieje taki przedmiot") | |
84 | - | else if (if ((status != NONE)) | |
85 | - | then (status != VOTING) | |
86 | - | else false) | |
87 | - | then throw("głosowanie nie jest możliwe") | |
88 | - | else [StringEntry(getKeyCommit(item, user), hash), IntegerEntry(getKeyCommitsCount(item), (commits + 1)), StringEntry(getKeyItemStatus(item), if ((commits == VOTERS)) | |
89 | - | then REVEAL | |
90 | - | else VOTING)] | |
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)] | |
91 | 67 | } | |
92 | 68 | ||
93 | 69 | ||
94 | 70 | ||
95 | 71 | @Callable(i) | |
96 | - | func voteReveal (item,vote,salt) = { | |
97 | - | let user = toBase58String(i.caller.bytes) | |
98 | - | let status = getValueItemStatus(item) | |
99 | - | let newVoteCount = (getValueVoteCount(item, vote) + 1) | |
100 | - | if ((toBase58String(sha256(toBytes((vote + salt)))) != getValueCommit(item, user))) | |
101 | - | then throw("reveal data is not valid") | |
102 | - | else if ((VOTERS > getValueCommitsCount(item))) | |
103 | - | then throw("max number of voters hasn't reached yet") | |
104 | - | else if ((getValueReveal(item, user) != NONE)) | |
105 | - | then throw("user has already participated") | |
106 | - | else if (if ((status != VOTING)) | |
107 | - | then (status != REVEAL) | |
108 | - | else false) | |
109 | - | then throw("wrong status") | |
110 | - | else if (if ((vote != FEATURED)) | |
111 | - | then (vote != DELISTED) | |
112 | - | else false) | |
113 | - | then throw("vote has finished") | |
114 | - | else [StringEntry(getKeyReveal(item, user), vote), IntegerEntry(getKeyVoteCount(item, vote), newVoteCount), StringEntry(getKeyItemStatus(item), if ((newVoteCount >= QUORUM)) | |
115 | - | then vote | |
116 | - | else REVEAL)] | |
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)] | |
117 | 99 | } | |
118 | 100 | ||
119 | 101 |
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 QUORUM = 2 | |
7 | - | ||
8 | - | let VOTING = "voting" | |
9 | - | ||
10 | - | let REVEAL = "reveal" | |
11 | - | ||
12 | - | let FEATURED = "featured" | |
13 | - | ||
14 | - | let DELISTED = "delisted" | |
15 | - | ||
16 | 4 | let NONE = "none" | |
17 | 5 | ||
18 | 6 | func getNumberByKey (key) = { | |
19 | 7 | let num = match getInteger(this, key) { | |
20 | 8 | case a: Int => | |
21 | 9 | a | |
22 | 10 | case _ => | |
23 | 11 | 0 | |
24 | 12 | } | |
25 | 13 | num | |
26 | 14 | } | |
27 | 15 | ||
28 | 16 | ||
29 | 17 | func getStrByKey (key) = { | |
30 | 18 | let str = match getString(this, key) { | |
31 | 19 | case a: String => | |
32 | 20 | a | |
33 | 21 | case _ => | |
34 | 22 | NONE | |
35 | 23 | } | |
36 | 24 | str | |
37 | 25 | } | |
38 | 26 | ||
39 | 27 | ||
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 | + | ||
40 | 46 | func getKeyItemSupplier (item) = (item + "_data") | |
41 | 47 | ||
42 | 48 | ||
43 | - | func | |
49 | + | func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item)) | |
44 | 50 | ||
45 | 51 | ||
46 | - | func | |
52 | + | func getKeyBalanceSupplier (account) = (account + "_balance") | |
47 | 53 | ||
48 | 54 | ||
49 | - | func getKeyCommitsCount (item) = (item + "_comcnt") | |
50 | - | ||
51 | - | ||
52 | - | func getValueCommitsCount (item) = getNumberByKey(getKeyCommitsCount(item)) | |
53 | - | ||
54 | - | ||
55 | - | func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal") | |
56 | - | ||
57 | - | ||
58 | - | func getValueReveal (item,user) = getStrByKey(getKeyReveal(item, user)) | |
59 | - | ||
60 | - | ||
61 | - | func getKeyItemStatus (item) = (item + "_status") | |
62 | - | ||
63 | - | ||
64 | - | func getValueItemStatus (item) = getStrByKey(getKeyItemStatus(item)) | |
65 | - | ||
66 | - | ||
67 | - | func getKeyVoteCount (item,vote) = ((item + "_res:") + vote) | |
68 | - | ||
69 | - | ||
70 | - | func getValueVoteCount (item,vote) = getNumberByKey(getKeyVoteCount(item, vote)) | |
55 | + | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
71 | 56 | ||
72 | 57 | ||
73 | 58 | @Callable(i) | |
74 | - | func voteCommit (item,hash) = { | |
75 | - | let user = toBase58String(i.caller.bytes) | |
76 | - | let commits = getValueCommitsCount(item) | |
77 | - | let status = getValueItemStatus(item) | |
78 | - | if ((commits >= VOTERS)) | |
79 | - | then throw("osiągnięto maksymaną liczbę głosujących") | |
80 | - | else if ((getValueCommit(item, user) != NONE)) | |
81 | - | then throw("użtykownik już głosuje") | |
82 | - | else if ((getKeyItemSupplier(item) == NONE)) | |
83 | - | then throw("nie istnieje taki przedmiot") | |
84 | - | else if (if ((status != NONE)) | |
85 | - | then (status != VOTING) | |
86 | - | else false) | |
87 | - | then throw("głosowanie nie jest możliwe") | |
88 | - | else [StringEntry(getKeyCommit(item, user), hash), IntegerEntry(getKeyCommitsCount(item), (commits + 1)), StringEntry(getKeyItemStatus(item), if ((commits == VOTERS)) | |
89 | - | then REVEAL | |
90 | - | else VOTING)] | |
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)] | |
91 | 67 | } | |
92 | 68 | ||
93 | 69 | ||
94 | 70 | ||
95 | 71 | @Callable(i) | |
96 | - | func voteReveal (item,vote,salt) = { | |
97 | - | let user = toBase58String(i.caller.bytes) | |
98 | - | let status = getValueItemStatus(item) | |
99 | - | let newVoteCount = (getValueVoteCount(item, vote) + 1) | |
100 | - | if ((toBase58String(sha256(toBytes((vote + salt)))) != getValueCommit(item, user))) | |
101 | - | then throw("reveal data is not valid") | |
102 | - | else if ((VOTERS > getValueCommitsCount(item))) | |
103 | - | then throw("max number of voters hasn't reached yet") | |
104 | - | else if ((getValueReveal(item, user) != NONE)) | |
105 | - | then throw("user has already participated") | |
106 | - | else if (if ((status != VOTING)) | |
107 | - | then (status != REVEAL) | |
108 | - | else false) | |
109 | - | then throw("wrong status") | |
110 | - | else if (if ((vote != FEATURED)) | |
111 | - | then (vote != DELISTED) | |
112 | - | else false) | |
113 | - | then throw("vote has finished") | |
114 | - | else [StringEntry(getKeyReveal(item, user), vote), IntegerEntry(getKeyVoteCount(item, vote), newVoteCount), StringEntry(getKeyItemStatus(item), if ((newVoteCount >= QUORUM)) | |
115 | - | then vote | |
116 | - | else REVEAL)] | |
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)] | |
117 | 99 | } | |
118 | 100 | ||
119 | 101 |
github/deemru/w8io/169f3d6 30.28 ms ◑