tx · FsxsWNHLDenjoguS3T1wJwoGzsEwTodGV1C9idxeu8qf 3N9b7vExDf2qqZt2xG9FUsca7iwLVuih1Ta: -0.01000000 Waves 2023.12.01 18:20 [2867749] smart account 3N9b7vExDf2qqZt2xG9FUsca7iwLVuih1Ta > SELF 0.00000000 Waves
{ "type": 13, "id": "FsxsWNHLDenjoguS3T1wJwoGzsEwTodGV1C9idxeu8qf", "fee": 1000000, "feeAssetId": null, "timestamp": 1701444059452, "version": 2, "chainId": 84, "sender": "3N9b7vExDf2qqZt2xG9FUsca7iwLVuih1Ta", "senderPublicKey": "4rSYGN3SSXzknh6jLyLqqGdGor584DXdjdP2BAbz7kgt", "proofs": [ "47ZSZCYx5aViwtdULTPvgSrHcfVAem6GghiyvXJ6vC6a61kR88NG2P9uk2et7X4K9x54oPcz5vbTkYiM7p6cjo33" ], "script": "base64:AAIFAAAAAAAAABcIAhIGCgQIAQgBEgMKAQgSBgoECAgBAQAAAAsAAAAACWRldmVsb3BlcgkBAAAAEUBleHRyTmF0aXZlKDEwNjIpAAAAAQIAAAAjM1A5bVRDcEJ0dUF6TWtIb2RiNFh3Z1g0ektZQWNoMnBnd2EBAAAACmtleVBhcnRuZXIAAAABAAAAB2FkZHJlc3MJAAEsAAAAAgIAAAAPJXMlc19fcGFydG5lcl9fBQAAAAdhZGRyZXNzAQAAABBrZXlXYW50ZWRBc3NldElkAAAAAQAAAAdhZGRyZXNzCQABLAAAAAICAAAAFSVzJXNfX3dhbnRlZEFzc2V0SWRfXwUAAAAHYWRkcmVzcwEAAAAPa2V5V2FudGVkQW1vdW50AAAAAQAAAAdhZGRyZXNzCQABLAAAAAICAAAAFCVzJXNfX3dhbnRlZEFtb3VudF9fBQAAAAdhZGRyZXNzAQAAAAprZXlBc3NldElkAAAAAQAAAAdvcmRlcklkCQABLAAAAAICAAAADyVzJXNfX2Fzc2V0SWRfXwUAAAAHb3JkZXJJZAEAAAAJa2V5QW1vdW50AAAAAQAAAAdvcmRlcklkCQABLAAA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AARQGV4dHJOYXRpdmUoMTA2MikAAAABBQAAAAdhZGRyZXNzBQAAAAZhbW91bnQFAAAAB2Fzc2V0SWQJAARMAAAAAgkBAAAADlNjcmlwdFRyYW5zZmVyAAAAAwgFAAAAAWkAAAAGY2FsbGVyBQAAAApyZXN0QW1vdW50BQAAAAdhc3NldElkCQAETAAAAAIJAQAAAAtEZWxldGVFbnRyeQAAAAEJAQAAAA1rZXlTZXJ2aWNlRmVlAAAAAQUAAAAHb3JkZXJJZAkABEwAAAACCQEAAAALRGVsZXRlRW50cnkAAAABCQEAAAAJa2V5QW1vdW50AAAAAQUAAAAHb3JkZXJJZAkABEwAAAACCQEAAAALRGVsZXRlRW50cnkAAAABCQEAAAAKa2V5T3JkZXJJZAAAAAEFAAAAB29yZGVySWQJAARMAAAAAgkBAAAAC0RlbGV0ZUVudHJ5AAAAAQkBAAAACmtleUFzc2V0SWQAAAABBQAAAAdvcmRlcklkBQAAAANuaWwJAARMAAAAAgkBAAAADlNjcmlwdFRyYW5zZmVyAAAAAwkBAAAAEUBleHRyTmF0aXZlKDEwNjIpAAAAAQUAAAAHYWRkcmVzcwUAAAAGYW1vdW50BQAAAAdhc3NldElkCQAETAAAAAIJAQAAAAtEZWxldGVFbnRyeQAAAAEJAQAAAAlrZXlBbW91bnQAAAABBQAAAAdvcmRlcklkCQAETAAAAAIJAQAAAAxJbnRlZ2VyRW50cnkAAAACCQEAAAAJa2V5QW1vdW50AAAAAQUAAAAHb3JkZXJJZAUAAAAKcmVzdEFtb3VudAUAAAADbmlsAAAAAEQ5NbE=", "height": 2867749, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: EPm2tt48aCwdS6tqKXadRcRCaUZvxXB8BUAkW5yQ3sdZ Next: Ga8M349XXYJwVGRnNtEXPgEaWq8czAHxyAhe7RPiUJVi Diff:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | func keyAssetId (address) = ("%s%s__assetId__" + address) | |
5 | - | ||
6 | - | ||
7 | - | func keyAmount (address) = ("%s%s__amount__" + address) | |
8 | - | ||
4 | + | let developer = addressFromStringValue("3P9mTCpBtuAzMkHodb4XwgX4zKYAch2pgwa") | |
9 | 5 | ||
10 | 6 | func keyPartner (address) = ("%s%s__partner__" + address) | |
11 | 7 | ||
14 | 10 | ||
15 | 11 | ||
16 | 12 | func keyWantedAmount (address) = ("%s%s__wantedAmount__" + address) | |
13 | + | ||
14 | + | ||
15 | + | func keyAssetId (orderId) = ("%s%s__assetId__" + orderId) | |
16 | + | ||
17 | + | ||
18 | + | func keyAmount (orderId) = ("%s%s__amount__" + orderId) | |
19 | + | ||
20 | + | ||
21 | + | func keyOrderId (orderId) = ("%s%s__orderId__" + orderId) | |
22 | + | ||
23 | + | ||
24 | + | func keyServiceFee (orderId) = ("%s%s__serviceFee__" + orderId) | |
17 | 25 | ||
18 | 26 | ||
19 | 27 | func toStr (assetId) = if ((assetId == unit)) | |
26 | 34 | else fromBase58String(assetIdStr) | |
27 | 35 | ||
28 | 36 | ||
29 | - | func crossCheckAssetIds (partnerAddress,myOfferedAssetId,myWantedAssetId,partnerOfferedAssetId,partnerWantedAssetId) = if (if ((partnerOfferedAssetId != myWantedAssetId)) | |
30 | - | then true | |
31 | - | else (partnerWantedAssetId != myOfferedAssetId)) | |
32 | - | then throw(((((((((("AssetIds don't match: you want " + myWantedAssetId) + " and pay ") + myOfferedAssetId) + ", but ") + partnerAddress) + " wants ") + partnerWantedAssetId) + " and pays ") + partnerOfferedAssetId)) | |
33 | - | else true | |
34 | - | ||
35 | - | ||
36 | - | func crossCheckAmounts (partnerAddress,myOfferedAmount,myWantedAmount,partnerOfferedAmount,partnerWantedAmount) = if (if ((partnerOfferedAmount != myWantedAmount)) | |
37 | - | then true | |
38 | - | else (partnerWantedAmount != myOfferedAmount)) | |
39 | - | then throw(((((((((("Amounts don't match: you want " + toString(myWantedAmount)) + " and pay ") + toString(myOfferedAmount)) + ", but ") + partnerAddress) + " wants ") + toString(partnerWantedAmount)) + " and pays ") + toString(partnerOfferedAmount))) | |
40 | - | else true | |
41 | - | ||
42 | - | ||
43 | - | func checkAsset (wantAssetId) = { | |
44 | - | let asset = fromStr(wantAssetId) | |
37 | + | func checkAsset (assetId) = { | |
38 | + | let asset = fromStr(assetId) | |
45 | 39 | if (if ((asset != unit)) | |
46 | 40 | then (assetInfo(value(asset)) == unit) | |
47 | 41 | else false) | |
48 | - | then throw("Invalid | |
42 | + | then throw("Invalid assetId: assetInfo missing") | |
49 | 43 | else toStr(asset) | |
50 | 44 | } | |
51 | 45 | ||
52 | 46 | ||
53 | 47 | @Callable(i) | |
54 | - | func escrow (wantAssetId,wantAmount,partnerAddress) = { | |
55 | - | let caller = toString(i.caller) | |
56 | - | if (isDefined(getString(this, keyAssetId(caller)))) | |
57 | - | then throw("You already have an active deal, please cancel it first") | |
58 | - | else if ((size(i.payments) != 1)) | |
59 | - | then throw("Exactly 1 payment expected") | |
60 | - | else { | |
61 | - | let partner = addressFromStringValue(partnerAddress) | |
62 | - | if ((partner == partner)) | |
63 | - | then { | |
64 | - | let wantedAssetId = checkAsset(wantAssetId) | |
65 | - | if ((0 >= wantAmount)) | |
66 | - | then throw("Non-positive wantAmount") | |
67 | - | else { | |
68 | - | let partnerAssetId = getString(this, keyAssetId(partnerAddress)) | |
69 | - | let myAssetId = value(i.payments[0]).assetId | |
70 | - | let myAmount = value(i.payments[0]).amount | |
71 | - | if (isDefined(partnerAssetId)) | |
72 | - | then if ((value(getString(this, keyPartner(partnerAddress))) != caller)) | |
73 | - | then throw(("You are not a partner of " + partnerAddress)) | |
74 | - | else { | |
75 | - | let check = if (crossCheckAssetIds(partnerAddress, toStr(myAssetId), wantedAssetId, value(partnerAssetId), value(getString(this, keyWantedAssetId(partnerAddress))))) | |
76 | - | then crossCheckAmounts(partnerAddress, myAmount, wantAmount, value(getInteger(this, keyAmount(partnerAddress))), value(getInteger(this, keyWantedAmount(partnerAddress)))) | |
77 | - | else false | |
78 | - | if ((check == check)) | |
79 | - | then [ScriptTransfer(partner, myAmount, myAssetId), ScriptTransfer(i.caller, wantAmount, fromStr(wantedAssetId)), DeleteEntry(keyAssetId(partnerAddress)), DeleteEntry(keyAmount(partnerAddress)), DeleteEntry(keyPartner(partnerAddress)), DeleteEntry(keyWantedAssetId(partnerAddress)), DeleteEntry(keyWantedAmount(partnerAddress))] | |
80 | - | else throw("Strict value is not equal to itself.") | |
81 | - | } | |
82 | - | else [StringEntry(keyAssetId(caller), toStr(myAssetId)), IntegerEntry(keyAmount(caller), myAmount), StringEntry(keyPartner(caller), partnerAddress), StringEntry(keyWantedAssetId(caller), wantedAssetId), IntegerEntry(keyWantedAmount(caller), wantAmount)] | |
83 | - | } | |
84 | - | } | |
85 | - | else throw("Strict value is not equal to itself.") | |
86 | - | } | |
87 | - | } | |
48 | + | func escrow (orderId,amount,assetId,developerFee) = if (isDefined(getString(this, keyOrderId(orderId)))) | |
49 | + | then throw(("You already have an order with this id: " + orderId)) | |
50 | + | else if ((0 >= amount)) | |
51 | + | then throw("Non-positive order amount") | |
52 | + | else [IntegerEntry(keyServiceFee(orderId), developerFee), IntegerEntry(keyAmount(orderId), amount), StringEntry(keyOrderId(orderId), orderId), StringEntry(keyAssetId(orderId), assetId)] | |
88 | 53 | ||
89 | 54 | ||
90 | 55 | ||
91 | 56 | @Callable(i) | |
92 | - | func cancel () = { | |
93 | - | let caller = toString(i.caller) | |
94 | - | let assetIdKey = keyAssetId(caller) | |
95 | - | let assetIdRaw = getString(this, assetIdKey) | |
96 | - | if (!(isDefined(assetIdRaw))) | |
97 | - | then throw("You don't have an active deal") | |
57 | + | func cancel (orderId) = if (!(isDefined(keyOrderId(orderId)))) | |
58 | + | then throw(("You don't have an order with this id: " + orderId)) | |
59 | + | else { | |
60 | + | let assetId = toBytes(value(keyAssetId(orderId))) | |
61 | + | let restAmount = toBytes(value(keyAmount(orderId))) | |
62 | + | [ScriptTransfer(i.caller, toInt(restAmount), assetId), DeleteEntry(keyServiceFee(orderId)), DeleteEntry(keyAmount(orderId)), DeleteEntry(keyOrderId(orderId)), DeleteEntry(keyAssetId(orderId))] | |
63 | + | } | |
64 | + | ||
65 | + | ||
66 | + | ||
67 | + | @Callable(i) | |
68 | + | func deal (orderId,address,amount,minAmount) = if (!(isDefined(keyOrderId(orderId)))) | |
69 | + | then throw(("You don't have an order with this id: " + orderId)) | |
70 | + | else if ((amount > toInt(toBytes(value(keyAmount(orderId)))))) | |
71 | + | then throw("The transaction cannot be executed because the seller does not have enough funds") | |
98 | 72 | else { | |
99 | - | let assetIdStr = value(assetIdRaw) | |
100 | - | [ScriptTransfer(i.caller, value(getInteger(this, keyAmount(caller))), fromStr(assetIdStr)), DeleteEntry(assetIdKey), DeleteEntry(keyAmount(caller)), DeleteEntry(keyPartner(caller)), DeleteEntry(keyWantedAssetId(caller)), DeleteEntry(keyWantedAmount(caller))] | |
73 | + | let restAmount = (toInt(toBytes(value(keyAmount(orderId)))) - amount) | |
74 | + | let assetId = toBytes(value(keyAssetId(orderId))) | |
75 | + | if ((minAmount > restAmount)) | |
76 | + | then [ScriptTransfer(addressFromStringValue(address), amount, assetId), ScriptTransfer(i.caller, restAmount, assetId), DeleteEntry(keyServiceFee(orderId)), DeleteEntry(keyAmount(orderId)), DeleteEntry(keyOrderId(orderId)), DeleteEntry(keyAssetId(orderId))] | |
77 | + | else [ScriptTransfer(addressFromStringValue(address), amount, assetId), DeleteEntry(keyAmount(orderId)), IntegerEntry(keyAmount(orderId), restAmount)] | |
101 | 78 | } | |
102 | - | } | |
103 | 79 | ||
104 | 80 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | func keyAssetId (address) = ("%s%s__assetId__" + address) | |
5 | - | ||
6 | - | ||
7 | - | func keyAmount (address) = ("%s%s__amount__" + address) | |
8 | - | ||
4 | + | let developer = addressFromStringValue("3P9mTCpBtuAzMkHodb4XwgX4zKYAch2pgwa") | |
9 | 5 | ||
10 | 6 | func keyPartner (address) = ("%s%s__partner__" + address) | |
11 | 7 | ||
12 | 8 | ||
13 | 9 | func keyWantedAssetId (address) = ("%s%s__wantedAssetId__" + address) | |
14 | 10 | ||
15 | 11 | ||
16 | 12 | func keyWantedAmount (address) = ("%s%s__wantedAmount__" + address) | |
13 | + | ||
14 | + | ||
15 | + | func keyAssetId (orderId) = ("%s%s__assetId__" + orderId) | |
16 | + | ||
17 | + | ||
18 | + | func keyAmount (orderId) = ("%s%s__amount__" + orderId) | |
19 | + | ||
20 | + | ||
21 | + | func keyOrderId (orderId) = ("%s%s__orderId__" + orderId) | |
22 | + | ||
23 | + | ||
24 | + | func keyServiceFee (orderId) = ("%s%s__serviceFee__" + orderId) | |
17 | 25 | ||
18 | 26 | ||
19 | 27 | func toStr (assetId) = if ((assetId == unit)) | |
20 | 28 | then "WAVES" | |
21 | 29 | else toBase58String(value(assetId)) | |
22 | 30 | ||
23 | 31 | ||
24 | 32 | func fromStr (assetIdStr) = if ((assetIdStr == "WAVES")) | |
25 | 33 | then unit | |
26 | 34 | else fromBase58String(assetIdStr) | |
27 | 35 | ||
28 | 36 | ||
29 | - | func crossCheckAssetIds (partnerAddress,myOfferedAssetId,myWantedAssetId,partnerOfferedAssetId,partnerWantedAssetId) = if (if ((partnerOfferedAssetId != myWantedAssetId)) | |
30 | - | then true | |
31 | - | else (partnerWantedAssetId != myOfferedAssetId)) | |
32 | - | then throw(((((((((("AssetIds don't match: you want " + myWantedAssetId) + " and pay ") + myOfferedAssetId) + ", but ") + partnerAddress) + " wants ") + partnerWantedAssetId) + " and pays ") + partnerOfferedAssetId)) | |
33 | - | else true | |
34 | - | ||
35 | - | ||
36 | - | func crossCheckAmounts (partnerAddress,myOfferedAmount,myWantedAmount,partnerOfferedAmount,partnerWantedAmount) = if (if ((partnerOfferedAmount != myWantedAmount)) | |
37 | - | then true | |
38 | - | else (partnerWantedAmount != myOfferedAmount)) | |
39 | - | then throw(((((((((("Amounts don't match: you want " + toString(myWantedAmount)) + " and pay ") + toString(myOfferedAmount)) + ", but ") + partnerAddress) + " wants ") + toString(partnerWantedAmount)) + " and pays ") + toString(partnerOfferedAmount))) | |
40 | - | else true | |
41 | - | ||
42 | - | ||
43 | - | func checkAsset (wantAssetId) = { | |
44 | - | let asset = fromStr(wantAssetId) | |
37 | + | func checkAsset (assetId) = { | |
38 | + | let asset = fromStr(assetId) | |
45 | 39 | if (if ((asset != unit)) | |
46 | 40 | then (assetInfo(value(asset)) == unit) | |
47 | 41 | else false) | |
48 | - | then throw("Invalid | |
42 | + | then throw("Invalid assetId: assetInfo missing") | |
49 | 43 | else toStr(asset) | |
50 | 44 | } | |
51 | 45 | ||
52 | 46 | ||
53 | 47 | @Callable(i) | |
54 | - | func escrow (wantAssetId,wantAmount,partnerAddress) = { | |
55 | - | let caller = toString(i.caller) | |
56 | - | if (isDefined(getString(this, keyAssetId(caller)))) | |
57 | - | then throw("You already have an active deal, please cancel it first") | |
58 | - | else if ((size(i.payments) != 1)) | |
59 | - | then throw("Exactly 1 payment expected") | |
60 | - | else { | |
61 | - | let partner = addressFromStringValue(partnerAddress) | |
62 | - | if ((partner == partner)) | |
63 | - | then { | |
64 | - | let wantedAssetId = checkAsset(wantAssetId) | |
65 | - | if ((0 >= wantAmount)) | |
66 | - | then throw("Non-positive wantAmount") | |
67 | - | else { | |
68 | - | let partnerAssetId = getString(this, keyAssetId(partnerAddress)) | |
69 | - | let myAssetId = value(i.payments[0]).assetId | |
70 | - | let myAmount = value(i.payments[0]).amount | |
71 | - | if (isDefined(partnerAssetId)) | |
72 | - | then if ((value(getString(this, keyPartner(partnerAddress))) != caller)) | |
73 | - | then throw(("You are not a partner of " + partnerAddress)) | |
74 | - | else { | |
75 | - | let check = if (crossCheckAssetIds(partnerAddress, toStr(myAssetId), wantedAssetId, value(partnerAssetId), value(getString(this, keyWantedAssetId(partnerAddress))))) | |
76 | - | then crossCheckAmounts(partnerAddress, myAmount, wantAmount, value(getInteger(this, keyAmount(partnerAddress))), value(getInteger(this, keyWantedAmount(partnerAddress)))) | |
77 | - | else false | |
78 | - | if ((check == check)) | |
79 | - | then [ScriptTransfer(partner, myAmount, myAssetId), ScriptTransfer(i.caller, wantAmount, fromStr(wantedAssetId)), DeleteEntry(keyAssetId(partnerAddress)), DeleteEntry(keyAmount(partnerAddress)), DeleteEntry(keyPartner(partnerAddress)), DeleteEntry(keyWantedAssetId(partnerAddress)), DeleteEntry(keyWantedAmount(partnerAddress))] | |
80 | - | else throw("Strict value is not equal to itself.") | |
81 | - | } | |
82 | - | else [StringEntry(keyAssetId(caller), toStr(myAssetId)), IntegerEntry(keyAmount(caller), myAmount), StringEntry(keyPartner(caller), partnerAddress), StringEntry(keyWantedAssetId(caller), wantedAssetId), IntegerEntry(keyWantedAmount(caller), wantAmount)] | |
83 | - | } | |
84 | - | } | |
85 | - | else throw("Strict value is not equal to itself.") | |
86 | - | } | |
87 | - | } | |
48 | + | func escrow (orderId,amount,assetId,developerFee) = if (isDefined(getString(this, keyOrderId(orderId)))) | |
49 | + | then throw(("You already have an order with this id: " + orderId)) | |
50 | + | else if ((0 >= amount)) | |
51 | + | then throw("Non-positive order amount") | |
52 | + | else [IntegerEntry(keyServiceFee(orderId), developerFee), IntegerEntry(keyAmount(orderId), amount), StringEntry(keyOrderId(orderId), orderId), StringEntry(keyAssetId(orderId), assetId)] | |
88 | 53 | ||
89 | 54 | ||
90 | 55 | ||
91 | 56 | @Callable(i) | |
92 | - | func cancel () = { | |
93 | - | let caller = toString(i.caller) | |
94 | - | let assetIdKey = keyAssetId(caller) | |
95 | - | let assetIdRaw = getString(this, assetIdKey) | |
96 | - | if (!(isDefined(assetIdRaw))) | |
97 | - | then throw("You don't have an active deal") | |
57 | + | func cancel (orderId) = if (!(isDefined(keyOrderId(orderId)))) | |
58 | + | then throw(("You don't have an order with this id: " + orderId)) | |
59 | + | else { | |
60 | + | let assetId = toBytes(value(keyAssetId(orderId))) | |
61 | + | let restAmount = toBytes(value(keyAmount(orderId))) | |
62 | + | [ScriptTransfer(i.caller, toInt(restAmount), assetId), DeleteEntry(keyServiceFee(orderId)), DeleteEntry(keyAmount(orderId)), DeleteEntry(keyOrderId(orderId)), DeleteEntry(keyAssetId(orderId))] | |
63 | + | } | |
64 | + | ||
65 | + | ||
66 | + | ||
67 | + | @Callable(i) | |
68 | + | func deal (orderId,address,amount,minAmount) = if (!(isDefined(keyOrderId(orderId)))) | |
69 | + | then throw(("You don't have an order with this id: " + orderId)) | |
70 | + | else if ((amount > toInt(toBytes(value(keyAmount(orderId)))))) | |
71 | + | then throw("The transaction cannot be executed because the seller does not have enough funds") | |
98 | 72 | else { | |
99 | - | let assetIdStr = value(assetIdRaw) | |
100 | - | [ScriptTransfer(i.caller, value(getInteger(this, keyAmount(caller))), fromStr(assetIdStr)), DeleteEntry(assetIdKey), DeleteEntry(keyAmount(caller)), DeleteEntry(keyPartner(caller)), DeleteEntry(keyWantedAssetId(caller)), DeleteEntry(keyWantedAmount(caller))] | |
73 | + | let restAmount = (toInt(toBytes(value(keyAmount(orderId)))) - amount) | |
74 | + | let assetId = toBytes(value(keyAssetId(orderId))) | |
75 | + | if ((minAmount > restAmount)) | |
76 | + | then [ScriptTransfer(addressFromStringValue(address), amount, assetId), ScriptTransfer(i.caller, restAmount, assetId), DeleteEntry(keyServiceFee(orderId)), DeleteEntry(keyAmount(orderId)), DeleteEntry(keyOrderId(orderId)), DeleteEntry(keyAssetId(orderId))] | |
77 | + | else [ScriptTransfer(addressFromStringValue(address), amount, assetId), DeleteEntry(keyAmount(orderId)), IntegerEntry(keyAmount(orderId), restAmount)] | |
101 | 78 | } | |
102 | - | } | |
103 | 79 | ||
104 | 80 |
github/deemru/w8io/169f3d6 32.63 ms ◑