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/AwkAAGcAAAACAAAAAAAAAAAACAUAAAAHcGF5bWVudAAAAAZhbW91bnQJAAACAAAAAQIAAAAXYW1vdW50IG11c3QgYmUgcG9zaXRpdmUEAAAAB29yZGVySWQJAAEsAAAAAgIAAA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V0AgAAAAVXQVZFUwUAAAAEdW5pdAkAAlkAAAABBQAAAApwcmljZUFzc2V0CQAETAAAAAIJAQAAAA5TY3JpcHRUcmFuc2ZlcgAAAAMFAAAABW93bmVyCAUAAAAHcGF5bWVudAAAAAZhbW91bnQDCQAAAAAAAAIFAAAAC2Ftb3VudEFzc2V0AgAAAAVXQVZFUwUAAAAEdW5pdAkAAlkAAAABBQAAAAthbW91bnRBc3NldAUAAAADbmlsAAAAAGARwyI=", "chainId": 84, "height": 673601, "spentComplexity": 0 } View: original | compacted Prev: AyGhNRRjwJZeotFT4HmhjTvzj2ueVujUtM4XZXAjGA8E Next: DedBPVVigRYPHNEpZNmitxWCkqH4y8y8F9uiRR4Ty9Qy Diff:
OldNewDifferences
4747 case _ =>
4848 "WAVES"
4949 }
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)])
5157 }
5258 }
5359
7379 let price = getIntegerValue(this, (orderId + "_price"))
7480 let amount = getIntegerValue(this, (orderId + "_amount"))
7581 let amountAsset = getStringValue(this, (orderId + "_amount_asset"))
76- let paymentAssetDecimals = if ((paymentAsset == "WAVES"))
77- then 8
78- else value(assetInfo(fromBase58String(paymentAsset))).decimals
7982 let amountAssetDecimals = if ((amountAsset == "WAVES"))
8083 then 8
8184 else value(assetInfo(fromBase58String(amountAsset))).decimals
98101 }
99102
100103
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+
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 3 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44
55
66 @Callable(i)
77 func makeSell (priceAsset,price) = if (if ((priceAsset != "WAVES"))
88 then !(isDefined(assetInfo(fromBase58String(priceAsset))))
99 else false)
1010 then throw("There is no asset with specified id")
1111 else if ((0 >= price))
1212 then throw("price must be positive")
1313 else {
1414 let payment = valueOrErrorMessage(i.payment, "where is payment?")
1515 if ((0 >= payment.amount))
1616 then throw("amount must be positive")
1717 else {
1818 let orderId = ("sell_" + toBase58String(i.transactionId))
1919 let amountAsset = match payment.assetId {
2020 case p: ByteVector =>
2121 toBase58String(p)
2222 case _ =>
2323 "WAVES"
2424 }
2525 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)])
2626 }
2727 }
2828
2929
3030
3131 @Callable(i)
3232 func makeBuy (amountAsset,price) = if (if ((amountAsset != "WAVES"))
3333 then !(isDefined(assetInfo(fromBase58String(amountAsset))))
3434 else false)
3535 then throw("There is no asset with specified id")
3636 else if ((0 >= price))
3737 then throw("price must be positive")
3838 else {
3939 let payment = valueOrErrorMessage(i.payment, "where is payment?")
4040 if ((0 >= payment.amount))
4141 then throw("amount must be positive")
4242 else {
4343 let orderId = ("buy_" + toBase58String(i.transactionId))
4444 let priceAsset = match payment.assetId {
4545 case p: ByteVector =>
4646 toBase58String(p)
4747 case _ =>
4848 "WAVES"
4949 }
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)])
5157 }
5258 }
5359
5460
5561
5662 @Callable(i)
5763 func takeSell (id) = {
5864 let payment = valueOrErrorMessage(i.payment, "where is payment?")
5965 if ((0 >= payment.amount))
6066 then throw("amount must be positive")
6167 else {
6268 let orderId = ("sell_" + id)
6369 let paymentAsset = match payment.assetId {
6470 case p: ByteVector =>
6571 toBase58String(p)
6672 case _ =>
6773 "WAVES"
6874 }
6975 let priceAsset = valueOrErrorMessage(getString(this, (orderId + "_price_asset")), "there is no order with specified id")
7076 if ((priceAsset != paymentAsset))
7177 then throw(("payment asset must be " + priceAsset))
7278 else {
7379 let price = getIntegerValue(this, (orderId + "_price"))
7480 let amount = getIntegerValue(this, (orderId + "_amount"))
7581 let amountAsset = getStringValue(this, (orderId + "_amount_asset"))
76- let paymentAssetDecimals = if ((paymentAsset == "WAVES"))
77- then 8
78- else value(assetInfo(fromBase58String(paymentAsset))).decimals
7982 let amountAssetDecimals = if ((amountAsset == "WAVES"))
8083 then 8
8184 else value(assetInfo(fromBase58String(amountAsset))).decimals
8285 let buyAmount = ((payment.amount * pow(10, 0, amountAssetDecimals, 0, 0, CEILING)) / price)
8386 if ((buyAmount == 0))
8487 then throw("invalid amount")
8588 else {
8689 let owner = value(addressFromString(getStringValue(this, (orderId + "_owner"))))
8790 let spent = getIntegerValue(this, (orderId + "_spent"))
8891 if ((buyAmount > (amount - spent)))
8992 then throw("not enougth asset in order")
9093 else ScriptResult(WriteSet([DataEntry((orderId + "_spent"), (spent + buyAmount))]), TransferSet([ScriptTransfer(i.caller, buyAmount, if ((amountAsset == "WAVES"))
9194 then unit
9295 else fromBase58String(amountAsset)), ScriptTransfer(owner, payment.amount, if ((priceAsset == "WAVES"))
9396 then unit
9497 else fromBase58String(priceAsset))]))
9598 }
9699 }
97100 }
98101 }
99102
100103
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/169f3d6 
28.20 ms