tx · 6sqhkPor8Z35qph7Qgos3gpnv69H9UoiuSFZyMg4iXWA 3Mu7bwtYrymjrXt1ttcqaQbFc1PqGhZndhv: -0.01400000 Waves 2019.09.13 02:24 [673601] smart account 3Mu7bwtYrymjrXt1ttcqaQbFc1PqGhZndhv > SELF 0.00000000 Waves
{ "type": 13, "id": "6sqhkPor8Z35qph7Qgos3gpnv69H9UoiuSFZyMg4iXWA", "fee": 1400000, "feeAssetId": null, "timestamp": 1568330667279, "version": 1, "sender": "3Mu7bwtYrymjrXt1ttcqaQbFc1PqGhZndhv", "senderPublicKey": "BxHnTcjvN9ZtnKfdKYp6aKRdkMB4ZHxHnTDr5dWx5Vz2", "proofs": [ "4bsShiMoGPEyr5233CNCHrnXteECVp4ccuTtUn9Wn2XPdHNytNvHmseeQegxVuD2Jbo9aZFJiGDX8NaUjUCAL35j" ], "script": "base64:AAIDAAAAAAAAAAAAAAAAAAAABAAAAAFpAQAAAAhtYWtlU2VsbAAAAAIAAAAKcHJpY2VBc3NldAAAAAVwcmljZQMDCQEAAAACIT0AAAACBQAAAApwcmljZUFzc2V0AgAAAAVXQVZFUwkBAAAAASEAAAABCQEAAAAJaXNEZWZpbmVkAAAAAQkAA+wAAAABCQACWQAAAAEFAAAACnByaWNlQXNzZXQHCQAAAgAAAAECAAAAI1RoZXJlIGlzIG5vIGFzc2V0IHdpdGggc3BlY2lmaWVkIGlkAwkAAGcAAAACAAAAAAAAAAAABQAAAAVwcmljZQkAAAIAAAABAgAAABZwcmljZSBtdXN0IGJlIHBvc2l0aXZlBAAAAAdwYXltZW50CQEAAAATdmFsdWVPckVycm9yTWVzc2FnZQAAAAIIBQAAAAFpAAAAB3BheW1lbnQCAAAAEXdoZXJlIGlzIHBheW1lbnQ/AwkAAGcAAAACAAAAAAAAAAAACAUAAAAHcGF5bWVudAAAAAZhbW91bnQJAAACAAAAAQIAAAAXYW1vdW50IG11c3QgYmUgcG9zaXRpdmUEAAAAB29yZGVySWQJAAEsAAAAAgIAAAA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0AgAAAAVXQVZFUwUAAAAEdW5pdAkAAlkAAAABBQAAAApwcmljZUFzc2V0CQAETAAAAAIJAQAAAA5TY3JpcHRUcmFuc2ZlcgAAAAMFAAAABW93bmVyCAUAAAAHcGF5bWVudAAAAAZhbW91bnQDCQAAAAAAAAIFAAAAC2Ftb3VudEFzc2V0AgAAAAVXQVZFUwUAAAAEdW5pdAkAAlkAAAABBQAAAAthbW91bnRBc3NldAUAAAADbmlsAAAAAGARwyI=", "chainId": 84, "height": 673601, "spentComplexity": 0 } View: original | compacted Prev: AyGhNRRjwJZeotFT4HmhjTvzj2ueVujUtM4XZXAjGA8E Next: DedBPVVigRYPHNEpZNmitxWCkqH4y8y8F9uiRR4Ty9Qy Diff:
Old | New | Differences | |
---|---|---|---|
47 | 47 | case _ => | |
48 | 48 | "WAVES" | |
49 | 49 | } | |
50 | - | WriteSet([DataEntry((orderId + "_amount"), (payment.amount / price)), 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)]) | |
50 | + | let amountAssetDecimals = if ((amountAsset == "WAVES")) | |
51 | + | then 8 | |
52 | + | else value(assetInfo(fromBase58String(amountAsset))).decimals | |
53 | + | let buyAmount = ((payment.amount * pow(10, 0, amountAssetDecimals, 0, 0, CEILING)) / price) | |
54 | + | if ((buyAmount == 0)) | |
55 | + | then throw("invalid buy amount") | |
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)]) | |
51 | 57 | } | |
52 | 58 | } | |
53 | 59 | ||
73 | 79 | let price = getIntegerValue(this, (orderId + "_price")) | |
74 | 80 | let amount = getIntegerValue(this, (orderId + "_amount")) | |
75 | 81 | let amountAsset = getStringValue(this, (orderId + "_amount_asset")) | |
76 | - | let paymentAssetDecimals = if ((paymentAsset == "WAVES")) | |
77 | - | then 8 | |
78 | - | else value(assetInfo(fromBase58String(paymentAsset))).decimals | |
79 | 82 | let amountAssetDecimals = if ((amountAsset == "WAVES")) | |
80 | 83 | then 8 | |
81 | 84 | else value(assetInfo(fromBase58String(amountAsset))).decimals | |
98 | 101 | } | |
99 | 102 | ||
100 | 103 | ||
104 | + | ||
105 | + | @Callable(i) | |
106 | + | func takeBuy (id) = { | |
107 | + | let payment = valueOrErrorMessage(i.payment, "where is payment?") | |
108 | + | if ((0 >= payment.amount)) | |
109 | + | then throw("amount must be positive") | |
110 | + | else { | |
111 | + | let orderId = ("buy_" + id) | |
112 | + | let paymentAsset = match payment.assetId { | |
113 | + | case p: ByteVector => | |
114 | + | toBase58String(p) | |
115 | + | case _ => | |
116 | + | "WAVES" | |
117 | + | } | |
118 | + | let amountAsset = valueOrErrorMessage(getString(this, (orderId + "_amount_asset")), "there is no order with specified id") | |
119 | + | if ((amountAsset != paymentAsset)) | |
120 | + | then throw(("payment asset must be " + amountAsset)) | |
121 | + | else { | |
122 | + | let price = getIntegerValue(this, (orderId + "_price")) | |
123 | + | let amount = getIntegerValue(this, (orderId + "_amount")) | |
124 | + | let priceAsset = getStringValue(this, (orderId + "_price_asset")) | |
125 | + | let amountAssetDecimals = if ((amountAsset == "WAVES")) | |
126 | + | then 8 | |
127 | + | else value(assetInfo(fromBase58String(amountAsset))).decimals | |
128 | + | let buyAmount = ((payment.amount * price) / pow(10, 0, amountAssetDecimals, 0, 0, CEILING)) | |
129 | + | if ((buyAmount == 0)) | |
130 | + | then throw("invalid amount") | |
131 | + | else { | |
132 | + | let owner = value(addressFromString(getStringValue(this, (orderId + "_owner")))) | |
133 | + | let spent = getIntegerValue(this, (orderId + "_spent")) | |
134 | + | if ((buyAmount > (amount - spent))) | |
135 | + | then throw("not enougth asset in order") | |
136 | + | else ScriptResult(WriteSet([DataEntry((orderId + "_spent"), (spent + buyAmount))]), TransferSet([ScriptTransfer(i.caller, buyAmount, if ((priceAsset == "WAVES")) | |
137 | + | then unit | |
138 | + | else fromBase58String(priceAsset)), ScriptTransfer(owner, payment.amount, if ((amountAsset == "WAVES")) | |
139 | + | then unit | |
140 | + | else fromBase58String(amountAsset))])) | |
141 | + | } | |
142 | + | } | |
143 | + | } | |
144 | + | } | |
145 | + | ||
146 | + |
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 | - | WriteSet([DataEntry((orderId + "_amount"), (payment.amount / price)), 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)]) | |
50 | + | let amountAssetDecimals = if ((amountAsset == "WAVES")) | |
51 | + | then 8 | |
52 | + | else value(assetInfo(fromBase58String(amountAsset))).decimals | |
53 | + | let buyAmount = ((payment.amount * pow(10, 0, amountAssetDecimals, 0, 0, CEILING)) / price) | |
54 | + | if ((buyAmount == 0)) | |
55 | + | then throw("invalid buy amount") | |
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)]) | |
51 | 57 | } | |
52 | 58 | } | |
53 | 59 | ||
54 | 60 | ||
55 | 61 | ||
56 | 62 | @Callable(i) | |
57 | 63 | func takeSell (id) = { | |
58 | 64 | let payment = valueOrErrorMessage(i.payment, "where is payment?") | |
59 | 65 | if ((0 >= payment.amount)) | |
60 | 66 | then throw("amount must be positive") | |
61 | 67 | else { | |
62 | 68 | let orderId = ("sell_" + id) | |
63 | 69 | let paymentAsset = match payment.assetId { | |
64 | 70 | case p: ByteVector => | |
65 | 71 | toBase58String(p) | |
66 | 72 | case _ => | |
67 | 73 | "WAVES" | |
68 | 74 | } | |
69 | 75 | let priceAsset = valueOrErrorMessage(getString(this, (orderId + "_price_asset")), "there is no order with specified id") | |
70 | 76 | if ((priceAsset != paymentAsset)) | |
71 | 77 | then throw(("payment asset must be " + priceAsset)) | |
72 | 78 | else { | |
73 | 79 | let price = getIntegerValue(this, (orderId + "_price")) | |
74 | 80 | let amount = getIntegerValue(this, (orderId + "_amount")) | |
75 | 81 | let amountAsset = getStringValue(this, (orderId + "_amount_asset")) | |
76 | - | let paymentAssetDecimals = if ((paymentAsset == "WAVES")) | |
77 | - | then 8 | |
78 | - | else value(assetInfo(fromBase58String(paymentAsset))).decimals | |
79 | 82 | let amountAssetDecimals = if ((amountAsset == "WAVES")) | |
80 | 83 | then 8 | |
81 | 84 | else value(assetInfo(fromBase58String(amountAsset))).decimals | |
82 | 85 | let buyAmount = ((payment.amount * pow(10, 0, amountAssetDecimals, 0, 0, CEILING)) / price) | |
83 | 86 | if ((buyAmount == 0)) | |
84 | 87 | then throw("invalid amount") | |
85 | 88 | else { | |
86 | 89 | let owner = value(addressFromString(getStringValue(this, (orderId + "_owner")))) | |
87 | 90 | let spent = getIntegerValue(this, (orderId + "_spent")) | |
88 | 91 | if ((buyAmount > (amount - spent))) | |
89 | 92 | then throw("not enougth asset in order") | |
90 | 93 | else ScriptResult(WriteSet([DataEntry((orderId + "_spent"), (spent + buyAmount))]), TransferSet([ScriptTransfer(i.caller, buyAmount, if ((amountAsset == "WAVES")) | |
91 | 94 | then unit | |
92 | 95 | else fromBase58String(amountAsset)), ScriptTransfer(owner, payment.amount, if ((priceAsset == "WAVES")) | |
93 | 96 | then unit | |
94 | 97 | else fromBase58String(priceAsset))])) | |
95 | 98 | } | |
96 | 99 | } | |
97 | 100 | } | |
98 | 101 | } | |
99 | 102 | ||
100 | 103 | ||
104 | + | ||
105 | + | @Callable(i) | |
106 | + | func takeBuy (id) = { | |
107 | + | let payment = valueOrErrorMessage(i.payment, "where is payment?") | |
108 | + | if ((0 >= payment.amount)) | |
109 | + | then throw("amount must be positive") | |
110 | + | else { | |
111 | + | let orderId = ("buy_" + id) | |
112 | + | let paymentAsset = match payment.assetId { | |
113 | + | case p: ByteVector => | |
114 | + | toBase58String(p) | |
115 | + | case _ => | |
116 | + | "WAVES" | |
117 | + | } | |
118 | + | let amountAsset = valueOrErrorMessage(getString(this, (orderId + "_amount_asset")), "there is no order with specified id") | |
119 | + | if ((amountAsset != paymentAsset)) | |
120 | + | then throw(("payment asset must be " + amountAsset)) | |
121 | + | else { | |
122 | + | let price = getIntegerValue(this, (orderId + "_price")) | |
123 | + | let amount = getIntegerValue(this, (orderId + "_amount")) | |
124 | + | let priceAsset = getStringValue(this, (orderId + "_price_asset")) | |
125 | + | let amountAssetDecimals = if ((amountAsset == "WAVES")) | |
126 | + | then 8 | |
127 | + | else value(assetInfo(fromBase58String(amountAsset))).decimals | |
128 | + | let buyAmount = ((payment.amount * price) / pow(10, 0, amountAssetDecimals, 0, 0, CEILING)) | |
129 | + | if ((buyAmount == 0)) | |
130 | + | then throw("invalid amount") | |
131 | + | else { | |
132 | + | let owner = value(addressFromString(getStringValue(this, (orderId + "_owner")))) | |
133 | + | let spent = getIntegerValue(this, (orderId + "_spent")) | |
134 | + | if ((buyAmount > (amount - spent))) | |
135 | + | then throw("not enougth asset in order") | |
136 | + | else ScriptResult(WriteSet([DataEntry((orderId + "_spent"), (spent + buyAmount))]), TransferSet([ScriptTransfer(i.caller, buyAmount, if ((priceAsset == "WAVES")) | |
137 | + | then unit | |
138 | + | else fromBase58String(priceAsset)), ScriptTransfer(owner, payment.amount, if ((amountAsset == "WAVES")) | |
139 | + | then unit | |
140 | + | else fromBase58String(amountAsset))])) | |
141 | + | } | |
142 | + | } | |
143 | + | } | |
144 | + | } | |
145 | + | ||
146 | + |
github/deemru/w8io/03bedc9 32.41 ms ◑![]()