tx · C2mB2YmKEQv9q8L9u7Nsg4UxWdUyavS1HBJJQJnqg8Qt

3PQT3vDXg5tvZaeeS58X2onVvxwBoHn85Mc:  -0.01400000 Waves

2019.10.04 10:23 [1734869] smart account 3PQT3vDXg5tvZaeeS58X2onVvxwBoHn85Mc > SELF 0.00000000 Waves

{ "type": 13, "id": "C2mB2YmKEQv9q8L9u7Nsg4UxWdUyavS1HBJJQJnqg8Qt", "fee": 1400000, "feeAssetId": null, "timestamp": 1570173954415, "version": 1, "sender": "3PQT3vDXg5tvZaeeS58X2onVvxwBoHn85Mc", "senderPublicKey": "G4Ywi2Ua6APjE691ynx8kGLQauzNcNZ1us1AnbgWSXTA", "proofs": [ "55pQ1W8ewydUArWdPLqL34jBnQSeLYiQQYy4GE2rbxekPhSVHDfHcmoQm7u1HUxcNuTWqPXn9Jf3zav4f8LeKPn1" ], "script": null, "chainId": 87, "height": 1734869, "spentComplexity": 0 } View: original | compacted Prev: jY236k8pjnvDVTjnVMmo2Qq37Jwc4MVptdMNqAH8ios Next: none Full:
OldNewDifferences
1-{-# STDLIB_VERSION 3 #-}
2-{-# SCRIPT_TYPE ACCOUNT #-}
3-{-# CONTENT_TYPE DAPP #-}
4-let adminPublicKey = base58'REPLACEADMNKEY'
5-
6-let thanksTokenId = base58'HERESASSETHASH'
7-
8-@Callable(i)
9-func addToWhiteList (address) = {
10- let userInTheList = getBoolean(this, address)
11- let newValue = match userInTheList {
12- case b: Boolean =>
13- if (b)
14- then throw("User is already in the list and enabled")
15- else throw("User is in the list, but disabled")
16- case _ =>
17- true
18- }
19- if ((i.callerPublicKey != adminPublicKey))
20- then throw("Only admin can call this function")
21- else match i.payment {
22- case pmt: AttachedPayment =>
23- ScriptResult(WriteSet([DataEntry(address, newValue)]), TransferSet([ScriptTransfer(addressFromStringValue(address), 1000000, unit)]))
24- case _ =>
25- throw("Payment is needed to transfer to an account")
26- }
27- }
28-
29-
30-
31-@Callable(i)
32-func removeFromWhiteList (address) = if ((i.callerPublicKey != adminPublicKey))
33- then throw("Only admin can call this function")
34- else WriteSet([DataEntry(address, false)])
35-
36-
37-
38-@Callable(i)
39-func buyItem (itemId) = {
40- let callerAddress = toBase58String(i.caller.bytes)
41- let inWhiteListUnit = getBoolean(this, callerAddress)
42- let inWhiteList = match inWhiteListUnit {
43- case w: Boolean =>
44- if (w)
45- then true
46- else throw("Buyer is not in the white-list[removed]")
47- case _ =>
48- throw(("Buyer is not in the white-list: " + callerAddress))
49- }
50- let pmt = match i.payment {
51- case pmt: AttachedPayment =>
52- if (if (!(isDefined(pmt.assetId)))
53- then true
54- else (pmt.assetId != thanksTokenId))
55- then throw("can accept thanks tokens only")
56- else pmt
57- case _ =>
58- throw("Payment is required")
59- }
60- let price = getInteger(this, (("item_" + itemId) + "_price"))
61- let priceReal = match price {
62- case in: Int =>
63- if ((pmt.amount >= in))
64- then in
65- else throw(("Price is too low, you have to pay: " + toString(in)))
66- case _ =>
67- throw(("The price is not defined: " + itemId))
68- }
69- let buyer = getString(this, (("item_" + itemId) + "_buyer"))
70- let buyerAddressString = match buyer {
71- case b: String =>
72- if ((b == callerAddress))
73- then b
74- else throw("You are not the buyer of it!")
75- case _ =>
76- throw("buyerAddress not found")
77- }
78- if ((assetBalance(this, fromBase58String(itemId)) == 0))
79- then throw(("There is no such item: " + itemId))
80- else if (if (if (inWhiteList)
81- then (callerAddress == buyerAddressString)
82- else false)
83- then (pmt.amount >= priceReal)
84- else false)
85- then {
86- let callerPubKey = toBase58String(i.callerPublicKey)
87- let buyKey = (("item_" + itemId) + "_bought")
88- WriteSet([DataEntry(buyKey, "pending")])
89- }
90- else throw("Unknown error")
91- }
92-
93-
94-
95-@Callable(i)
96-func approve (itemId) = {
97- let buyerKey = (("item_" + itemId) + "_buyer")
98- let buyer = getString(this, buyerKey)
99- let buyerAddress = match buyer {
100- case b: String =>
101- addressFromString(b)
102- case _ =>
103- throw("buyerAddress not found")
104- }
105- let buyerAddressReal = match buyerAddress {
106- case a: Address =>
107- a
108- case _ =>
109- throw("Bad address of buyer")
110- }
111- if ((i.callerPublicKey != adminPublicKey))
112- then throw("Only admin can call this function")
113- else {
114- let buyKey = (("item_" + itemId) + "_bought")
115- let itemIdBytes = fromBase58String(itemId)
116- ScriptResult(WriteSet([DataEntry(buyKey, "approved")]), TransferSet([ScriptTransfer(buyerAddressReal, 1, itemIdBytes)]))
117- }
118- }
119-
120-
121-
122-@Callable(i)
123-func reject (itemId) = if ((i.callerPublicKey != adminPublicKey))
124- then throw("Only admin can call this function")
125- else {
126- let buyKey = (("item_" + itemId) + "_bought")
127- let buyerKey = (("item_" + itemId) + "_buyer")
128- let priceKey = (("item_" + itemId) + "_price")
129- let buyerAddress = addressFromStringValue(getStringValue(this, buyerKey))
130- let price = getIntegerValue(this, priceKey)
131- ScriptResult(WriteSet([DataEntry(buyKey, "rejected")]), TransferSet([ScriptTransfer(buyerAddress, price, thanksTokenId)]))
132- }
133-
134-
135-
136-@Callable(i)
137-func addItem (buyerAddress,price) = {
138- let inWhiteListUnit = getBoolean(this, buyerAddress)
139- let inWhiteList = match inWhiteListUnit {
140- case w: Boolean =>
141- if (w)
142- then true
143- else throw("Buyer is not in the white-list[removed]")
144- case _ =>
145- throw(("Buyer is not in the white-list: " + buyerAddress))
146- }
147- if (if ((i.callerPublicKey != adminPublicKey))
148- then true
149- else (inWhiteList == false))
150- then throw("Only admin can call this function")
151- else {
152- let pmt = match i.payment {
153- case pmt: AttachedPayment =>
154- pmt
155- case _ =>
156- throw("Payment is required")
157- }
158- let paymentAssetId = match pmt.assetId {
159- case d: ByteVector =>
160- d
161- case _ =>
162- throw("You have attached waves to the payment *facepalm*")
163- }
164- let nftAssetInfo = assetInfo(paymentAssetId)
165- let nftAssetInfoReal = match nftAssetInfo {
166- case ai: Asset =>
167- ai
168- case _ =>
169- throw("Cant get asset info")
170- }
171- if (if (if ((nftAssetInfoReal.quantity != 1))
172- then true
173- else (nftAssetInfoReal.decimals != 0))
174- then true
175- else (nftAssetInfoReal.issuerPublicKey != adminPublicKey))
176- then throw("Token should be an NFT and from admin user")
177- else {
178- let buyerKey = (("item_" + toBase58String(nftAssetInfoReal.id)) + "_buyer")
179- let priceKey = (("item_" + toBase58String(nftAssetInfoReal.id)) + "_price")
180- WriteSet([DataEntry(buyerKey, buyerAddress), DataEntry(priceKey, price)])
181- }
182- }
183- }
184-
185-
1+# no script

github/deemru/w8io/6500d08 
79.90 ms