tx · BgT3oiLf3hromEptmkkgwKiB5ML9EnBHw8Bj2YaWRzz7 3MsJqBKZqXQmGUxc41Vn93qeSCvMpWMiZt7: -0.01000000 Waves 2019.08.13 18:26 [629482] smart account 3MsJqBKZqXQmGUxc41Vn93qeSCvMpWMiZt7 > SELF 0.00000000 Waves
{ "type": 13, "id": "BgT3oiLf3hromEptmkkgwKiB5ML9EnBHw8Bj2YaWRzz7", "fee": 1000000, "feeAssetId": null, "timestamp": 1565710095471, "version": 1, "sender": "3MsJqBKZqXQmGUxc41Vn93qeSCvMpWMiZt7", "senderPublicKey": "3V1kb4Tgqob82jFBtpNexTCMUgbmAxjvVABCamnEt3sH", "proofs": [ "4DTPiRkUsGaysAGnZuNBwRnXtA9cCV3pzZS61G9KKbjz7eKSY1iEA3taunqAtAhEu4YwvTASAFGsMTuPvHbvuHac" ], "script": "base64:AAIDAAAAAAAAAAAAAAAHAAAAAAx3YXZlc0Fzc2V0SWQBAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAhnZXRQcmljZQAAAAEAAAAEZGF0YQkABLEAAAABCQAAyQAAAAIFAAAABGRhdGEAAAAAAAAAAAgBAAAACGdldFN0b2NrAAAAAQAAAARkYXRhCQAEsQAAAAEJAADJAAAAAgkAAMoAAAACBQAAAARkYXRhAAAAAAAAAAAAAAAAAAAAAAAIAQAAAA1nZXRQcmljZUFzc2V0AAAAAQAAAARkYXRhBAAAAAJwcgkAAMkAAAACCQAAygAAAAIFAAAABGRhdGEJAABkAAAAAgAAAAAAAAAACAAAAAAAAAAACAAAAAAAAAAAIAMJAAAAAAAAAgUAAAACcHIFAAAADHdhdmVzQXNzZXRJZAUAAAAEdW5pdAUAAAACcHIBAAAADmdldEFtb3VudEFzc2V0AAAAAQAAAARkYXRhCQAAyQAAAAIJAADKAAAAAgUAAAAEZGF0YQkAAGQAAAACCQAAZAAAAAIAAAAAAAAAAAgAAAAAAAAAAAgAAAAAAAAAACAAAAAAAA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W50VG9CdXkFAAAABXByaWNlCAUAAAABcAAAAAZhbW91bnQJAAACAAAAAQIAAAAXSW52YWxpZCBwYXltZW50IGFtb3VudC4DCQEAAAACIT0AAAACCQAAyAAAAAEFAAAABGRhdGEJAABkAAAAAgkAAGQAAAACCQAAZAAAAAIJAABkAAAAAgAAAAAAAAAACAAAAAAAAAAACAAAAAAAAAAAIAAAAAAAAAAAIAAAAAAAAAAAIAkAAAIAAAABAgAAABpBbHJlYWR5IHNvbGQgb3IgY2FuY2VsbGVkLgMJAABmAAAAAgUAAAALYW1vdW50VG9CdXkFAAAABmFtb3VudAkAAAIAAAABAgAAABpOb3QgZW5vdWdoIGl0ZW1zIGluIHN0b2NrLgMJAQAAAAIhPQAAAAIFAAAACnByaWNlQXNzZXQIBQAAAAFwAAAAB2Fzc2V0SWQJAAACAAAAAQIAAAAWSW52YWxpZCBwYXltZW50IGFzc2V0LgkBAAAADFNjcmlwdFJlc3VsdAAAAAIJAQAAAAhXcml0ZVNldAAAAAEJAARMAAAAAgkBAAAACXNlcmlhbGl6ZQAAAAYFAAAAAmlkBQAAAAVwcmljZQkAAGUAAAACBQAAAAZhbW91bnQFAAAAC2Ftb3VudFRvQnV5BQAAAApwcmljZUFzc2V0BQAAAAthbW91bnRBc3NldAUAAAAGc2VsbGVyBQAAAANuaWwJAQAAAAtUcmFuc2ZlclNldAAAAAEJAARMAAAAAgkBAAAADlNjcmlwdFRyYW5zZmVyAAAAAwgFAAAAAWkAAAAGY2FsbGVyBQAAAAthbW91bnRUb0J1eQUAAAALYW1vdW50QXNzZXQJAARMAAAAAgkBAAAADlNjcmlwdFRyYW5zZmVyAAAAAwkBAAAAFGFkZHJlc3NGcm9tUHVibGljS2V5AAAAAQUAAAAGc2VsbGVyBQAAAAVwcmljZQUAAAAKcHJpY2VBc3NldAUAAAADbmlsAAAAAP3VC/8=", "chainId": 84, "height": 629482, "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, 0), 8)) | |
10 | + | ||
11 | + | ||
12 | + | func getPriceAsset (data) = { | |
13 | + | let pr = take(drop(data, (8 + 8)), 32) | |
14 | + | if ((pr == wavesAssetId)) | |
15 | + | then unit | |
16 | + | else pr | |
17 | + | } | |
18 | + | ||
19 | + | ||
20 | + | func getAmountAsset (data) = take(drop(data, ((8 + 8) + 32)), 32) | |
21 | + | ||
22 | + | ||
23 | + | func getSeller (data) = drop(data, (((8 + 8) + 32) + 32)) | |
24 | + | ||
25 | + | ||
26 | + | func serialize (id,price,stock,priceAsset,amountAsset,seller) = { | |
27 | + | let idAsString = match id { | |
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 ((p.assetId == unit)) | |
51 | + | then throw("You can't sell Waves.") | |
52 | + | else if ((0 >= p.amount)) | |
53 | + | then throw("You can't nothing.") | |
54 | + | else WriteSet([serialize(i.transactionId, price, p.amount, priceAsset, extract(extract(i.payment).assetId), i.callerPublicKey)]) | |
55 | + | } | |
56 | + | ||
57 | + | ||
58 | + | ||
59 | + | @Callable(i) | |
60 | + | func cancel (id) = { | |
61 | + | let data = extract(getBinary(this, id)) | |
62 | + | let price = toInt(take(data, 8)) | |
63 | + | let amount = toInt(take(drop(data, 0), 8)) | |
64 | + | let priceAsset = take(drop(data, (8 + 8)), 32) | |
65 | + | let amountAsset = take(drop(data, ((8 + 8) + 32)), 32) | |
66 | + | let seller = drop(data, (((8 + 8) + 32) + 32)) | |
67 | + | if ((seller != i.callerPublicKey)) | |
68 | + | then throw("Invalid user.") | |
69 | + | else ScriptResult(WriteSet([serialize(id, price, 0, priceAsset, amountAsset, seller)]), TransferSet([ScriptTransfer(addressFromPublicKey(seller), amount, amountAsset)])) | |
70 | + | } | |
71 | + | ||
72 | + | ||
73 | + | ||
74 | + | @Callable(i) | |
75 | + | func buy (id,amountToBuy) = { | |
76 | + | let data = extract(getBinary(this, id)) | |
77 | + | let price = getPrice(data) | |
78 | + | let amount = getStock(data) | |
79 | + | let priceAsset = getPriceAsset(data) | |
80 | + | let amountAsset = getAmountAsset(data) | |
81 | + | let seller = getSeller(data) | |
82 | + | let p = extract(i.payment) | |
83 | + | if ((p.assetId == wavesAssetId)) | |
84 | + | then throw("Invalid payment asset.") | |
85 | + | else if ((0 >= amountToBuy)) | |
86 | + | then throw("Invalid payment amount.") | |
87 | + | else if (((amountToBuy * price) != p.amount)) | |
88 | + | then throw("Invalid payment amount.") | |
89 | + | else if ((size(data) != ((((8 + 8) + 32) + 32) + 32))) | |
90 | + | then throw("Already sold or cancelled.") | |
91 | + | else if ((amountToBuy > amount)) | |
92 | + | then throw("Not enough items in stock.") | |
93 | + | else if ((priceAsset != p.assetId)) | |
94 | + | then throw("Invalid payment asset.") | |
95 | + | else ScriptResult(WriteSet([serialize(id, price, (amount - amountToBuy), priceAsset, amountAsset, seller)]), TransferSet([ScriptTransfer(i.caller, amountToBuy, amountAsset), ScriptTransfer(addressFromPublicKey(seller), price, priceAsset)])) | |
96 | + | } | |
97 | + | ||
98 | + |
github/deemru/w8io/169f3d6 27.71 ms ◑