tx · Dx6hYdHor2mDdtVAVKHtXCdDMuMM4Dzq89yyA793x4By

3N8zHTUaMJcH29G8xUozZWytpn53v69CL51:  -0.01000000 Waves

2022.03.20 09:14 [1971889] smart account 3N8zHTUaMJcH29G8xUozZWytpn53v69CL51 > SELF 0.00000000 Waves

{ "type": 13, "id": "Dx6hYdHor2mDdtVAVKHtXCdDMuMM4Dzq89yyA793x4By", "fee": 1000000, "feeAssetId": null, "timestamp": 1647757025386, "version": 2, "chainId": 84, "sender": "3N8zHTUaMJcH29G8xUozZWytpn53v69CL51", "senderPublicKey": "2Tx8tnvYK2QdEPckHxCWd42w913bGCC3bbsaQzCGom72", "proofs": [ "4xCMupjWJz3WMKsi5SfeSfbSZcfqLVi9UGXu7mvodvHJsxBGa5uH7WWydXV63QoSMqh64p3Ri8t1x6cp8dMHHMpC" ], "script": "base64:AAIFAAAAAAAAABAIAhIFCgMIAQgSAwoBCBIAAAAADQAAAAAETk9ORQIAAAAEbm9uZQEAAAAOZ2V0TnVtYmVyQnlLZXkAAAABAAAAA2tleQQAAAADbnVtBAAAAAckbWF0Y2gwCQAEGgAAAAIFAAAABHRoaXMFAAAAA2tleQMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAADSW50BAAAAAFhBQAAAAckbWF0Y2gwBQAAAAFhAAAAAAAAAAAABQAAAANudW0BAAAAC2dldFN0ckJ5S2V5AAAAAQAAAANrZXkEAAAAA3N0cgQAAAAHJG1hdGNoMAkABB0AAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAABlN0cmluZwQAAAABYQUAAAAHJG1hdGNoMAUAAAABYQUAAAAETk9ORQUAAAADc3RyAQAAAA9nZXRLZXlJdGVtUHJpY2UAAAABAAAABGl0ZW0JAAEsAAAAAgUAAAAEaXRlbQIAAAAGX3ByaWNlAQAAABFnZXRWYWx1ZUl0ZW1QcmljZQAAAAEAAAAEaXRlbQkBAAAADmdldE51bWJlckJ5S2V5AAAAAQkBAA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JAQAAABdnZXRWYWx1ZUJhbGFuY2VTdXBwbGllcgAAAAEFAAAAD3N1cHBsaWVyQWRkcmVzcwMJAABnAAAAAgAAAAAAAAAAAAUAAAAHYmFsYW5jZQkAAAIAAAABAgAAABRpbnN1ZmZpY2llbnQgYmFsYW5jZQkABRQAAAACCQAETAAAAAIJAQAAAAxJbnRlZ2VyRW50cnkAAAACCQEAAAAVZ2V0S2V5QmFsYW5jZVN1cHBsaWVyAAAAAQUAAAAPc3VwcGxpZXJBZGRyZXNzAAAAAAAAAAAACQAETAAAAAIJAQAAAA5TY3JpcHRUcmFuc2ZlcgAAAAMJAQAAABFAZXh0ck5hdGl2ZSgxMDYyKQAAAAEFAAAAD3N1cHBsaWVyQWRkcmVzcwUAAAAHYmFsYW5jZQUAAAAEdW5pdAUAAAADbmlsBQAAAAR1bml0AAAAAHU7Oyg=", "height": 1971889, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: none Next: Ai2PFDvpECRFbKDFsA7ochchgWY6zQMp6xfW2SVVA3zf Full:
OldNewDifferences
1-# no script
1+{-# STDLIB_VERSION 5 #-}
2+{-# SCRIPT_TYPE ACCOUNT #-}
3+{-# CONTENT_TYPE DAPP #-}
4+let NONE = "none"
5+
6+func getNumberByKey (key) = {
7+ let num = match getInteger(this, key) {
8+ case a: Int =>
9+ a
10+ case _ =>
11+ 0
12+ }
13+ num
14+ }
15+
16+
17+func getStrByKey (key) = {
18+ let str = match getString(this, key) {
19+ case a: String =>
20+ a
21+ case _ =>
22+ NONE
23+ }
24+ str
25+ }
26+
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+
46+func getKeyItemSupplier (item) = (item + "_owner")
47+
48+
49+func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item))
50+
51+
52+func getKeyBalanceSupplier (account) = (account + "_balance")
53+
54+
55+func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account))
56+
57+
58+@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 $Tuple2([StringEntry(getKeyItemSupplier(item), supplierAddress), IntegerEntry(getKeyItemPrice(item), price), StringEntry(getKeyItemData(item), data)], unit)
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("can use WAVES only at the moment")
76+ else {
77+ let userAddress = toBase58String(i.caller.bytes)
78+ let price = getValueItemPrice(item)
79+ let supplierAddress = getValueItemSupplier(item)
80+ if ((price > pmt.amount))
81+ then throw("purchase amount 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 ((supplierAddress == NONE))
85+ then throw("supplier does not exist")
86+ else $Tuple2([IntegerEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), IntegerEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))], unit)
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("insufficient balance")
98+ else $Tuple2([IntegerEntry(getKeyBalanceSupplier(supplierAddress), 0), ScriptTransfer(addressFromStringValue(supplierAddress), balance, unit)], unit)
99+ }
100+
101+

github/deemru/w8io/026f985 
31.69 ms