tx · 8frZQhPeixqbDX2nG8ATUPTfa9Y5yJRFhkYmd8giUgs8 3MuiTP4cDghsjfjQ6cWf9fDEo69GMNDM5Xk: -0.01000000 Waves 2020.07.01 16:50 [1068051] smart account 3MuiTP4cDghsjfjQ6cWf9fDEo69GMNDM5Xk > SELF 0.00000000 Waves
{ "type": 13, "id": "8frZQhPeixqbDX2nG8ATUPTfa9Y5yJRFhkYmd8giUgs8", "fee": 1000000, "feeAssetId": null, "timestamp": 1593611475955, "version": 1, "sender": "3MuiTP4cDghsjfjQ6cWf9fDEo69GMNDM5Xk", "senderPublicKey": "wbrMRFrDGSugEDAY1Rs32wnhRhtQX4ufaZgDgJ5qdE5", "proofs": [ "3dkhQGKRg8ZdLMmLyNytwgYUbqD4w7wz9GkivYJFAxdRoEaBo1ycVp9wQweQBJGUNgRumPhC6seNbXZQ4ruKUqS1" ], "script": "base64:AAIDAAAAAAAAABMIARIECgIBAhIDCgEIEgQKAggBAAAABwAAAAAMd2F2ZXNBc3NldElkAQAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAIZ2V0UHJpY2UAAAABAAAABGRhdGEJAASxAAAAAQkAAMkAAAACBQAAAARkYXRhAAAAAAAAAAAIAQAAAAhnZXRTdG9jawAAAAEAAAAEZGF0YQkABLEAAAABCQAAyQAAAAIJAADKAAAAAgUAAAAEZGF0YQAAAAAAAAAACAAAAAAAAAAACAEAAAAOZ2V0QW1vdW50QXNzZXQAAAABAAAABGRhdGEJAADJAAAAAgkAAMoAAAACBQAAAARkYXRhCQAAZAAAAAIJAABkAAAAAgAAAAAAAAAACAAAAAAAAAAACAAAAAAAAAAAIAAAAAAAAAAAIAEAAAAJZ2V0U2VsbGVyAAAAAQAAAARkYXRhCQAAygAAAAIFAAAABGRhdGEJAABkAAAAAgkAAGQAAAACCQAAZAAAAAIAAAAAAAAAAAgAAAAAAAAAAAgAAAAAAAAAACAAAAAAAAAAACABAAAADWdldFByaWNlQXNzZXQA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AAAAFwAAAAB2Fzc2V0SWQJAAACAAAAAQIAAAAWSW52YWxpZCBwYXltZW50IGFzc2V0LgkBAAAADFNjcmlwdFJlc3VsdAAAAAIJAQAAAAhXcml0ZVNldAAAAAEJAARMAAAAAgkBAAAACXNlcmlhbGl6ZQAAAAYFAAAABWxvdElkBQAAAAVwcmljZQkAAGUAAAACBQAAAAVzdG9jawUAAAALYW1vdW50VG9CdXkFAAAACnByaWNlQXNzZXQFAAAAC2Ftb3VudEFzc2V0BQAAAAZzZWxsZXIFAAAAA25pbAkBAAAAC1RyYW5zZmVyU2V0AAAAAQkABEwAAAACCQEAAAAOU2NyaXB0VHJhbnNmZXIAAAADCAUAAAABaQAAAAZjYWxsZXIFAAAAC2Ftb3VudFRvQnV5BQAAAAthbW91bnRBc3NldAkABEwAAAACCQEAAAAOU2NyaXB0VHJhbnNmZXIAAAADCQEAAAAUYWRkcmVzc0Zyb21QdWJsaWNLZXkAAAABBQAAAAZzZWxsZXIFAAAABXByaWNlBQAAAApwcmljZUFzc2V0BQAAAANuaWwAAAAA5doq3A==", "chainId": 84, "height": 1068051, "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 _: 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 = getPrice(data) | |
69 | + | let stock = getStock(data) | |
70 | + | let priceAsset = getPriceAsset(data) | |
71 | + | let amountAsset = getAmountAsset(data) | |
72 | + | let seller = getSeller(data) | |
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), stock, 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/169f3d6 40.19 ms ◑