tx · 6rr5gB1aUUUfoLkEUaB8v9sF6Ry6sofR6sK8StZdPD5u 3MrDcz4LFFjPhXdtu7YCqFSnHc3pD1tcWLa: -0.01000000 Waves 2019.08.14 18:23 [630916] smart account 3MrDcz4LFFjPhXdtu7YCqFSnHc3pD1tcWLa > SELF 0.00000000 Waves
{ "type": 13, "id": "6rr5gB1aUUUfoLkEUaB8v9sF6Ry6sofR6sK8StZdPD5u", "fee": 1000000, "feeAssetId": null, "timestamp": 1565796229860, "version": 1, "sender": "3MrDcz4LFFjPhXdtu7YCqFSnHc3pD1tcWLa", "senderPublicKey": "DMndfYeRYfHnVPek52VfuzXJS3A6UJRZrSJX6PMqMMjD", "proofs": [ "2BLiZa9upJKT5SEYUvWmJrzXeeYPV7nW8K5ZwNkmbRLmVYVDRuSr8icsnRZWJs3sg3D1c5oGxeeJWfJgVHHPtb9S" ], "script": "base64:AAIDAAAAAAAAAAAAAAAHAAAAAAx3YXZlc0Fzc2V0SWQBAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAhnZXRQcmljZQAAAAEAAAAEZGF0YQkABLEAAAABCQAAyQAAAAIFAAAABGRhdGEAAAAAAAAAAAgBAAAACGdldFN0b2NrAAAAAQAAAARkYXRhCQAEsQAAAAEJAADJAAAAAgkAAMoAAAACBQAAAARkYXRhAAAAAAAAAAAIAAAAAAAAAAAIAQAAAA5nZXRBbW91bnRBc3NldAAAAAEAAAAEZGF0YQkAAMkAAAACCQAAygAAAAIFAAAABGRhdGEJAABkAAAAAgkAAGQAAAACAAAAAAAAAAAIAAAAAAAAAAAIAAAAAAAAAAAgAAAAAAAAAAAgAQAAAAlnZXRTZWxsZXIAAAABAAAABGRhdGEJAADKAAAAAgUAAAAEZGF0YQkAAGQAAAACCQAAZAAAAAIJAABkAAAAAgAAAAAAAAAACAAAAAAAAAAACAAAAAAAAAAAIAAAAAAAAAAAIAEAAAANZ2V0UHJpY2VBc3NldAAAAAEAAAAEZGF0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gc2hvdWxkIGJlOiAJAAGkAAAAAQkAAGgAAAACBQAAAAthbW91bnRUb0J1eQUAAAAFcHJpY2UCAAAAAS4DCQAAZgAAAAIFAAAAC2Ftb3VudFRvQnV5BQAAAAVzdG9jawkAAAIAAAABAgAAABpOb3QgZW5vdWdoIGl0ZW1zIGluIHN0b2NrLgMJAQAAAAIhPQAAAAIFAAAACnByaWNlQXNzZXQIBQAAAAFwAAAAB2Fzc2V0SWQJAAACAAAAAQIAAAAWSW52YWxpZCBwYXltZW50IGFzc2V0LgkBAAAADFNjcmlwdFJlc3VsdAAAAAIJAQAAAAhXcml0ZVNldAAAAAEJAARMAAAAAgkBAAAACXNlcmlhbGl6ZQAAAAYFAAAABWxvdElkBQAAAAVwcmljZQkAAGUAAAACBQAAAAVzdG9jawUAAAALYW1vdW50VG9CdXkFAAAACnByaWNlQXNzZXQFAAAAC2Ftb3VudEFzc2V0BQAAAAZzZWxsZXIFAAAAA25pbAkBAAAAC1RyYW5zZmVyU2V0AAAAAQkABEwAAAACCQEAAAAOU2NyaXB0VHJhbnNmZXIAAAADCAUAAAABaQAAAAZjYWxsZXIFAAAAC2Ftb3VudFRvQnV5BQAAAAthbW91bnRBc3NldAkABEwAAAACCQEAAAAOU2NyaXB0VHJhbnNmZXIAAAADCQEAAAAUYWRkcmVzc0Zyb21QdWJsaWNLZXkAAAABBQAAAAZzZWxsZXIFAAAABXByaWNlBQAAAApwcmljZUFzc2V0BQAAAANuaWwAAAAA8kR/qg==", "chainId": 84, "height": 630916, "spentComplexity": 0 } View: original | compacted Prev: none Next: 3JyvVexJAg7yTwqPJGPyVDigVgXafJq8mULgu5T62eat 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 ((size(priceAsset) != 32)) | |
55 | + | then throw((("Invalid asset: " + toBase58String(priceAsset)) + ", expected price asset size should be 32.")) | |
56 | + | else if ((0 >= price)) | |
57 | + | then throw((("Invalid price: " + toString(price)) + ", expected price should be greater than zero.")) | |
58 | + | else if ((0 >= p.amount)) | |
59 | + | then throw((("Invalid amount for sell: " + toString(p.amount)) + ", expected amount should be greater than zero.")) | |
60 | + | else WriteSet([serialize(i.transactionId, price, p.amount, priceAsset, extract(extract(i.payment).assetId), i.callerPublicKey)]) | |
61 | + | } | |
62 | + | ||
63 | + | ||
64 | + | ||
65 | + | @Callable(i) | |
66 | + | func cancel (lotId) = { | |
67 | + | let data = extract(getBinary(this, lotId)) | |
68 | + | let price = toInt(take(data, 8)) | |
69 | + | let amount = toInt(take(drop(data, 0), 8)) | |
70 | + | let priceAsset = take(drop(data, (8 + 8)), 32) | |
71 | + | let amountAsset = take(drop(data, ((8 + 8) + 32)), 32) | |
72 | + | let seller = drop(data, (((8 + 8) + 32) + 32)) | |
73 | + | if ((seller != i.callerPublicKey)) | |
74 | + | then throw("Only seller can cancel the lot.") | |
75 | + | else ScriptResult(WriteSet([serialize(lotId, price, 0, priceAsset, amountAsset, seller)]), TransferSet([ScriptTransfer(addressFromPublicKey(seller), amount, amountAsset)])) | |
76 | + | } | |
77 | + | ||
78 | + | ||
79 | + | ||
80 | + | @Callable(i) | |
81 | + | func buy (lotId,amountToBuy) = { | |
82 | + | let data = extract(getBinary(this, lotId)) | |
83 | + | let price = getPrice(data) | |
84 | + | let stock = getStock(data) | |
85 | + | let priceAsset = getPriceAsset(data) | |
86 | + | let amountAsset = getAmountAsset(data) | |
87 | + | let seller = getSeller(data) | |
88 | + | let p = extract(i.payment) | |
89 | + | if ((0 >= stock)) | |
90 | + | then throw("Lot is closed or cancelled, 0 items in stock.") | |
91 | + | else if ((p.assetId == wavesAssetId)) | |
92 | + | then throw("Invalid payment asset.") | |
93 | + | else if ((0 >= amountToBuy)) | |
94 | + | then throw((("Invalid amount to buy: " + toString(amountToBuy)) + ", expected amount should be greater than zero.")) | |
95 | + | else if (((amountToBuy * price) != p.amount)) | |
96 | + | then throw((((("Invalid payment amount: " + toString(p.amount)) + ", expected amount should be: ") + toString((amountToBuy * price))) + ".")) | |
97 | + | else if ((amountToBuy > stock)) | |
98 | + | then throw("Not enough items in stock.") | |
99 | + | else if ((priceAsset != p.assetId)) | |
100 | + | then throw("Invalid payment asset.") | |
101 | + | else ScriptResult(WriteSet([serialize(lotId, price, (stock - amountToBuy), priceAsset, amountAsset, seller)]), TransferSet([ScriptTransfer(i.caller, amountToBuy, amountAsset), ScriptTransfer(addressFromPublicKey(seller), price, priceAsset)])) | |
102 | + | } | |
103 | + | ||
104 | + |
github/deemru/w8io/026f985 16.29 ms ◑