tx · 5Aoq76tGWqzsEqxcGnjCgH7a69CvCm7jyV6jF6KXGYGa 3Mzz3QCpMamT89CaFaovqXpnCdiUaKtLZ4D: -0.01400000 Waves 2019.06.22 17:13 [553358] smart account 3Mzz3QCpMamT89CaFaovqXpnCdiUaKtLZ4D > SELF 0.00000000 Waves
{ "type": 13, "id": "5Aoq76tGWqzsEqxcGnjCgH7a69CvCm7jyV6jF6KXGYGa", "fee": 1400000, "feeAssetId": null, "timestamp": 1561212871599, "version": 1, "sender": "3Mzz3QCpMamT89CaFaovqXpnCdiUaKtLZ4D", "senderPublicKey": "BJRaSW2saRv7CcFs3mSYpaVFQSFpZq9rGKnCcRKuKgWv", "proofs": [ "4M3W1NAAB2FZS8Pyr7L8T2Hrx7mppxtNCRjpzgoUPJvD6C2bRPVABLqBt4Xf4wfZSjtnmvJkrFyyMZPCvaneBxY2" ], "script": "base64:AAIDAAAAAAAAAAAAAAANAAAAAAROT05FAgAAAARub25lAQAAAApnZXRLZXlJdGVtAAAAAgAAAAhzdXBwbGllcgAAAAV0aXRsZQkAASwAAAACAgAAAAVpdGVtXwkAAlgAAAABCQAB9wAAAAEJAAGbAAAAAQkAASwAAAACBQAAAAhzdXBwbGllcgUAAAAFdGl0bGUBAAAAEmdldEtleUl0ZW1TdXBwbGllcgAAAAEAAAAEaXRlbQkAASwAAAACBQAAAARpdGVtAgAAAAZfb3duZXIBAAAAFWdldEtleUJhbGFuY2VTdXBwbGllcgAAAAEAAAAEaXRlbQkAASwAAAACBQAAAARpdGVtAgAAAAhfYmFsYW5jZQEAAAAPZ2V0S2V5SXRlbVByaWNlAAAAAQAAAARpdGVtCQABLAAAAAIFAAAABGl0ZW0CAAAABl9wcmljZQEAAAAOZ2V0S2V5SXRlbURhdGEAAAABAAAABGl0ZW0JAAEsAAAAAgUAAAAEaXRlbQIAAAAFX2RhdGEBAAAAFWdldEtleVVzZXJJdGVtQ291bnRlcgAAAAIAAAAEdXNlcgAAAARpdGVtCQABLAAAAAIJAAEs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ZQkBAAAAF2dldFZhbHVlQmFsYW5jZVN1cHBsaWVyAAAAAQUAAAAPc3VwcGxpZXJBZGRyZXNzAwkAAGcAAAACAAAAAAAAAAAABQAAAAdiYWxhbmNlCQAAAgAAAAECAAAAFGluc3VmZmljaWVudCBiYWxhbmNlCQEAAAAMU2NyaXB0UmVzdWx0AAAAAgkBAAAACFdyaXRlU2V0AAAAAQkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgkBAAAAFWdldEtleUJhbGFuY2VTdXBwbGllcgAAAAEFAAAAD3N1cHBsaWVyQWRkcmVzcwAAAAAAAAAAAAUAAAADbmlsCQEAAAALVHJhbnNmZXJTZXQAAAABCQAETAAAAAIJAQAAAA5TY3JpcHRUcmFuc2ZlcgAAAAMJAQAAABxAZXh0clVzZXIoYWRkcmVzc0Zyb21TdHJpbmcpAAAAAQUAAAAPc3VwcGxpZXJBZGRyZXNzBQAAAAdiYWxhbmNlBQAAAAR1bml0BQAAAANuaWwAAAAAwSzENA==", "chainId": 84, "height": 553358, "spentComplexity": 0 } View: original | compacted Prev: EKC61cF24UvhESRWABKAvwmG1BiZ1EMjb7zDrUh39kdc Next: C61ebeiM7iWGYJUJUebHmLWEMcbNizcbDkpqYELujFpe Diff:
Old | New | Differences | |
---|---|---|---|
111 | 111 | } | |
112 | 112 | ||
113 | 113 | ||
114 | + | ||
115 | + | @Callable(i) | |
116 | + | func withdraw () = { | |
117 | + | let supplierAddress = toBase58String(i.caller.bytes) | |
118 | + | let balance = getValueBalanceSupplier(supplierAddress) | |
119 | + | if ((0 >= balance)) | |
120 | + | then throw("insufficient balance") | |
121 | + | else ScriptResult(WriteSet([DataEntry(getKeyBalanceSupplier(supplierAddress), 0)]), TransferSet([ScriptTransfer(addressFromStringValue(supplierAddress), balance, unit)])) | |
122 | + | } | |
123 | + | ||
124 | + |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let NONE = "none" | |
5 | 5 | ||
6 | 6 | func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title))))) | |
7 | 7 | ||
8 | 8 | ||
9 | 9 | func getKeyItemSupplier (item) = (item + "_owner") | |
10 | 10 | ||
11 | 11 | ||
12 | 12 | func getKeyBalanceSupplier (item) = (item + "_balance") | |
13 | 13 | ||
14 | 14 | ||
15 | 15 | func getKeyItemPrice (item) = (item + "_price") | |
16 | 16 | ||
17 | 17 | ||
18 | 18 | func getKeyItemData (item) = (item + "_data") | |
19 | 19 | ||
20 | 20 | ||
21 | 21 | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt") | |
22 | 22 | ||
23 | 23 | ||
24 | 24 | func getStrByKey (key) = { | |
25 | 25 | let str = match getString(this, key) { | |
26 | 26 | case a: String => | |
27 | 27 | a | |
28 | 28 | case _ => | |
29 | 29 | NONE | |
30 | 30 | } | |
31 | 31 | str | |
32 | 32 | } | |
33 | 33 | ||
34 | 34 | ||
35 | 35 | func getNumberByKey (key) = { | |
36 | 36 | let num = match getInteger(this, key) { | |
37 | 37 | case a: Int => | |
38 | 38 | a | |
39 | 39 | case _ => | |
40 | 40 | 0 | |
41 | 41 | } | |
42 | 42 | num | |
43 | 43 | } | |
44 | 44 | ||
45 | 45 | ||
46 | 46 | func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item)) | |
47 | 47 | ||
48 | 48 | ||
49 | 49 | func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item)) | |
50 | 50 | ||
51 | 51 | ||
52 | 52 | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) | |
53 | 53 | ||
54 | 54 | ||
55 | 55 | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
56 | 56 | ||
57 | 57 | ||
58 | 58 | @Callable(i) | |
59 | 59 | func purchaseOld (type) = { | |
60 | 60 | let pmt = extract(i.payment) | |
61 | 61 | if (isDefined(pmt.assetId)) | |
62 | 62 | then throw("can use WAVES only at the moment") | |
63 | 63 | else { | |
64 | 64 | let customerAddress = toBase58String(i.caller.bytes) | |
65 | 65 | let price = match getInteger(this, (("item_" + type) + "_coupon_price")) { | |
66 | 66 | case a: Int => | |
67 | 67 | a | |
68 | 68 | case _ => | |
69 | 69 | 0 | |
70 | 70 | } | |
71 | 71 | if ((price > pmt.amount)) | |
72 | 72 | then throw("purschase amount cannot be less than item price") | |
73 | 73 | else if ((pmt.amount > price)) | |
74 | 74 | then throw("purchase amount cannot be higher than item price") | |
75 | 75 | else WriteSet([DataEntry(((("status:purchase_item_" + type) + "_customer_") + customerAddress), "confirmed"), DataEntry(((("price:purchase_item_" + type) + "_customer_") + customerAddress), price)]) | |
76 | 76 | } | |
77 | 77 | } | |
78 | 78 | ||
79 | 79 | ||
80 | 80 | ||
81 | 81 | @Callable(i) | |
82 | 82 | func addItem (title,price,data) = { | |
83 | 83 | let supplierAddress = toBase58String(i.caller.bytes) | |
84 | 84 | let item = getKeyItem(supplierAddress, title) | |
85 | 85 | if ((0 >= price)) | |
86 | 86 | then throw("purchase amount cannot be less than item price") | |
87 | 87 | else if ((getValueItemSupplier(item) != NONE)) | |
88 | 88 | then throw("an items is already exist") | |
89 | 89 | else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddress), DataEntry(getKeyItemPrice(item), price), DataEntry(getKeyItemData(item), data)]) | |
90 | 90 | } | |
91 | 91 | ||
92 | 92 | ||
93 | 93 | ||
94 | 94 | @Callable(i) | |
95 | 95 | func purchase (item) = { | |
96 | 96 | let pmt = extract(i.payment) | |
97 | 97 | if (isDefined(pmt.assetId)) | |
98 | 98 | then throw("WAVES tokens only at the moment") | |
99 | 99 | else { | |
100 | 100 | let userAddress = toBase58String(i.caller.bytes) | |
101 | 101 | let price = getValueItemPrice(item) | |
102 | 102 | let supplierAddress = getValueItemSupplier(item) | |
103 | 103 | if ((price > pmt.amount)) | |
104 | 104 | then throw("purchase amount cannot be less than item price") | |
105 | 105 | else if ((pmt.amount > price)) | |
106 | 106 | then throw("purchase amount cannot be higher than item price") | |
107 | 107 | else if ((supplierAddress == NONE)) | |
108 | 108 | then throw("supplier does not exist") | |
109 | 109 | else WriteSet([DataEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), DataEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))]) | |
110 | 110 | } | |
111 | 111 | } | |
112 | 112 | ||
113 | 113 | ||
114 | + | ||
115 | + | @Callable(i) | |
116 | + | func withdraw () = { | |
117 | + | let supplierAddress = toBase58String(i.caller.bytes) | |
118 | + | let balance = getValueBalanceSupplier(supplierAddress) | |
119 | + | if ((0 >= balance)) | |
120 | + | then throw("insufficient balance") | |
121 | + | else ScriptResult(WriteSet([DataEntry(getKeyBalanceSupplier(supplierAddress), 0)]), TransferSet([ScriptTransfer(addressFromStringValue(supplierAddress), balance, unit)])) | |
122 | + | } | |
123 | + | ||
124 | + |
github/deemru/w8io/026f985 33.12 ms ◑