tx · AQgjFY4Fjpu7ridNAuiCcX3ZMyRYn4q5U9dv192pwRuA 3N7MT5t1Gmyb9tcpdoUrd47pxXtTkAcgLsR: -0.01400000 Waves 2019.07.14 03:26 [584693] smart account 3N7MT5t1Gmyb9tcpdoUrd47pxXtTkAcgLsR > SELF 0.00000000 Waves
{ "type": 13, "id": "AQgjFY4Fjpu7ridNAuiCcX3ZMyRYn4q5U9dv192pwRuA", "fee": 1400000, "feeAssetId": null, "timestamp": 1563064034309, "version": 1, "sender": "3N7MT5t1Gmyb9tcpdoUrd47pxXtTkAcgLsR", "senderPublicKey": "Adn8NfJZ8ZXuWNMXb9VaY6X6kh6k6G3KMb1WQUesFUV", "proofs": [ "3c4GYQbBZE4qwQsnTJ4H2NHkvW7moGKANEHH7rudMdQrJAVuPfPpqC3SEbJaEUL2qx8VJ2AveLNWzMTbxurGT75g" ], "script": "base64:AAIDAAAAAAAAAAAAAAAXAAAAAA5vd25lclB1YmxpY0tleQEAAAAgAnfP9tCFuj2k2BUY5PW9DVGxrCHBHKJwugv8WyiaGXIAAAAABE5PTkUCAAAABG5vbmUBAAAADmdldE51bWJlckJ5S2V5AAAAAQAAAANrZXkEAAAAA251bQQAAAAHJG1hdGNoMAkABBoAAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAA0ludAQAAAABYQUAAAAHJG1hdGNoMAUAAAABYQAAAAAAAAAAAAUAAAADbnVtAQAAAAtnZXRTdHJCeUtleQAAAAEAAAADa2V5BAAAAANzdHIEAAAAByRtYXRjaDAJAAQdAAAAAgUAAAAEdGhpcwUAAAADa2V5AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAAZTdHJpbmcEAAAAAWEFAAAAByRtYXRjaDAFAAAAAWEFAAAABE5PTkUFAAAAA3N0cgEAAAAPZ2V0S2V5SXRlbVByaWNlAAAAAQAAAARpdGVtCQABLAAAAAIFAAAABGl0ZW0CAAAABl9wcmljZQEAAAARZ2V0VmFsdW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HJhbnNhY3Rpb24EAAAAAWQFAAAAByRtYXRjaDAJAAH0AAAAAwgFAAAAAnR4AAAACWJvZHlCeXRlcwkAAZEAAAACCAUAAAACdHgAAAAGcHJvb2ZzAAAAAAAAAAAABQAAAA5vd25lclB1YmxpY0tleQMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAAPRGF0YVRyYW5zYWN0aW9uBAAAAAFkBQAAAAckbWF0Y2gwBgdHJ5JC", "chainId": 84, "height": 584693, "spentComplexity": 0 } View: original | compacted Prev: 9zkvzo8pJgcQaSPVWyMXXr2y8BDei9NygdLaKajvQJLN Next: 4a2cDu64bQgMpnYozKHBxabDH3kUCuzSkpGgHbs64YN1 Diff:
Old | New | Differences | |
---|---|---|---|
90 | 90 | if (isDefined(pmt.assetId)) | |
91 | 91 | then throw("can use WAVES only at the moment") | |
92 | 92 | else { | |
93 | - | let | |
93 | + | let userAddress = toBase58String(i.caller.bytes) | |
94 | 94 | let price = getValueItemPrice(item) | |
95 | 95 | let supplierAddress = getValueItemSupplier(item) | |
96 | 96 | if ((price > pmt.amount)) | |
97 | 97 | then throw("purchase amount cannot be less than item price") | |
98 | 98 | else if ((pmt.amount > price)) | |
99 | 99 | then throw("purchase amount cannot be higher than item price") | |
100 | - | else WriteSet([DataEntry(("status:purchase_item_A_customer_" + customerAddress), "confirmed"), DataEntry(("price:purchase_item_A_customer_" + customerAddress), price)]) | |
100 | + | else if ((supplierAddress == NONE)) | |
101 | + | then throw("supplier does not exist") | |
102 | + | else WriteSet([DataEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), DataEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))]) | |
101 | 103 | } | |
102 | 104 | } | |
103 | 105 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let ownerPublicKey = base58'Adn8NfJZ8ZXuWNMXb9VaY6X6kh6k6G3KMb1WQUesFUV' | |
5 | 5 | ||
6 | 6 | let NONE = "none" | |
7 | 7 | ||
8 | 8 | func getNumberByKey (key) = { | |
9 | 9 | let num = match getInteger(this, key) { | |
10 | 10 | case a: Int => | |
11 | 11 | a | |
12 | 12 | case _ => | |
13 | 13 | 0 | |
14 | 14 | } | |
15 | 15 | num | |
16 | 16 | } | |
17 | 17 | ||
18 | 18 | ||
19 | 19 | func getStrByKey (key) = { | |
20 | 20 | let str = match getString(this, key) { | |
21 | 21 | case a: String => | |
22 | 22 | a | |
23 | 23 | case _ => | |
24 | 24 | NONE | |
25 | 25 | } | |
26 | 26 | str | |
27 | 27 | } | |
28 | 28 | ||
29 | 29 | ||
30 | 30 | func getKeyItemPrice (item) = (item + "_price") | |
31 | 31 | ||
32 | 32 | ||
33 | 33 | func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item)) | |
34 | 34 | ||
35 | 35 | ||
36 | 36 | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt") | |
37 | 37 | ||
38 | 38 | ||
39 | 39 | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) | |
40 | 40 | ||
41 | 41 | ||
42 | 42 | func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title))))) | |
43 | 43 | ||
44 | 44 | ||
45 | 45 | func getKeyItemData (item) = (item + "_data") | |
46 | 46 | ||
47 | 47 | ||
48 | 48 | func getKeyItemSupplier (item) = (item + "_owner") | |
49 | 49 | ||
50 | 50 | ||
51 | 51 | func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item)) | |
52 | 52 | ||
53 | 53 | ||
54 | 54 | func getKeyBalanceSupplier (account) = (account + "_balance") | |
55 | 55 | ||
56 | 56 | ||
57 | 57 | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
58 | 58 | ||
59 | 59 | ||
60 | 60 | func getKeyCommit (item,user) = (((item + "_") + user) + "_commit") | |
61 | 61 | ||
62 | 62 | ||
63 | 63 | func getValueCommit (item,user) = getStrByKey(getKeyCommit(item, user)) | |
64 | 64 | ||
65 | 65 | ||
66 | 66 | func getKeyCommitsCount (item) = (item + "_comcnt") | |
67 | 67 | ||
68 | 68 | ||
69 | 69 | func getValueCommitsCount (item) = getNumberByKey(getKeyCommitsCount(item)) | |
70 | 70 | ||
71 | 71 | ||
72 | 72 | func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal") | |
73 | 73 | ||
74 | 74 | ||
75 | 75 | func getValueReveal (item,user) = getStrByKey(getKeyReveal(item, user)) | |
76 | 76 | ||
77 | 77 | ||
78 | 78 | func getKeyItemStatus (item) = (item + "_status") | |
79 | 79 | ||
80 | 80 | ||
81 | 81 | func getValueItemStatus (item) = getStrByKey(getKeyItemStatus(item)) | |
82 | 82 | ||
83 | 83 | ||
84 | 84 | func getKeyVoteCount (item,vote) = ((item + "_res:") + vote) | |
85 | 85 | ||
86 | 86 | ||
87 | 87 | @Callable(i) | |
88 | 88 | func purchase (item) = { | |
89 | 89 | let pmt = extract(i.payment) | |
90 | 90 | if (isDefined(pmt.assetId)) | |
91 | 91 | then throw("can use WAVES only at the moment") | |
92 | 92 | else { | |
93 | - | let | |
93 | + | let userAddress = toBase58String(i.caller.bytes) | |
94 | 94 | let price = getValueItemPrice(item) | |
95 | 95 | let supplierAddress = getValueItemSupplier(item) | |
96 | 96 | if ((price > pmt.amount)) | |
97 | 97 | then throw("purchase amount cannot be less than item price") | |
98 | 98 | else if ((pmt.amount > price)) | |
99 | 99 | then throw("purchase amount cannot be higher than item price") | |
100 | - | else WriteSet([DataEntry(("status:purchase_item_A_customer_" + customerAddress), "confirmed"), DataEntry(("price:purchase_item_A_customer_" + customerAddress), price)]) | |
100 | + | else if ((supplierAddress == NONE)) | |
101 | + | then throw("supplier does not exist") | |
102 | + | else WriteSet([DataEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), DataEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))]) | |
101 | 103 | } | |
102 | 104 | } | |
103 | 105 | ||
104 | 106 | ||
105 | 107 | ||
106 | 108 | @Callable(i) | |
107 | 109 | func addItem (title,price,data) = { | |
108 | 110 | let supplierAddress = toBase58String(i.caller.bytes) | |
109 | 111 | let item = getKeyItem(supplierAddress, title) | |
110 | 112 | if ((0 >= price)) | |
111 | 113 | then throw("purchase amount cannot be less than item price") | |
112 | 114 | else if ((getValueItemSupplier(item) != NONE)) | |
113 | 115 | then throw("an item is already exist") | |
114 | 116 | else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddress), DataEntry(getKeyItemPrice(item), price), DataEntry(getKeyItemData(item), data)]) | |
115 | 117 | } | |
116 | 118 | ||
117 | 119 | ||
118 | 120 | @Verifier(tx) | |
119 | 121 | func verify () = match tx { | |
120 | 122 | case d: SetScriptTransaction => | |
121 | 123 | sigVerify(tx.bodyBytes, tx.proofs[0], ownerPublicKey) | |
122 | 124 | case d: DataTransaction => | |
123 | 125 | true | |
124 | 126 | case _ => | |
125 | 127 | false | |
126 | 128 | } | |
127 | 129 |
github/deemru/w8io/169f3d6 46.28 ms ◑