tx · 2KTtPtvqHXAVTPviVruN7Qjkc8DkubBjAWKJnM9xb5Ve

3Mrik3RqY2jPfkkG7R7UiHLBXGGa3jfMpyT:  -0.01400000 Waves

2019.08.28 00:00 [650116] smart account 3Mrik3RqY2jPfkkG7R7UiHLBXGGa3jfMpyT > SELF 0.00000000 Waves

{ "type": 13, "id": "2KTtPtvqHXAVTPviVruN7Qjkc8DkubBjAWKJnM9xb5Ve", "fee": 1400000, "feeAssetId": null, "timestamp": 1566939670674, "version": 1, "sender": "3Mrik3RqY2jPfkkG7R7UiHLBXGGa3jfMpyT", "senderPublicKey": "Di8Ucr8vDr6jZNa27iAQxGMYEW9WSuF6MCBaM3fe9coP", "proofs": [ "2w6Kr9UmmfK5rqe6Ac9SRRGrZjqq5aEuhc1GFgPnTMXSwKG815n59wgs63mnn4hipmV6bhAMBpqXQoVoF23EvrRZ" ], "script": "base64:AAIDAAAAAAAAAAAAAAANAAAAAAROT05FAgAAAARub25lAQAAAA5nZXROdW1iZXJCeUtleQAAAAEAAAADa2V5BAAAAANudW0EAAAAByRtYXRjaDAJAAQaAAAAAgUAAAAEdGhpcwUAAAADa2V5AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAANJbnQEAAAAAWEFAAAAByRtYXRjaDAFAAAAAWEAAAAAAAAAAAAFAAAAA251bQEAAAALZ2V0U3RyQnlLZXkAAAABAAAAA2tleQQAAAADc3RyBAAAAAckbWF0Y2gwCQAEHQAAAAIFAAAABHRoaXMFAAAAA2tleQMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAAGU3RyaW5nBAAAAAFhBQAAAAckbWF0Y2gwBQAAAAFhBQAAAAROT05FBQAAAANzdHIBAAAACmdldEtleUl0ZW0AAAACAAAACHN1cHBsaWVyAAAABXRpdGxlCQABLAAAAAICAAAABWl0ZW1fCQACWAAAAAEJAAH3AAAAAQkAAZsAAAABCQABLAAAAAIFAAAACHN1cHBsaWVyBQAAAAV0aXRsZQEAAAAPZ2V0S2V5SXRlbVBya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zdXBwbGllckFkZHJlc3MDCQAAZwAAAAIAAAAAAAAAAAAFAAAAB2JhbGFuY2UJAAACAAAAAQIAAAASaW5zdWZmaWNpZW50IGZ1bmRzCQEAAAAMU2NyaXB0UmVzdWx0AAAAAgkBAAAACFdyaXRlU2V0AAAAAQkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgkBAAAAFWdldEtleVN1cHBsaWVyQmFsYW5jZQAAAAEFAAAAD3N1cHBsaWVyQWRkcmVzcwAAAAAAAAAAAAUAAAADbmlsCQEAAAALVHJhbnNmZXJTZXQAAAABCQAETAAAAAIJAQAAAA5TY3JpcHRUcmFuc2ZlcgAAAAMJAQAAABxAZXh0clVzZXIoYWRkcmVzc0Zyb21TdHJpbmcpAAAAAQUAAAAPc3VwcGxpZXJBZGRyZXNzBQAAAAdiYWxhbmNlBQAAAAR1bml0BQAAAANuaWwAAAAAzSPv9w==", "chainId": 84, "height": 650116, "spentComplexity": 0 } View: original | compacted Prev: DQAWG7fJRq7ZtBTLVYQiKNkmSA3Bgg15KF3VYHB3Nrti Next: 5E3iA3mmGDQhoFLTmV5ChfParNXddyYRwFcU8ji6Pi8K Diff:
OldNewDifferences
8888 }
8989
9090
91+
92+@Callable(i)
93+func withdraw () = {
94+ let supplierAddress = toBase58String(i.caller.bytes)
95+ let balance = getValueSupplierBalance(supplierAddress)
96+ if ((0 >= balance))
97+ then throw("insufficient funds")
98+ else ScriptResult(WriteSet([DataEntry(getKeySupplierBalance(supplierAddress), 0)]), TransferSet([ScriptTransfer(addressFromStringValue(supplierAddress), balance, unit)]))
99+ }
100+
101+
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 3 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let NONE = "none"
55
66 func getNumberByKey (key) = {
77 let num = match getInteger(this, key) {
88 case a: Int =>
99 a
1010 case _ =>
1111 0
1212 }
1313 num
1414 }
1515
1616
1717 func getStrByKey (key) = {
1818 let str = match getString(this, key) {
1919 case a: String =>
2020 a
2121 case _ =>
2222 NONE
2323 }
2424 str
2525 }
2626
2727
2828 func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title)))))
2929
3030
3131 func getKeyItemPrice (item) = (item + "_price")
3232
3333
3434 func getKeyItemData (item) = (item + "_data")
3535
3636
3737 func getKeyItemSupplier (item) = (item + "_owner")
3838
3939
4040 func getKeySupplierBalance (account) = (account + "_balance")
4141
4242
4343 func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt")
4444
4545
4646 func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item))
4747
4848
4949 func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item))
5050
5151
5252 func getValueSupplierBalance (account) = getNumberByKey(getKeySupplierBalance(account))
5353
5454
5555 func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item))
5656
5757
5858 @Callable(i)
5959 func addItem (title,price,data) = {
6060 let supplierAddress = toBase58String(i.caller.bytes)
6161 let item = getKeyItem(supplierAddress, title)
6262 if ((0 >= price))
6363 then throw("Purchase amount cannot be less than or equal 0")
6464 else if ((getValueItemSupplier(item) != NONE))
6565 then throw("Item exists already")
6666 else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddress), DataEntry(getKeyItemPrice(item), price), DataEntry(getKeyItemData(item), data)])
6767 }
6868
6969
7070
7171 @Callable(i)
7272 func purchase (item) = {
7373 let pmt = extract(i.payment)
7474 if (isDefined(pmt.assetId))
7575 then throw("WAVES only at the moment")
7676 else {
7777 let userAddress = toBase58String(i.caller.bytes)
7878 let price = getValueItemPrice(item)
7979 let supplierAddress = getValueItemSupplier(item)
8080 if ((price > pmt.amount))
8181 then throw("purchase amount cannot be less than item price")
8282 else if ((pmt.amount > price))
8383 then throw("purchase amount cannot be higher than item price")
8484 else if ((supplierAddress == NONE))
8585 then throw("supplier doesn't exists")
8686 else WriteSet([DataEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), DataEntry(getKeySupplierBalance(supplierAddress), (getValueSupplierBalance(supplierAddress) + pmt.amount))])
8787 }
8888 }
8989
9090
91+
92+@Callable(i)
93+func withdraw () = {
94+ let supplierAddress = toBase58String(i.caller.bytes)
95+ let balance = getValueSupplierBalance(supplierAddress)
96+ if ((0 >= balance))
97+ then throw("insufficient funds")
98+ else ScriptResult(WriteSet([DataEntry(getKeySupplierBalance(supplierAddress), 0)]), TransferSet([ScriptTransfer(addressFromStringValue(supplierAddress), balance, unit)]))
99+ }
100+
101+

github/deemru/w8io/026f985 
105.28 ms