tx · zwakKpemf7yZ1ytwhjtfUxJLTAeL44dNBzYchFU5MHp 3MxS2LBsPnEGA6AetWPqWTZjmQu8zUySd2c: -0.01000000 Waves 2021.07.07 10:31 [1602891] smart account 3MxS2LBsPnEGA6AetWPqWTZjmQu8zUySd2c > SELF 0.00000000 Waves
{ "type": 13, "id": "zwakKpemf7yZ1ytwhjtfUxJLTAeL44dNBzYchFU5MHp", "fee": 1000000, "feeAssetId": null, "timestamp": 1625643084133, "version": 2, "chainId": 84, "sender": "3MxS2LBsPnEGA6AetWPqWTZjmQu8zUySd2c", "senderPublicKey": "9dJbLdKrkcPAEacPHvgivaqbGgimy4WN2MRrE6XXWFQu", "proofs": [ "5mC4F5CCxCZPtJWagnYyc3HEa6EPdRX54RoZaLbHppwoZNr8izy8DzRdbegR43emakWwPnz9x8EyMdpgMBGacmBi" ], "script": "base64:AAIFAAAAAAAAAi4IAhIFCgMIAQgSAwoBCBIAGgoKAmExEgROT05FGhQKAmEyEg5nZXROdW1iZXJCeUtleRoJCgJhMxIDa2V5GgkKAmE0EgNudW0aDQoCYTUSByRtYXRjaDAaBwoCYTYSAWEaEQoCYTcSC2dldFN0ckJ5S2V5GgkKAmE4EgNzdHIaFQoCYTkSD2dldEtleUl0ZW1QcmljZRoKCgJiMRIEaXRlbRoXCgJiMhIRZ2V0VmFsdWVJdGVtUHJpY2UaGwoCYjMSFWdldEtleVVzZXJJdGVtQ291bnRlchoKCgJiNBIEdXNlchodCgJiNRIXZ2V0VmFsdWVVc2VySXRlbUNvdW50ZXIaEAoCYjYSCmdldEtleUl0ZW0aDgoCYjcSCHN1cHBsaWVyGgsKAmI4EgV0aXRsZRoUCgJiORIOZ2V0S2V5SXRlbURhdGEaGAoCYzESEmdldEtleUl0ZW1TdXBwbGllchoaCgJjMhIUZ2V0VmFsdWVJdGVtU3VwcGxpZXIaGwoCYzMSFWdldEtleUJhbGFuY2VTdXBwbGllchoNCgJjNBIHYWNjb3VudBodCgJjNRIXZ2V0VmFsdWVC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AAAAAmM3CAUAAAACZDEAAAAGYW1vdW50CQAAAgAAAAECAAAALlB1cmNoYXNlIGFtb3VudCBjYW5ub3QgYmUgbGVzcyB0aGFuIGl0ZW0gcHJpY2UDCQAAAAAAAAIFAAAAAmM5BQAAAAJhMQkAAAIAAAABAgAAABdTdXBwbGllciBkb2VzIG5vdCBleGlzdAkABEwAAAACCQEAAAAMSW50ZWdlckVudHJ5AAAAAgkBAAAAAmIzAAAAAgUAAAACZDIFAAAAAmIxCQAAZAAAAAIJAQAAAAJiNQAAAAIFAAAAAmQyBQAAAAJiMQAAAAAAAAAAAQkABEwAAAACCQEAAAAMSW50ZWdlckVudHJ5AAAAAgkBAAAAAmMzAAAAAQUAAAACYzkJAABkAAAAAgkBAAAAAmM1AAAAAQUAAAACYzkIBQAAAAJkMQAAAAZhbW91bnQFAAAAA25pbAAAAAJjNgEAAAAId2l0aGRyYXcAAAAABAAAAAJjOQkAAlgAAAABCAgFAAAAAmM2AAAABmNhbGxlcgAAAAVieXRlcwQAAAACZDMJAQAAAAJjNQAAAAEFAAAAAmM5AwkAAGcAAAACAAAAAAAAAAAABQAAAAJkMwkAAAIAAAABAgAAABNpbnN1ZmljaWVudCBiYWxhbmNlCQAETAAAAAIJAQAAAAxJbnRlZ2VyRW50cnkAAAACCQEAAAACYzMAAAABBQAAAAJjOQAAAAAAAAAAAAkABEwAAAACCQEAAAAOU2NyaXB0VHJhbnNmZXIAAAADCQEAAAARQGV4dHJOYXRpdmUoMTA2MikAAAABBQAAAAJjOQUAAAACZDMFAAAABHVuaXQFAAAAA25pbAAAAAAceWLv", "height": 1602891, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: HiaxjgkBon59CX7NBhKuMdu6wXGxGEenUYX8JGcE3bsA Next: DUtNdMZBKjqiTS6iAApr4kybKuN1keyE54DhFPH81qgE Diff:
Old | New | Differences | |
---|---|---|---|
86 | 86 | } | |
87 | 87 | ||
88 | 88 | ||
89 | + | ||
90 | + | @Callable(i) | |
91 | + | func withdraw () = { | |
92 | + | let supplierAddress = toBase58String(i.caller.bytes) | |
93 | + | let balance = getValueBalanceSupplier(supplierAddress) | |
94 | + | if ((0 >= balance)) | |
95 | + | then throw("insuficient balance") | |
96 | + | else [IntegerEntry(getKeyBalanceSupplier(supplierAddress), 0), ScriptTransfer(addressFromStringValue(supplierAddress), balance, unit)] | |
97 | + | } | |
98 | + | ||
99 | + |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let NONE = "none" | |
5 | 5 | ||
6 | 6 | func getNumberByKey (key) = { | |
7 | 7 | let num = match getInteger(this, key) { | |
8 | 8 | case a: Int => | |
9 | 9 | a | |
10 | 10 | case _ => | |
11 | 11 | 0 | |
12 | 12 | } | |
13 | 13 | num | |
14 | 14 | } | |
15 | 15 | ||
16 | 16 | ||
17 | 17 | func getStrByKey (key) = { | |
18 | 18 | let str = match getString(this, key) { | |
19 | 19 | case a: String => | |
20 | 20 | a | |
21 | 21 | case _ => | |
22 | 22 | NONE | |
23 | 23 | } | |
24 | 24 | str | |
25 | 25 | } | |
26 | 26 | ||
27 | 27 | ||
28 | 28 | func getKeyItemPrice (item) = (item + "_price") | |
29 | 29 | ||
30 | 30 | ||
31 | 31 | func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item)) | |
32 | 32 | ||
33 | 33 | ||
34 | 34 | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt") | |
35 | 35 | ||
36 | 36 | ||
37 | 37 | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) | |
38 | 38 | ||
39 | 39 | ||
40 | 40 | func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title))))) | |
41 | 41 | ||
42 | 42 | ||
43 | 43 | func getKeyItemData (item) = (item + "_data") | |
44 | 44 | ||
45 | 45 | ||
46 | 46 | func getKeyItemSupplier (item) = (item + "_owner") | |
47 | 47 | ||
48 | 48 | ||
49 | 49 | func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item)) | |
50 | 50 | ||
51 | 51 | ||
52 | 52 | func getKeyBalanceSupplier (account) = (account + "_balance") | |
53 | 53 | ||
54 | 54 | ||
55 | 55 | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
56 | 56 | ||
57 | 57 | ||
58 | 58 | @Callable(i) | |
59 | 59 | func addItem (title,price,data) = { | |
60 | 60 | let supplierAddress = toBase58String(i.caller.bytes) | |
61 | 61 | let item = getKeyItem(supplierAddress, title) | |
62 | 62 | if ((0 >= price)) | |
63 | 63 | then throw("Purchase amount cannot be less than item price") | |
64 | 64 | else if ((getValueItemSupplier(item) != NONE)) | |
65 | 65 | then throw("an item already exists") | |
66 | 66 | else [StringEntry(getKeyItemSupplier(item), supplierAddress), IntegerEntry(getKeyItemPrice(item), price), StringEntry(getKeyItemData(item), data)] | |
67 | 67 | } | |
68 | 68 | ||
69 | 69 | ||
70 | 70 | ||
71 | 71 | @Callable(i) | |
72 | 72 | func purchase (item) = { | |
73 | 73 | let pmt = i.payments[0] | |
74 | 74 | if (isDefined(pmt.assetId)) | |
75 | 75 | then throw("WAVES ONLY HHEUAWHEUAS") | |
76 | 76 | else { | |
77 | 77 | let userAddress = toBase58String(i.caller.bytes) | |
78 | 78 | let price = getValueItemPrice(item) | |
79 | 79 | let supplierAddress = getValueItemSupplier(item) | |
80 | 80 | if ((price > pmt.amount)) | |
81 | 81 | then throw("Purchase amount cannot be less than item price") | |
82 | 82 | else if ((supplierAddress == NONE)) | |
83 | 83 | then throw("Supplier does not exist") | |
84 | 84 | else [IntegerEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), IntegerEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))] | |
85 | 85 | } | |
86 | 86 | } | |
87 | 87 | ||
88 | 88 | ||
89 | + | ||
90 | + | @Callable(i) | |
91 | + | func withdraw () = { | |
92 | + | let supplierAddress = toBase58String(i.caller.bytes) | |
93 | + | let balance = getValueBalanceSupplier(supplierAddress) | |
94 | + | if ((0 >= balance)) | |
95 | + | then throw("insuficient balance") | |
96 | + | else [IntegerEntry(getKeyBalanceSupplier(supplierAddress), 0), ScriptTransfer(addressFromStringValue(supplierAddress), balance, unit)] | |
97 | + | } | |
98 | + | ||
99 | + |
github/deemru/w8io/026f985 43.08 ms ◑