tx · 41L72vHuLQ6A8Z5AZHVeSXVBLSp1X1MxLXrpWVPswSFF 3MtjjEoEs6Rcqkh8tYjPmBxZND58FuMtRWN: -0.05000000 Waves 2022.09.07 00:35 [2217811] smart account 3MtjjEoEs6Rcqkh8tYjPmBxZND58FuMtRWN > SELF 0.00000000 Waves
{ "type": 13, "id": "41L72vHuLQ6A8Z5AZHVeSXVBLSp1X1MxLXrpWVPswSFF", "fee": 5000000, "feeAssetId": null, "timestamp": 1662500166880, "version": 2, "chainId": 84, "sender": "3MtjjEoEs6Rcqkh8tYjPmBxZND58FuMtRWN", "senderPublicKey": "GR35NTmt1JUgBMwuwSK6aFSmLN7g6eZKbYvfSV3ThdWR", "proofs": [ "3sj6Hg1JTTSGTDbrLb2G51KASMdazbscrrcjacvXXTRzAaHugyLV94NeMcGEA57ijDA9aGG14y6BuL8ZKBcHXNaE" ], "script": "base64:AAIFAAAAAAAAABIIAhIECgIIARIDCgEIEgMKAQgAAAAEAQAAAAx0cnlHZXRTdHJpbmcAAAABAAAAA2tleQQAAAAHJG1hdGNoMAkABB0AAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAABlN0cmluZwQAAAABYgUAAAAHJG1hdGNoMAUAAAABYgIAAAAAAQAAAA10cnlHZXRJbnRlZ2VyAAAAAQAAAANrZXkEAAAAByRtYXRjaDAJAAQaAAAAAgUAAAAEdGhpcwUAAAADa2V5AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAANJbnQEAAAAAWIFAAAAByRtYXRjaDAFAAAAAWIAAAAAAAAAAAABAAAADmdldEFzc2V0U3RyaW5nAAAAAQAAAAdhc3NldElkBAAAAAckbWF0Y2gwBQAAAAdhc3NldElkAwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAApCeXRlVmVjdG9yBAAAAAFiBQAAAAckbWF0Y2gwCQACWAAAAAEFAAAAAWICAAAABVdBVkVTAQAAAA1nZXRBc3NldEJ5dGVzAAAAAQAAAA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yKQAAAAEFAAAACm9yZGVyT3duZXIFAAAAEG9yZGVyQW1vdW50MExlZnQJAQAAAA1nZXRBc3NldEJ5dGVzAAAAAQUAAAALb3JkZXJBc3NldDAJAARMAAAAAgkBAAAAC1N0cmluZ0VudHJ5AAAAAgkAASwAAAACCQABLAAAAAICAAAABm9yZGVyXwUAAAAHb3JkZXJJZAIAAAAHX3N0YXR1cwIAAAAIY2FuY2VsZWQFAAAAA25pbAAAAAEAAAACdHgBAAAABnZlcmlmeQAAAAAJAAH0AAAAAwgFAAAAAnR4AAAACWJvZHlCeXRlcwkAAZEAAAACCAUAAAACdHgAAAAGcHJvb2ZzAAAAAAAAAAAACAUAAAACdHgAAAAPc2VuZGVyUHVibGljS2V54W7cDA==", "height": 2217811, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: none Next: 7uGWx3sRs8RYca7CtvSaHUeoDb9LyQSh5w1dEWYP9Eif Full:
Old | New | Differences | |
---|---|---|---|
1 | - | # no script | |
1 | + | {-# STDLIB_VERSION 5 #-} | |
2 | + | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | + | {-# CONTENT_TYPE DAPP #-} | |
4 | + | func tryGetString (key) = match getString(this, key) { | |
5 | + | case b: String => | |
6 | + | b | |
7 | + | case _ => | |
8 | + | "" | |
9 | + | } | |
10 | + | ||
11 | + | ||
12 | + | func tryGetInteger (key) = match getInteger(this, key) { | |
13 | + | case b: Int => | |
14 | + | b | |
15 | + | case _ => | |
16 | + | 0 | |
17 | + | } | |
18 | + | ||
19 | + | ||
20 | + | func getAssetString (assetId) = match assetId { | |
21 | + | case b: ByteVector => | |
22 | + | toBase58String(b) | |
23 | + | case _ => | |
24 | + | "WAVES" | |
25 | + | } | |
26 | + | ||
27 | + | ||
28 | + | func getAssetBytes (assetIdStr) = if ((assetIdStr == "WAVES")) | |
29 | + | then unit | |
30 | + | else fromBase58String(assetIdStr) | |
31 | + | ||
32 | + | ||
33 | + | @Callable(i) | |
34 | + | func createOrder (asset1,amount1) = { | |
35 | + | let newOrdersAmount = (tryGetInteger("global_ordersAmount") + 1) | |
36 | + | let orderId = toString(newOrdersAmount) | |
37 | + | if ((size(i.payments) != 1)) | |
38 | + | then throw("You should to provide payment") | |
39 | + | else if ((0 >= amount1)) | |
40 | + | then throw("Amount1 cannot be less or equals 0") | |
41 | + | else { | |
42 | + | let asset0 = getAssetString(i.payments[0].assetId) | |
43 | + | let amount0 = i.payments[0].amount | |
44 | + | let userOrders = tryGetString((("user_" + toString(i.caller)) + "_orders")) | |
45 | + | let newUserOrders = match userOrders { | |
46 | + | case _ => | |
47 | + | if (("" == $match0)) | |
48 | + | then orderId | |
49 | + | else ((userOrders + ",") + orderId) | |
50 | + | } | |
51 | + | [IntegerEntry("global_ordersAmount", newOrdersAmount), StringEntry((("order_" + orderId) + "_token0"), asset0), IntegerEntry((("order_" + orderId) + "_amount0"), amount0), IntegerEntry((("order_" + orderId) + "_amount1"), amount1), StringEntry((("order_" + orderId) + "_token1"), asset1), IntegerEntry((("order_" + orderId) + "_fulfilled0"), 0), IntegerEntry((("order_" + orderId) + "_fulfilled1"), 0), StringEntry((("order_" + orderId) + "_owner"), toString(i.caller)), StringEntry((("order_" + orderId) + "_status"), "active"), StringEntry((("user_" + toString(i.caller)) + "_orders"), newUserOrders)] | |
52 | + | } | |
53 | + | } | |
54 | + | ||
55 | + | ||
56 | + | ||
57 | + | @Callable(i) | |
58 | + | func fulfillOrder (orderId) = { | |
59 | + | let orderOwner = valueOrErrorMessage(getString((("order_" + orderId) + "_owner")), "Cannot find order owner") | |
60 | + | let orderStatus = getString((("order_" + orderId) + "_status")) | |
61 | + | let orderAsset0 = valueOrErrorMessage(getString((("order_" + orderId) + "_token0")), "Cannot find token0") | |
62 | + | let orderAmount0 = valueOrErrorMessage(getInteger((("order_" + orderId) + "_amount0")), "Cannot find amount0") | |
63 | + | let orderFulfilled0 = valueOrErrorMessage(getInteger((("order_" + orderId) + "_fulfilled0")), "Cannot find fulfilled0") | |
64 | + | let orderAmount0Left = (orderAmount0 - orderFulfilled0) | |
65 | + | let orderAsset1 = valueOrErrorMessage(getString((("order_" + orderId) + "_token1")), "Cannot find token1") | |
66 | + | let orderAmount1 = valueOrErrorMessage(getInteger((("order_" + orderId) + "_amount1")), "Cannot find amount1") | |
67 | + | let orderFulfilled1 = valueOrErrorMessage(getInteger((("order_" + orderId) + "_fulfilled1")), "Cannot find fulfilled1") | |
68 | + | let orderAmount1Left = (orderAmount1 - orderFulfilled1) | |
69 | + | if ((orderStatus != "active")) | |
70 | + | then throw("Order already closed or canceled") | |
71 | + | else if ((size(i.payments) != 1)) | |
72 | + | then throw("You should to provide payment") | |
73 | + | else { | |
74 | + | let callerAddress = i.caller | |
75 | + | let ownerAddress = addressFromStringValue(orderOwner) | |
76 | + | let paymentAsset1 = getAssetString(i.payments[0].assetId) | |
77 | + | let paymentAmount1 = i.payments[0].amount | |
78 | + | if ((paymentAsset1 != orderAsset1)) | |
79 | + | then throw("Wrong payment asset") | |
80 | + | else if ((paymentAmount1 >= orderAmount1Left)) | |
81 | + | then [ScriptTransfer(callerAddress, (paymentAmount1 - orderAmount1Left), getAssetBytes(orderAsset1)), ScriptTransfer(callerAddress, orderAmount0Left, getAssetBytes(orderAsset0)), ScriptTransfer(ownerAddress, orderAmount1Left, getAssetBytes(paymentAsset1)), IntegerEntry((("order_" + orderId) + "_fulfilled0"), (orderFulfilled0 + orderAmount0Left)), IntegerEntry((("order_" + orderId) + "_fulfilled1"), (orderFulfilled1 + orderAmount1Left)), StringEntry((("order_" + orderId) + "_status"), "closed")] | |
82 | + | else { | |
83 | + | let amount0 = fraction(orderAmount0, paymentAmount1, orderAmount1, FLOOR) | |
84 | + | [ScriptTransfer(ownerAddress, paymentAmount1, getAssetBytes(paymentAsset1)), ScriptTransfer(callerAddress, amount0, getAssetBytes(orderAsset0)), IntegerEntry((("order_" + orderId) + "_fulfilled0"), (orderFulfilled0 + amount0)), IntegerEntry((("order_" + orderId) + "_fulfilled1"), (orderFulfilled1 + paymentAmount1))] | |
85 | + | } | |
86 | + | } | |
87 | + | } | |
88 | + | ||
89 | + | ||
90 | + | ||
91 | + | @Callable(i) | |
92 | + | func cancelOrder (orderId) = { | |
93 | + | let orderOwner = valueOrErrorMessage(getString((("order_" + orderId) + "_owner")), "Cannot find order owner") | |
94 | + | let orderStatus = getString((("order_" + orderId) + "_status")) | |
95 | + | let orderAsset0 = valueOrErrorMessage(getString((("order_" + orderId) + "_token0")), "Cannot find token0") | |
96 | + | let orderAmount0 = valueOrErrorMessage(getInteger((("order_" + orderId) + "_amount0")), "Cannot find amount0") | |
97 | + | let orderFulfilled0 = valueOrErrorMessage(getInteger((("order_" + orderId) + "_fulfilled0")), "Cannot find fulfilled0") | |
98 | + | let orderAmount0Left = (orderAmount0 - orderFulfilled0) | |
99 | + | if ((toBase58String(i.caller.bytes) != orderOwner)) | |
100 | + | then throw("You cannot cancel order") | |
101 | + | else if ((orderStatus != "active")) | |
102 | + | then throw("order is closed or canceled") | |
103 | + | else [ScriptTransfer(addressFromStringValue(orderOwner), orderAmount0Left, getAssetBytes(orderAsset0)), StringEntry((("order_" + orderId) + "_status"), "canceled")] | |
104 | + | } | |
105 | + | ||
106 | + | ||
107 | + | @Verifier(tx) | |
108 | + | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
109 | + |
github/deemru/w8io/026f985 18.68 ms ◑