tx · B6C4rbbVf18caKMfr48GnkkMvazvDrDErEHEGe3pijsY 3Mu7bwtYrymjrXt1ttcqaQbFc1PqGhZndhv: -0.01400000 Waves 2019.09.13 03:07 [673643] smart account 3Mu7bwtYrymjrXt1ttcqaQbFc1PqGhZndhv > SELF 0.00000000 Waves
{ "type": 13, "id": "B6C4rbbVf18caKMfr48GnkkMvazvDrDErEHEGe3pijsY", "fee": 1400000, "feeAssetId": null, "timestamp": 1568333274245, "version": 1, "sender": "3Mu7bwtYrymjrXt1ttcqaQbFc1PqGhZndhv", "senderPublicKey": "BxHnTcjvN9ZtnKfdKYp6aKRdkMB4ZHxHnTDr5dWx5Vz2", "proofs": [ "4MrTwCFoFahsn6ad78FgMnpQURGq4WgNVJW9BWuTbSQFUNJAzh4ve4NHcsBFvkjCe9rWwS9kz69CguXv1Tumn9tR" ], "script": "base64:AAIDAAAAAAAAAAAAAAAAAAAABAAAAAFpAQAAAAhtYWtlU2VsbAAAAAIAAAAKcHJpY2VBc3NldAAAAAVwcmljZQMDCQEAAAACIT0AAAACBQAAAApwcmljZUFzc2V0AgAAAAVXQVZFUwkBAAAAASEAAAABCQEAAAAJaXNEZWZpbmVkAAAAAQkAA+wAAAABCQACWQAAAAEFAAAACnByaWNlQXNzZXQHCQAAAgAAAAECAAAAI1RoZXJlIGlzIG5vIGFzc2V0IHdpdGggc3BlY2lmaWVkIGlkAwkAAGcAAAACAAAAAAAAAAAABQAAAAVwcmljZQkAAAIAAAABAgAAABZwcmljZSBtdXN0IGJlIHBvc2l0aXZlBAAAAAdwYXltZW50CQEAAAATdmFsdWVPckVycm9yTWVzc2FnZQAAAAIIBQAAAAFpAAAAB3BheW1lbnQCAAAAEXdoZXJlIGlzIHBheW1lbnQ/AwkAAGcAAAACAAAAAAAAAAAACAUAAAAHcGF5bWVudAAAAAZhbW91bnQJAAACAAAAAQIAAAAXYW1vdW50IG11c3QgYmUgcG9zaXRpdmUEAAAAB29yZGVySWQJAAEsAAAAAgIAAAAFc2Vs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aWNlQXNzZXQCAAAABVdBVkVTBQAAAAR1bml0CQACWQAAAAEFAAAACnByaWNlQXNzZXQJAARMAAAAAgkBAAAADlNjcmlwdFRyYW5zZmVyAAAAAwUAAAAFb3duZXIIBQAAAAdwYXltZW50AAAABmFtb3VudAMJAAAAAAAAAgUAAAALYW1vdW50QXNzZXQCAAAABVdBVkVTBQAAAAR1bml0CQACWQAAAAEFAAAAC2Ftb3VudEFzc2V0BQAAAANuaWwAAAAAn3uIRQ==", "chainId": 84, "height": 673643, "spentComplexity": 0 } View: original | compacted Prev: DedBPVVigRYPHNEpZNmitxWCkqH4y8y8F9uiRR4Ty9Qy Next: BG3hvuFjaWQ5f1hffcaoqPjZuecSwt589Kg1yCs8Q6ko Diff:
Old | New | Differences | |
---|---|---|---|
125 | 125 | let priceAssetDecimals = if ((priceAsset == "WAVES")) | |
126 | 126 | then 8 | |
127 | 127 | else value(assetInfo(fromBase58String(priceAsset))).decimals | |
128 | - | let | |
129 | - | if (( | |
128 | + | let priceAmount = ((payment.amount * price) / pow(10, 0, priceAssetDecimals, 0, 0, CEILING)) | |
129 | + | if ((priceAmount == 0)) | |
130 | 130 | then throw("invalid amount") | |
131 | 131 | else { | |
132 | 132 | let owner = value(addressFromString(getStringValue(this, (orderId + "_owner")))) | |
133 | 133 | let spent = getIntegerValue(this, (orderId + "_spent")) | |
134 | - | if (( | |
134 | + | if ((payment.amount > (amount - spent))) | |
135 | 135 | then throw("not enougth asset in order") | |
136 | - | else ScriptResult(WriteSet([DataEntry((orderId + "_spent"), (spent + | |
136 | + | else ScriptResult(WriteSet([DataEntry((orderId + "_spent"), (spent + payment.amount))]), TransferSet([ScriptTransfer(i.caller, priceAmount, if ((priceAsset == "WAVES")) | |
137 | 137 | then unit | |
138 | 138 | else fromBase58String(priceAsset)), ScriptTransfer(owner, payment.amount, if ((amountAsset == "WAVES")) | |
139 | 139 | then unit |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | ||
5 | 5 | ||
6 | 6 | @Callable(i) | |
7 | 7 | func makeSell (priceAsset,price) = if (if ((priceAsset != "WAVES")) | |
8 | 8 | then !(isDefined(assetInfo(fromBase58String(priceAsset)))) | |
9 | 9 | else false) | |
10 | 10 | then throw("There is no asset with specified id") | |
11 | 11 | else if ((0 >= price)) | |
12 | 12 | then throw("price must be positive") | |
13 | 13 | else { | |
14 | 14 | let payment = valueOrErrorMessage(i.payment, "where is payment?") | |
15 | 15 | if ((0 >= payment.amount)) | |
16 | 16 | then throw("amount must be positive") | |
17 | 17 | else { | |
18 | 18 | let orderId = ("sell_" + toBase58String(i.transactionId)) | |
19 | 19 | let amountAsset = match payment.assetId { | |
20 | 20 | case p: ByteVector => | |
21 | 21 | toBase58String(p) | |
22 | 22 | case _ => | |
23 | 23 | "WAVES" | |
24 | 24 | } | |
25 | 25 | WriteSet([DataEntry((orderId + "_amount"), payment.amount), DataEntry((orderId + "_amount_asset"), amountAsset), DataEntry((orderId + "_price"), price), DataEntry((orderId + "_price_asset"), priceAsset), DataEntry((orderId + "_owner"), toBase58String(i.caller.bytes)), DataEntry((orderId + "_spent"), 0)]) | |
26 | 26 | } | |
27 | 27 | } | |
28 | 28 | ||
29 | 29 | ||
30 | 30 | ||
31 | 31 | @Callable(i) | |
32 | 32 | func makeBuy (amountAsset,price) = if (if ((amountAsset != "WAVES")) | |
33 | 33 | then !(isDefined(assetInfo(fromBase58String(amountAsset)))) | |
34 | 34 | else false) | |
35 | 35 | then throw("There is no asset with specified id") | |
36 | 36 | else if ((0 >= price)) | |
37 | 37 | then throw("price must be positive") | |
38 | 38 | else { | |
39 | 39 | let payment = valueOrErrorMessage(i.payment, "where is payment?") | |
40 | 40 | if ((0 >= payment.amount)) | |
41 | 41 | then throw("amount must be positive") | |
42 | 42 | else { | |
43 | 43 | let orderId = ("buy_" + toBase58String(i.transactionId)) | |
44 | 44 | let priceAsset = match payment.assetId { | |
45 | 45 | case p: ByteVector => | |
46 | 46 | toBase58String(p) | |
47 | 47 | case _ => | |
48 | 48 | "WAVES" | |
49 | 49 | } | |
50 | 50 | let amountAssetDecimals = if ((amountAsset == "WAVES")) | |
51 | 51 | then 8 | |
52 | 52 | else value(assetInfo(fromBase58String(amountAsset))).decimals | |
53 | 53 | let buyAmount = ((payment.amount * pow(10, 0, amountAssetDecimals, 0, 0, CEILING)) / price) | |
54 | 54 | if ((buyAmount == 0)) | |
55 | 55 | then throw("invalid buy amount") | |
56 | 56 | else WriteSet([DataEntry((orderId + "_amount"), buyAmount), DataEntry((orderId + "_amount_asset"), amountAsset), DataEntry((orderId + "_price"), price), DataEntry((orderId + "_price_asset"), priceAsset), DataEntry((orderId + "_owner"), toBase58String(i.caller.bytes)), DataEntry((orderId + "_spent"), 0)]) | |
57 | 57 | } | |
58 | 58 | } | |
59 | 59 | ||
60 | 60 | ||
61 | 61 | ||
62 | 62 | @Callable(i) | |
63 | 63 | func takeSell (id) = { | |
64 | 64 | let payment = valueOrErrorMessage(i.payment, "where is payment?") | |
65 | 65 | if ((0 >= payment.amount)) | |
66 | 66 | then throw("amount must be positive") | |
67 | 67 | else { | |
68 | 68 | let orderId = ("sell_" + id) | |
69 | 69 | let paymentAsset = match payment.assetId { | |
70 | 70 | case p: ByteVector => | |
71 | 71 | toBase58String(p) | |
72 | 72 | case _ => | |
73 | 73 | "WAVES" | |
74 | 74 | } | |
75 | 75 | let priceAsset = valueOrErrorMessage(getString(this, (orderId + "_price_asset")), "there is no order with specified id") | |
76 | 76 | if ((priceAsset != paymentAsset)) | |
77 | 77 | then throw(("payment asset must be " + priceAsset)) | |
78 | 78 | else { | |
79 | 79 | let price = getIntegerValue(this, (orderId + "_price")) | |
80 | 80 | let amount = getIntegerValue(this, (orderId + "_amount")) | |
81 | 81 | let amountAsset = getStringValue(this, (orderId + "_amount_asset")) | |
82 | 82 | let amountAssetDecimals = if ((amountAsset == "WAVES")) | |
83 | 83 | then 8 | |
84 | 84 | else value(assetInfo(fromBase58String(amountAsset))).decimals | |
85 | 85 | let buyAmount = ((payment.amount * pow(10, 0, amountAssetDecimals, 0, 0, CEILING)) / price) | |
86 | 86 | if ((buyAmount == 0)) | |
87 | 87 | then throw("invalid amount") | |
88 | 88 | else { | |
89 | 89 | let owner = value(addressFromString(getStringValue(this, (orderId + "_owner")))) | |
90 | 90 | let spent = getIntegerValue(this, (orderId + "_spent")) | |
91 | 91 | if ((buyAmount > (amount - spent))) | |
92 | 92 | then throw("not enougth asset in order") | |
93 | 93 | else ScriptResult(WriteSet([DataEntry((orderId + "_spent"), (spent + buyAmount))]), TransferSet([ScriptTransfer(i.caller, buyAmount, if ((amountAsset == "WAVES")) | |
94 | 94 | then unit | |
95 | 95 | else fromBase58String(amountAsset)), ScriptTransfer(owner, payment.amount, if ((priceAsset == "WAVES")) | |
96 | 96 | then unit | |
97 | 97 | else fromBase58String(priceAsset))])) | |
98 | 98 | } | |
99 | 99 | } | |
100 | 100 | } | |
101 | 101 | } | |
102 | 102 | ||
103 | 103 | ||
104 | 104 | ||
105 | 105 | @Callable(i) | |
106 | 106 | func takeBuy (id) = { | |
107 | 107 | let payment = valueOrErrorMessage(i.payment, "where is payment?") | |
108 | 108 | if ((0 >= payment.amount)) | |
109 | 109 | then throw("amount must be positive") | |
110 | 110 | else { | |
111 | 111 | let orderId = ("buy_" + id) | |
112 | 112 | let paymentAsset = match payment.assetId { | |
113 | 113 | case p: ByteVector => | |
114 | 114 | toBase58String(p) | |
115 | 115 | case _ => | |
116 | 116 | "WAVES" | |
117 | 117 | } | |
118 | 118 | let amountAsset = valueOrErrorMessage(getString(this, (orderId + "_amount_asset")), "there is no order with specified id") | |
119 | 119 | if ((amountAsset != paymentAsset)) | |
120 | 120 | then throw(("payment asset must be " + amountAsset)) | |
121 | 121 | else { | |
122 | 122 | let price = getIntegerValue(this, (orderId + "_price")) | |
123 | 123 | let amount = getIntegerValue(this, (orderId + "_amount")) | |
124 | 124 | let priceAsset = getStringValue(this, (orderId + "_price_asset")) | |
125 | 125 | let priceAssetDecimals = if ((priceAsset == "WAVES")) | |
126 | 126 | then 8 | |
127 | 127 | else value(assetInfo(fromBase58String(priceAsset))).decimals | |
128 | - | let | |
129 | - | if (( | |
128 | + | let priceAmount = ((payment.amount * price) / pow(10, 0, priceAssetDecimals, 0, 0, CEILING)) | |
129 | + | if ((priceAmount == 0)) | |
130 | 130 | then throw("invalid amount") | |
131 | 131 | else { | |
132 | 132 | let owner = value(addressFromString(getStringValue(this, (orderId + "_owner")))) | |
133 | 133 | let spent = getIntegerValue(this, (orderId + "_spent")) | |
134 | - | if (( | |
134 | + | if ((payment.amount > (amount - spent))) | |
135 | 135 | then throw("not enougth asset in order") | |
136 | - | else ScriptResult(WriteSet([DataEntry((orderId + "_spent"), (spent + | |
136 | + | else ScriptResult(WriteSet([DataEntry((orderId + "_spent"), (spent + payment.amount))]), TransferSet([ScriptTransfer(i.caller, priceAmount, if ((priceAsset == "WAVES")) | |
137 | 137 | then unit | |
138 | 138 | else fromBase58String(priceAsset)), ScriptTransfer(owner, payment.amount, if ((amountAsset == "WAVES")) | |
139 | 139 | then unit | |
140 | 140 | else fromBase58String(amountAsset))])) | |
141 | 141 | } | |
142 | 142 | } | |
143 | 143 | } | |
144 | 144 | } | |
145 | 145 | ||
146 | 146 |
github/deemru/w8io/169f3d6 37.67 ms ◑