tx · 2fDJQmdrdLcqSUnmcP5JRcpsttcjNMTJSGRC9p9u6Xbt 3MqiiiD5GiCgJENfvC6HA8MyUeZfX1fB4yD: -0.01400000 Waves 2019.06.25 10:38 [557333] smart account 3MqiiiD5GiCgJENfvC6HA8MyUeZfX1fB4yD > SELF 0.00000000 Waves
{ "type": 13, "id": "2fDJQmdrdLcqSUnmcP5JRcpsttcjNMTJSGRC9p9u6Xbt", "fee": 1400000, "feeAssetId": null, "timestamp": 1561448400592, "version": 1, "sender": "3MqiiiD5GiCgJENfvC6HA8MyUeZfX1fB4yD", "senderPublicKey": "2XEK2wpQ5tXMZdzxJPyGzitzHyVyQxp3WT9Ekxe8br7N", "proofs": [ "oYDFLaTwdsSqt12fbL9enhLS1Nb9orx9SMzgq2xDCYuYVq9UgvJsnFQQeugJHLWsMGLpoA4j4HJbUUH1rCdR64D" ], "script": "base64:AAIDAAAAAAAAAAAAAAANAAAAAAROT05FAgAAAARub25lAQAAAA5nZXROdW1iZXJCeUtleQAAAAEAAAADa2V5BAAAAANudW0EAAAAByRtYXRjaDAJAAQaAAAAAgUAAAAEdGhpcwUAAAADa2V5AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAANJbnQEAAAAAWEFAAAAByRtYXRjaDAFAAAAAWEAAAAAAAAAAAAFAAAAA251bQEAAAALZ2V0U3RyQnlLZXkAAAABAAAAA2tleQQAAAADc3RyBAAAAAckbWF0Y2gwCQAEHQAAAAIFAAAABHRoaXMFAAAAA2tleQMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAAGU3RyaW5nBAAAAAFhBQAAAAckbWF0Y2gwBQAAAAFhBQAAAAROT05FBQAAAANzdHIBAAAAD2dldEtleUl0ZW1QcmljZQAAAAEAAAAEaXRlbQkAASwAAAACBQAAAARpdGVtAgAAAAZfcHJpY2UBAAAAEWdldFZhbHVlSXRlbVByaWNlAAAAAQAAAARpdGVtCQEAAAAOZ2V0TnVtYmVyQnlLZXkAAAABCQEAAAAPZ2V0S2V5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JAQAAABdnZXRWYWx1ZUJhbGFuY2VTdXBwbGllcgAAAAEFAAAAD3N1cHBsaWVyQWRkcmVzcwgFAAAAA3BtdAAAAAZhbW91bnQFAAAAA25pbAAAAAFpAQAAAAdhZGRJdGVtAAAAAwAAAAV0aXRsZQAAAAVwcmljZQAAAARkYXRhBAAAAA9zdXBwbGllckFkZHJlc3MJAAJYAAAAAQgIBQAAAAFpAAAABmNhbGxlcgAAAAVieXRlcwQAAAAEaXRlbQkBAAAACmdldEtleUl0ZW0AAAACBQAAAA9zdXBwbGllckFkZHJlc3MFAAAABXRpdGxlAwkAAGcAAAACAAAAAAAAAAAABQAAAAVwcmljZQkAAAIAAAABAgAAAC5wdXJjaGFzZSBhbW91bnQgY2Fubm90IGJlIGxlc3MgdGhhbiBpdGVtIHByaWNlAwkBAAAAAiE9AAAAAgkBAAAAFGdldFZhbHVlSXRlbVN1cHBsaWVyAAAAAQUAAAAEaXRlbQUAAAAETk9ORQkAAAIAAAABAgAAABNJdGVtIGFscmVhZHkgZXhpc3RzCQEAAAAIV3JpdGVTZXQAAAABCQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACCQEAAAASZ2V0S2V5SXRlbVN1cHBsaWVyAAAAAQUAAAAEaXRlbQUAAAAPc3VwcGxpZXJBZGRyZXNzCQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACCQEAAAAPZ2V0S2V5SXRlbVByaWNlAAAAAQUAAAAEaXRlbQUAAAAFcHJpY2UJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAQAAAA5nZXRLZXlJdGVtRGF0YQAAAAEFAAAABGl0ZW0FAAAABGRhdGEFAAAAA25pbAAAAAD0XuUO", "chainId": 84, "height": 557333, "spentComplexity": 0 } View: original | compacted Prev: GZKEkGekm23j9ghNpfdmbEZmqzsuM1YdfWFsjrhYmYP2 Next: GcqDgYMmS8iQH7AvXpnhZo2fU9wvmK9AKoDswj5SYyJM Diff:
Old | New | Differences | |
---|---|---|---|
56 | 56 | ||
57 | 57 | ||
58 | 58 | @Callable(i) | |
59 | - | func purchase ( | |
59 | + | func purchase (item) = { | |
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 | - | let customerAddress = toBase58String(i.caller.bytes) | |
65 | - | let price = match getInteger(this, (("item_" + itemName) + "_coupon_price")) { | |
66 | - | case a: Int => | |
67 | - | a | |
68 | - | case _ => | |
69 | - | 0 | |
70 | - | } | |
64 | + | let userAddress = toBase58String(i.caller.bytes) | |
65 | + | let price = getValueItemPrice(item) | |
66 | + | let supplierAddress = getValueItemSupplier(item) | |
71 | 67 | if ((price > pmt.amount)) | |
72 | 68 | then throw("purchase amount cannot be less than item price") | |
73 | 69 | else if ((pmt.amount > price)) | |
74 | 70 | then throw("purchase amount cannot be higher than item price") | |
75 | - | else WriteSet([DataEntry(((("status:purchase_item_" + itemName) + "_customer_") + customerAddress), "confirmed"), DataEntry(((("price:purchase_item_" + itemName) + "_customer_") + customerAddress), price)]) | |
71 | + | else if ((supplierAddress == NONE)) | |
72 | + | then throw("supplier does not exist") | |
73 | + | else WriteSet([DataEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), DataEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))]) | |
76 | 74 | } | |
77 | 75 | } | |
78 | 76 |
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 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,item) = ("item_" + toBase58String(sha256(toBytes((supplier + item))))) | |
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 (item) = getNumberByKey(getKeyBalanceSupplier(item)) | |
56 | 56 | ||
57 | 57 | ||
58 | 58 | @Callable(i) | |
59 | - | func purchase ( | |
59 | + | func purchase (item) = { | |
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 | - | let customerAddress = toBase58String(i.caller.bytes) | |
65 | - | let price = match getInteger(this, (("item_" + itemName) + "_coupon_price")) { | |
66 | - | case a: Int => | |
67 | - | a | |
68 | - | case _ => | |
69 | - | 0 | |
70 | - | } | |
64 | + | let userAddress = toBase58String(i.caller.bytes) | |
65 | + | let price = getValueItemPrice(item) | |
66 | + | let supplierAddress = getValueItemSupplier(item) | |
71 | 67 | if ((price > pmt.amount)) | |
72 | 68 | then throw("purchase amount cannot be less than item price") | |
73 | 69 | else if ((pmt.amount > price)) | |
74 | 70 | then throw("purchase amount cannot be higher than item price") | |
75 | - | else WriteSet([DataEntry(((("status:purchase_item_" + itemName) + "_customer_") + customerAddress), "confirmed"), DataEntry(((("price:purchase_item_" + itemName) + "_customer_") + customerAddress), price)]) | |
71 | + | else if ((supplierAddress == NONE)) | |
72 | + | then throw("supplier does not exist") | |
73 | + | else WriteSet([DataEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), DataEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))]) | |
76 | 74 | } | |
77 | 75 | } | |
78 | 76 | ||
79 | 77 | ||
80 | 78 | ||
81 | 79 | @Callable(i) | |
82 | 80 | func addItem (title,price,data) = { | |
83 | 81 | let supplierAddress = toBase58String(i.caller.bytes) | |
84 | 82 | let item = getKeyItem(supplierAddress, title) | |
85 | 83 | if ((0 >= price)) | |
86 | 84 | then throw("purchase amount cannot be less than item price") | |
87 | 85 | else if ((getValueItemSupplier(item) != NONE)) | |
88 | 86 | then throw("Item already exists") | |
89 | 87 | else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddress), DataEntry(getKeyItemPrice(item), price), DataEntry(getKeyItemData(item), data)]) | |
90 | 88 | } | |
91 | 89 | ||
92 | 90 |
github/deemru/w8io/169f3d6 39.97 ms ◑