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