tx · 3JyvVexJAg7yTwqPJGPyVDigVgXafJq8mULgu5T62eat 3MrDcz4LFFjPhXdtu7YCqFSnHc3pD1tcWLa: -0.01400000 Waves 2019.08.17 12:31 [634920] smart account 3MrDcz4LFFjPhXdtu7YCqFSnHc3pD1tcWLa > SELF 0.00000000 Waves
{ "type": 13, "id": "3JyvVexJAg7yTwqPJGPyVDigVgXafJq8mULgu5T62eat", "fee": 1400000, "feeAssetId": null, "timestamp": 1566034329651, "version": 1, "sender": "3MrDcz4LFFjPhXdtu7YCqFSnHc3pD1tcWLa", "senderPublicKey": "DMndfYeRYfHnVPek52VfuzXJS3A6UJRZrSJX6PMqMMjD", "proofs": [ "2Fy1Hppi2dodYnc8AAKah1YQxzXXkFdFYCXBntbR7fZMq6Rwq6TGS2UwPTVSeUYZ5gmBpRBuSss5UbMy9z3qEggo" ], "script": "base64:AAIDAAAAAAAAAAAAAAAHAAAAAAx3YXZlc0Fzc2V0SWQBAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAhnZXRQcmljZQAAAAEAAAAEZGF0YQkABLEAAAABCQAAyQAAAAIFAAAABGRhdGEAAAAAAAAAAAgBAAAACGdldFN0b2NrAAAAAQAAAARkYXRhCQAEsQAAAAEJAADJAAAAAgkAAMoAAAACBQAAAARkYXRhAAAAAAAAAAAIAAAAAAAAAAAIAQAAAA5nZXRBbW91bnRBc3NldAAAAAEAAAAEZGF0YQkAAMkAAAACCQAAygAAAAIFAAAABGRhdGEJAABkAAAAAgkAAGQAAAACAAAAAAAAAAAIAAAAAAAAAAAIAAAAAAAAAAAgAAAAAAAAAAAgAQAAAAlnZXRTZWxsZXIAAAABAAAABGRhdGEJAADKAAAAAgUAAAAEZGF0YQkAAGQAAAACCQAAZAAAAAIJAABkAAAAAgAAAAAAAAAACAAAAAAAAAAACAAAAAAAAAAAIAAAAAAAAAAAIAEAAAANZ2V0UHJpY2VBc3NldAAAAAEAAAAEZGF0YQQAAAACcHIJ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2VBc3NldAgFAAAAAXAAAAAHYXNzZXRJZAkAAAIAAAABAgAAABZJbnZhbGlkIHBheW1lbnQgYXNzZXQuCQEAAAAMU2NyaXB0UmVzdWx0AAAAAgkBAAAACFdyaXRlU2V0AAAAAQkABEwAAAACCQEAAAAJc2VyaWFsaXplAAAABgUAAAAFbG90SWQFAAAABXByaWNlCQAAZQAAAAIFAAAABXN0b2NrBQAAAAthbW91bnRUb0J1eQUAAAAKcHJpY2VBc3NldAUAAAALYW1vdW50QXNzZXQFAAAABnNlbGxlcgUAAAADbmlsCQEAAAALVHJhbnNmZXJTZXQAAAABCQAETAAAAAIJAQAAAA5TY3JpcHRUcmFuc2ZlcgAAAAMIBQAAAAFpAAAABmNhbGxlcgUAAAALYW1vdW50VG9CdXkFAAAAC2Ftb3VudEFzc2V0CQAETAAAAAIJAQAAAA5TY3JpcHRUcmFuc2ZlcgAAAAMJAQAAABRhZGRyZXNzRnJvbVB1YmxpY0tleQAAAAEFAAAABnNlbGxlcgUAAAAFcHJpY2UFAAAACnByaWNlQXNzZXQFAAAAA25pbAAAAAA6h7OJ", "chainId": 84, "height": 634920, "spentComplexity": 0 } View: original | compacted Prev: 6rr5gB1aUUUfoLkEUaB8v9sF6Ry6sofR6sK8StZdPD5u Next: none Diff:
Old | New | Differences | |
---|---|---|---|
65 | 65 | @Callable(i) | |
66 | 66 | func cancel (lotId) = { | |
67 | 67 | let data = extract(getBinary(this, lotId)) | |
68 | - | let price = | |
69 | - | let | |
70 | - | let priceAsset = | |
71 | - | let amountAsset = | |
72 | - | let seller = | |
68 | + | let price = getPrice(data) | |
69 | + | let stock = getStock(data) | |
70 | + | let priceAsset = getPriceAsset(data) | |
71 | + | let amountAsset = getAmountAsset(data) | |
72 | + | let seller = getSeller(data) | |
73 | 73 | if ((seller != i.callerPublicKey)) | |
74 | 74 | then throw("Only seller can cancel the lot.") | |
75 | - | else ScriptResult(WriteSet([serialize(lotId, price, 0, priceAsset, amountAsset, seller)]), TransferSet([ScriptTransfer(addressFromPublicKey(seller), | |
75 | + | else ScriptResult(WriteSet([serialize(lotId, price, 0, priceAsset, amountAsset, seller)]), TransferSet([ScriptTransfer(addressFromPublicKey(seller), stock, amountAsset)])) | |
76 | 76 | } | |
77 | 77 | ||
78 | 78 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let wavesAssetId = base58'11111111111111111111111111111111' | |
5 | 5 | ||
6 | 6 | func getPrice (data) = toInt(take(data, 8)) | |
7 | 7 | ||
8 | 8 | ||
9 | 9 | func getStock (data) = toInt(take(drop(data, 8), 8)) | |
10 | 10 | ||
11 | 11 | ||
12 | 12 | func getAmountAsset (data) = take(drop(data, ((8 + 8) + 32)), 32) | |
13 | 13 | ||
14 | 14 | ||
15 | 15 | func getSeller (data) = drop(data, (((8 + 8) + 32) + 32)) | |
16 | 16 | ||
17 | 17 | ||
18 | 18 | func getPriceAsset (data) = { | |
19 | 19 | let pr = take(drop(data, (8 + 8)), 32) | |
20 | 20 | if ((pr == wavesAssetId)) | |
21 | 21 | then unit | |
22 | 22 | else pr | |
23 | 23 | } | |
24 | 24 | ||
25 | 25 | ||
26 | 26 | func serialize (lotId,price,stock,priceAsset,amountAsset,seller) = { | |
27 | 27 | let idAsString = match lotId { | |
28 | 28 | case s: String => | |
29 | 29 | s | |
30 | 30 | case bv: ByteVector => | |
31 | 31 | toBase58String(bv) | |
32 | 32 | case _ => | |
33 | 33 | throw() | |
34 | 34 | } | |
35 | 35 | let priceAssetBytes = match priceAsset { | |
36 | 36 | case u: Unit => | |
37 | 37 | wavesAssetId | |
38 | 38 | case bv: ByteVector => | |
39 | 39 | bv | |
40 | 40 | case _ => | |
41 | 41 | throw() | |
42 | 42 | } | |
43 | 43 | DataEntry(idAsString, ((((toBytes(price) + toBytes(stock)) + priceAssetBytes) + amountAsset) + seller)) | |
44 | 44 | } | |
45 | 45 | ||
46 | 46 | ||
47 | 47 | @Callable(i) | |
48 | 48 | func sell (price,priceAsset) = { | |
49 | 49 | let p = extract(i.payment) | |
50 | 50 | if (if ((p.assetId == unit)) | |
51 | 51 | then true | |
52 | 52 | else (p.assetId == wavesAssetId)) | |
53 | 53 | then throw("Invalid asset to sell.") | |
54 | 54 | else if ((size(priceAsset) != 32)) | |
55 | 55 | then throw((("Invalid asset: " + toBase58String(priceAsset)) + ", expected price asset size should be 32.")) | |
56 | 56 | else if ((0 >= price)) | |
57 | 57 | then throw((("Invalid price: " + toString(price)) + ", expected price should be greater than zero.")) | |
58 | 58 | else if ((0 >= p.amount)) | |
59 | 59 | then throw((("Invalid amount for sell: " + toString(p.amount)) + ", expected amount should be greater than zero.")) | |
60 | 60 | else WriteSet([serialize(i.transactionId, price, p.amount, priceAsset, extract(extract(i.payment).assetId), i.callerPublicKey)]) | |
61 | 61 | } | |
62 | 62 | ||
63 | 63 | ||
64 | 64 | ||
65 | 65 | @Callable(i) | |
66 | 66 | func cancel (lotId) = { | |
67 | 67 | let data = extract(getBinary(this, lotId)) | |
68 | - | let price = | |
69 | - | let | |
70 | - | let priceAsset = | |
71 | - | let amountAsset = | |
72 | - | let seller = | |
68 | + | let price = getPrice(data) | |
69 | + | let stock = getStock(data) | |
70 | + | let priceAsset = getPriceAsset(data) | |
71 | + | let amountAsset = getAmountAsset(data) | |
72 | + | let seller = getSeller(data) | |
73 | 73 | if ((seller != i.callerPublicKey)) | |
74 | 74 | then throw("Only seller can cancel the lot.") | |
75 | - | else ScriptResult(WriteSet([serialize(lotId, price, 0, priceAsset, amountAsset, seller)]), TransferSet([ScriptTransfer(addressFromPublicKey(seller), | |
75 | + | else ScriptResult(WriteSet([serialize(lotId, price, 0, priceAsset, amountAsset, seller)]), TransferSet([ScriptTransfer(addressFromPublicKey(seller), stock, amountAsset)])) | |
76 | 76 | } | |
77 | 77 | ||
78 | 78 | ||
79 | 79 | ||
80 | 80 | @Callable(i) | |
81 | 81 | func buy (lotId,amountToBuy) = { | |
82 | 82 | let data = extract(getBinary(this, lotId)) | |
83 | 83 | let price = getPrice(data) | |
84 | 84 | let stock = getStock(data) | |
85 | 85 | let priceAsset = getPriceAsset(data) | |
86 | 86 | let amountAsset = getAmountAsset(data) | |
87 | 87 | let seller = getSeller(data) | |
88 | 88 | let p = extract(i.payment) | |
89 | 89 | if ((0 >= stock)) | |
90 | 90 | then throw("Lot is closed or cancelled, 0 items in stock.") | |
91 | 91 | else if ((p.assetId == wavesAssetId)) | |
92 | 92 | then throw("Invalid payment asset.") | |
93 | 93 | else if ((0 >= amountToBuy)) | |
94 | 94 | then throw((("Invalid amount to buy: " + toString(amountToBuy)) + ", expected amount should be greater than zero.")) | |
95 | 95 | else if (((amountToBuy * price) != p.amount)) | |
96 | 96 | then throw((((("Invalid payment amount: " + toString(p.amount)) + ", expected amount should be: ") + toString((amountToBuy * price))) + ".")) | |
97 | 97 | else if ((amountToBuy > stock)) | |
98 | 98 | then throw("Not enough items in stock.") | |
99 | 99 | else if ((priceAsset != p.assetId)) | |
100 | 100 | then throw("Invalid payment asset.") | |
101 | 101 | else ScriptResult(WriteSet([serialize(lotId, price, (stock - amountToBuy), priceAsset, amountAsset, seller)]), TransferSet([ScriptTransfer(i.caller, amountToBuy, amountAsset), ScriptTransfer(addressFromPublicKey(seller), price, priceAsset)])) | |
102 | 102 | } | |
103 | 103 | ||
104 | 104 |
github/deemru/w8io/026f985 39.30 ms ◑