tx · BUDhUPsLcZE36WbdRj2Rtvj2KUkwhXjZsDTUpqSmbFJv

3MpjwMAGCaNqNFRa34foE5sTfV6zb76bYja:  -0.01000010 Waves

2021.07.21 16:14 [1623429] smart account 3MpjwMAGCaNqNFRa34foE5sTfV6zb76bYja > SELF 0.00000000 Waves

{ "type": 13, "id": "BUDhUPsLcZE36WbdRj2Rtvj2KUkwhXjZsDTUpqSmbFJv", "fee": 1000010, "feeAssetId": null, "timestamp": 1626873285853, "version": 2, "chainId": 84, "sender": "3MpjwMAGCaNqNFRa34foE5sTfV6zb76bYja", "senderPublicKey": "7Cy4wXHvgCRHP6MMhu9tTdayLHr9P9Dc342DVcCoCPzm", "proofs": [ "67CUATPnDEsZBVTmk2hEAupdsMVXbaBR4PLsy8cTCatYYwoFWF5tvVBSwRenFKnEEnB1QcGSsBFyzi8CSHHUByq6" ], "script": "base64:AAIFAAAAAAAAAAkIAhIAEgMKAQEAAAABAAAAAAR3RVVSAQAAACBRgM2l49nKLjfHvaSg2e7mORayjPZpt1hF5HDPqsnD2gAAAAIAAAABaQEAAAAHZGVwb3NpdAAAAAAEAAAAA3BtdAkAAZEAAAACCAUAAAABaQAAAAhwYXltZW50cwAAAAAAAAAAAAMJAQAAAAIhPQAAAAIIBQAAAANwbXQAAAAHYXNzZXRJZAUAAAAEd0VVUgkAAAIAAAABAgAAADV3RVVSIC0gJzZWOXdQcUIzZ01UcWE4MjlYVmt4anBSbnhyTUdaTWh4UjQ0MUpDMmttZmgzJwQAAAAKY3VycmVudEtleQkAAlgAAAABCAgFAAAAAWkAAAAGY2FsbGVyAAAABWJ5dGVzBAAAAA1jdXJyZW50QW1vdW50BAAAAAckbWF0Y2gwCQAEGgAAAAIFAAAABHRoaXMFAAAACmN1cnJlbnRLZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAA0ludAQAAAABYQUAAAAHJG1hdGNoMAUAAAABYQAAAAAAAAAAAAQAAAAJbmV3QW1vdW50CQAAZAAAAAIFAAAADWN1cnJlbnRBbW91bnQIBQAAAANwbXQAAAAGYW1vdW50CQAETAAAAAIJAQAAAAxJbnRlZ2VyRW50cnkAAAACBQAAAApjdXJyZW50S2V5BQAAAAluZXdBbW91bnQFAAAAA25pbAAAAAFpAQAAAAd3aXRkcmF3AAAAAQAAAAZhbW91bnQEAAAACmN1cnJlbnRLZXkJAAJYAAAAAQgIBQAAAAFpAAAABmNhbGxlcgAAAAVieXRlcwQAAAANY3VycmVudEFtb3VudAQAAAAHJG1hdGNoMAkABBoAAAACBQAAAAR0aGlzBQAAAApjdXJyZW50S2V5AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAANJbnQEAAAAAWEFAAAAByRtYXRjaDAFAAAAAWEAAAAAAAAAAAAEAAAACW5ld0Ftb3VudAkAAGUAAAACBQAAAA1jdXJyZW50QW1vdW50BQAAAAZhbW91bnQDCQAAZgAAAAIAAAAAAAAAAAAFAAAABmFtb3VudAkAAAIAAAABAgAAAB9jYW4ndCB3aXRoZHJhdyBuZWdhdGl2ZXMgYW1vdW50AwkAAGYAAAACAAAAAAAAAAAABQAAAAluZXdBbW91bnQJAAACAAAAAQIAAAASTm90IGVub3VnaCBiYWxhbmNlCQAETAAAAAIJAQAAAAxJbnRlZ2VyRW50cnkAAAACBQAAAApjdXJyZW50S2V5BQAAAAluZXdBbW91bnQJAARMAAAAAgkBAAAADlNjcmlwdFRyYW5zZmVyAAAAAwgFAAAAAWkAAAAGY2FsbGVyBQAAAAZhbW91bnQFAAAABHdFVVIFAAAAA25pbAAAAACfw6mx", "height": 1623429, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 7Lfcqsp3pnmuFur37TzNQydAqcHybAbQi9hDGHxP4JKT Next: none Full:
OldNewDifferences
11 {-# STDLIB_VERSION 5 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# 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 + "_data")
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-
4+let wEUR = base58'6V9wPqB3gMTqa829XVkxjpRnxrMGZMhxR441JC2kmfh3'
575
586 @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) = {
7+func deposit () = {
738 let pmt = i.payments[0]
74- if (isDefined(pmt.assetId))
75- then throw("WAVES token only at the moment")
9+ if ((pmt.assetId != wEUR))
10+ then throw("wEUR - '6V9wPqB3gMTqa829XVkxjpRnxrMGZMhxR441JC2kmfh3'")
7611 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))]
12+ let currentKey = toBase58String(i.caller.bytes)
13+ let currentAmount = match getInteger(this, currentKey) {
14+ case a: Int =>
15+ a
16+ case _ =>
17+ 0
18+ }
19+ let newAmount = (currentAmount + pmt.amount)
20+[IntegerEntry(currentKey, newAmount)]
8721 }
8822 }
8923
9024
9125
9226 @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)]
27+func witdraw (amount) = {
28+ let currentKey = toBase58String(i.caller.bytes)
29+ let currentAmount = match getInteger(this, currentKey) {
30+ case a: Int =>
31+ a
32+ case _ =>
33+ 0
34+ }
35+ let newAmount = (currentAmount - amount)
36+ if ((0 > amount))
37+ then throw("can't withdraw negatives amount")
38+ else if ((0 > newAmount))
39+ then throw("Not enough balance")
40+ else [IntegerEntry(currentKey, newAmount), ScriptTransfer(i.caller, amount, wEUR)]
9941 }
10042
10143

github/deemru/w8io/026f985 
28.18 ms