tx · 9s4HzRGug4Jii9dBtYjSao3raLMji4sJKJfJyhzC4Xdo 3N7a7sTSKaE621QewSqQcL1mUbknJjnLkZc: -0.01000000 Waves 2021.10.22 18:05 [1757664] smart account 3N7a7sTSKaE621QewSqQcL1mUbknJjnLkZc > SELF 0.00000000 Waves
{ "type": 13, "id": "9s4HzRGug4Jii9dBtYjSao3raLMji4sJKJfJyhzC4Xdo", "fee": 1000000, "feeAssetId": null, "timestamp": 1634915174113, "version": 2, "chainId": 84, "sender": "3N7a7sTSKaE621QewSqQcL1mUbknJjnLkZc", "senderPublicKey": "6LrPmGtwuADhwHYcxBouLzwfSTGgucbwYG5Pja7LUrcd", "proofs": [ "5qjPU1fHLwnWm2AHzHfk5ds6UmUhTPMbZGhm2RksKLQ8Y6dCJrCvEjhWHa1GgwiJw8JvY1oQ9NP8AwVtESm7d1nV" ], "script": "base64:AAIFAAAAAAAAABcIAhIECgIIGRIDCgEBEgMKAQESAwoBAQAAABUAAAAACm9mZmVySWRLZXkCAAAADSRPRkZFUl9OVU1CRVIAAAAAB3Rlc3RLZXkCAAAABSRURVNUAAAAAA9vZmZlck9wZW5TdGF0dXMAAAAAAAAAAAEAAAAAE29mZmVyQ2FuY2VsZWRTdGF0dXMAAAAAAAAAAAIAAAAAE29mZmVyQWNjZXB0ZWRTdGF0dXMAAAAAAAAAAAMAAAAAE29mZmVyUmVqZWN0ZWRTdGF0dXMAAAAAAAAAAAQAAAAAEndhdmVzU3RhbmRJblN0cmluZwIAAAAFV0FWRVMAAAAAFndhdmVzU3RhbmRJbkJ5dGVWZWN0b3IJAAGbAAAAAQUAAAASd2F2ZXNTdGFuZEluU3RyaW5nAAAAABJ3YXZlc1N0YW5kSW5CYXNlNjQJAAJaAAAAAQUAAAAWd2F2ZXNTdGFuZEluQnl0ZVZlY3RvcgEAAAARZ2V0T2ZmZXJTdGF0dXNLZXkAAAABAAAAB29mZmVySWQJAAEsAAAAAgkAAaQAAAABBQAAAAdvZmZlcklkAgAAAAdfc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ZGRyZXNzVG8FAAAACWNhbGxlclN0cgkAAAIAAAABAgAAABxvZmZlciBtdXN0IGJlIG1hZGUgdG8gY2FsbGVyCQEAAAAJZHJvcE9mZmVyAAAAAgUAAAAHb2ZmZXJJZAUAAAATb2ZmZXJSZWplY3RlZFN0YXR1cwAAAACuqEbJ", "height": 1757664, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: trJuHoX1NitFuvuN9RLQ4nq5rCwRBmH4qXBDwrvjfFu Next: EoQ5H2avxZKPCvwRrn7ZsNX841NZ9Ugb1CCkykAKJdYC Diff:
Old | New | Differences | |
---|---|---|---|
73 | 73 | } | |
74 | 74 | ||
75 | 75 | ||
76 | - | func tryGetAssetId ( | |
77 | - | let val = fromBase64String(getStringValue(this, | |
76 | + | func tryGetAssetId (key) = { | |
77 | + | let val = fromBase64String(getStringValue(this, key)) | |
78 | 78 | if ((val == wavesStandInByteVector)) | |
79 | 79 | then unit | |
80 | 80 | else val | |
83 | 83 | ||
84 | 84 | func dropOffer (offerId,dropStatus) = { | |
85 | 85 | let addressFrom = Address(fromBase58String(getStringValue(this, getOfferAddressFromKey(offerId)))) | |
86 | - | let assetId = tryGetAssetId(offerId, 0) | |
86 | + | let assetId = tryGetAssetId(getOfferOfferedAssetKey(offerId, 0)) | |
87 | 87 | let assetAmount = tryGetInteger(getOfferOfferedAmountKey(offerId, 0)) | |
88 | 88 | [IntegerEntry(getOfferStatusKey(offerId), dropStatus), ScriptTransfer(addressFrom, assetAmount, assetId)] | |
89 | 89 | } | |
126 | 126 | let callerStr = toBase58String(i.caller.bytes) | |
127 | 127 | if ((addressTo != callerStr)) | |
128 | 128 | then throw("offer must be made to caller") | |
129 | - | else [IntegerEntry(getOfferStatusKey(offerId), offerAcceptedStatus)] | |
129 | + | else { | |
130 | + | let askedAsset0Id = tryGetAssetId(getOfferAskedAssetKey(offerId, 0)) | |
131 | + | let askedAsset0Amount = tryGetInteger(getOfferAskedAmountKey(offerId, 0)) | |
132 | + | let firstPayment = value(i.payments[0]) | |
133 | + | if (!(isDefined(firstPayment))) | |
134 | + | then throw("no payment") | |
135 | + | else if ((firstPayment.assetId != askedAsset0Id)) | |
136 | + | then throw("not same asset") | |
137 | + | else if ((firstPayment.amount != askedAsset0Amount)) | |
138 | + | then throw("not same amount") | |
139 | + | else { | |
140 | + | let offeredAsset0Id = tryGetAssetId(getOfferOfferedAssetKey(offerId, 0)) | |
141 | + | let offeredAsset0Amount = tryGetInteger(getOfferOfferedAmountKey(offerId, 0)) | |
142 | + | let addressFromAsAddress = Address(fromBase58String(getStringValue(this, getOfferAddressFromKey(offerId)))) | |
143 | + | let addressToAsAddress = Address(fromBase58String(getStringValue(this, getOfferAddressFromKey(offerId)))) | |
144 | + | [IntegerEntry(getOfferStatusKey(offerId), offerAcceptedStatus), ScriptTransfer(addressFromAsAddress, askedAsset0Amount, askedAsset0Id), ScriptTransfer(addressToAsAddress, offeredAsset0Amount, offeredAsset0Id)] | |
145 | + | } | |
146 | + | } | |
130 | 147 | } | |
131 | 148 | } | |
132 | 149 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let offerIdKey = "$OFFER_NUMBER" | |
5 | 5 | ||
6 | 6 | let testKey = "$TEST" | |
7 | 7 | ||
8 | 8 | let offerOpenStatus = 1 | |
9 | 9 | ||
10 | 10 | let offerCanceledStatus = 2 | |
11 | 11 | ||
12 | 12 | let offerAcceptedStatus = 3 | |
13 | 13 | ||
14 | 14 | let offerRejectedStatus = 4 | |
15 | 15 | ||
16 | 16 | let wavesStandInString = "WAVES" | |
17 | 17 | ||
18 | 18 | let wavesStandInByteVector = toBytes(wavesStandInString) | |
19 | 19 | ||
20 | 20 | let wavesStandInBase64 = toBase64String(wavesStandInByteVector) | |
21 | 21 | ||
22 | 22 | func getOfferStatusKey (offerId) = (toString(offerId) + "_status") | |
23 | 23 | ||
24 | 24 | ||
25 | 25 | func getOfferAddressFromKey (offerId) = (toString(offerId) + "_from") | |
26 | 26 | ||
27 | 27 | ||
28 | 28 | func getOfferAddressToKey (offerId) = (toString(offerId) + "_to") | |
29 | 29 | ||
30 | 30 | ||
31 | 31 | func getOfferOfferedAssetKey (offerId,itemNumber) = (((toString(offerId) + "_") + toString(itemNumber)) + "_offered_asset_id") | |
32 | 32 | ||
33 | 33 | ||
34 | 34 | func getOfferOfferedAmountKey (offerId,itemNumber) = (((toString(offerId) + "_") + toString(itemNumber)) + "_offered_asset_amount") | |
35 | 35 | ||
36 | 36 | ||
37 | 37 | func getOfferAskedAssetKey (offerId,itemNumber) = (((toString(offerId) + "_") + toString(itemNumber)) + "_asked_asset_id") | |
38 | 38 | ||
39 | 39 | ||
40 | 40 | func getOfferAskedAmountKey (offerId,itemNumber) = (((toString(offerId) + "_") + toString(itemNumber)) + "_asked_asset_amount") | |
41 | 41 | ||
42 | 42 | ||
43 | 43 | func tryGetInteger (key) = { | |
44 | 44 | let val = match getInteger(this, key) { | |
45 | 45 | case b: Int => | |
46 | 46 | b | |
47 | 47 | case _ => | |
48 | 48 | 0 | |
49 | 49 | } | |
50 | 50 | val | |
51 | 51 | } | |
52 | 52 | ||
53 | 53 | ||
54 | 54 | func tryGetAssetIdFromAssetList (asset) = { | |
55 | 55 | let res = match asset[0] { | |
56 | 56 | case b: String => | |
57 | 57 | toBytes(b) | |
58 | 58 | case _ => | |
59 | 59 | throw("must have an assetId") | |
60 | 60 | } | |
61 | 61 | res | |
62 | 62 | } | |
63 | 63 | ||
64 | 64 | ||
65 | 65 | func tryGetAmountFromAssetList (asset) = { | |
66 | 66 | let res = match asset[1] { | |
67 | 67 | case b: Int => | |
68 | 68 | b | |
69 | 69 | case _ => | |
70 | 70 | throw("must have an amount") | |
71 | 71 | } | |
72 | 72 | res | |
73 | 73 | } | |
74 | 74 | ||
75 | 75 | ||
76 | - | func tryGetAssetId ( | |
77 | - | let val = fromBase64String(getStringValue(this, | |
76 | + | func tryGetAssetId (key) = { | |
77 | + | let val = fromBase64String(getStringValue(this, key)) | |
78 | 78 | if ((val == wavesStandInByteVector)) | |
79 | 79 | then unit | |
80 | 80 | else val | |
81 | 81 | } | |
82 | 82 | ||
83 | 83 | ||
84 | 84 | func dropOffer (offerId,dropStatus) = { | |
85 | 85 | let addressFrom = Address(fromBase58String(getStringValue(this, getOfferAddressFromKey(offerId)))) | |
86 | - | let assetId = tryGetAssetId(offerId, 0) | |
86 | + | let assetId = tryGetAssetId(getOfferOfferedAssetKey(offerId, 0)) | |
87 | 87 | let assetAmount = tryGetInteger(getOfferOfferedAmountKey(offerId, 0)) | |
88 | 88 | [IntegerEntry(getOfferStatusKey(offerId), dropStatus), ScriptTransfer(addressFrom, assetAmount, assetId)] | |
89 | 89 | } | |
90 | 90 | ||
91 | 91 | ||
92 | 92 | @Callable(i) | |
93 | 93 | func createOffer (toAddress,asset0) = { | |
94 | 94 | let offerId = (tryGetInteger(offerIdKey) + 1) | |
95 | 95 | let firstPayment = value(i.payments[0]) | |
96 | 96 | if (!(isDefined(firstPayment))) | |
97 | 97 | then throw("no payment") | |
98 | 98 | else [IntegerEntry(offerIdKey, offerId), IntegerEntry(getOfferStatusKey(offerId), offerOpenStatus), StringEntry(getOfferAddressFromKey(offerId), toBase58String(i.caller.bytes)), StringEntry(getOfferAddressToKey(offerId), toAddress), StringEntry(getOfferOfferedAssetKey(offerId, 0), toBase64String(valueOrElse(firstPayment.assetId, wavesStandInByteVector))), IntegerEntry(getOfferOfferedAmountKey(offerId, 0), firstPayment.amount), StringEntry(getOfferAskedAssetKey(offerId, 0), toBase64String(tryGetAssetIdFromAssetList(asset0))), IntegerEntry(getOfferAskedAmountKey(offerId, 0), tryGetAmountFromAssetList(asset0))] | |
99 | 99 | } | |
100 | 100 | ||
101 | 101 | ||
102 | 102 | ||
103 | 103 | @Callable(i) | |
104 | 104 | func cancelOffer (offerId) = { | |
105 | 105 | let offerStatus = tryGetInteger(getOfferStatusKey(offerId)) | |
106 | 106 | if ((offerStatus != offerOpenStatus)) | |
107 | 107 | then throw("offer status must be open") | |
108 | 108 | else { | |
109 | 109 | let addressFrom = getStringValue(this, getOfferAddressFromKey(offerId)) | |
110 | 110 | let callerStr = toBase58String(i.caller.bytes) | |
111 | 111 | if ((addressFrom != callerStr)) | |
112 | 112 | then throw("offer must be made by caller") | |
113 | 113 | else dropOffer(offerId, offerCanceledStatus) | |
114 | 114 | } | |
115 | 115 | } | |
116 | 116 | ||
117 | 117 | ||
118 | 118 | ||
119 | 119 | @Callable(i) | |
120 | 120 | func acceptOffer (offerId) = { | |
121 | 121 | let offerStatus = tryGetInteger(getOfferStatusKey(offerId)) | |
122 | 122 | if ((offerStatus != offerOpenStatus)) | |
123 | 123 | then throw("offer status must be open") | |
124 | 124 | else { | |
125 | 125 | let addressTo = getStringValue(this, getOfferAddressToKey(offerId)) | |
126 | 126 | let callerStr = toBase58String(i.caller.bytes) | |
127 | 127 | if ((addressTo != callerStr)) | |
128 | 128 | then throw("offer must be made to caller") | |
129 | - | else [IntegerEntry(getOfferStatusKey(offerId), offerAcceptedStatus)] | |
129 | + | else { | |
130 | + | let askedAsset0Id = tryGetAssetId(getOfferAskedAssetKey(offerId, 0)) | |
131 | + | let askedAsset0Amount = tryGetInteger(getOfferAskedAmountKey(offerId, 0)) | |
132 | + | let firstPayment = value(i.payments[0]) | |
133 | + | if (!(isDefined(firstPayment))) | |
134 | + | then throw("no payment") | |
135 | + | else if ((firstPayment.assetId != askedAsset0Id)) | |
136 | + | then throw("not same asset") | |
137 | + | else if ((firstPayment.amount != askedAsset0Amount)) | |
138 | + | then throw("not same amount") | |
139 | + | else { | |
140 | + | let offeredAsset0Id = tryGetAssetId(getOfferOfferedAssetKey(offerId, 0)) | |
141 | + | let offeredAsset0Amount = tryGetInteger(getOfferOfferedAmountKey(offerId, 0)) | |
142 | + | let addressFromAsAddress = Address(fromBase58String(getStringValue(this, getOfferAddressFromKey(offerId)))) | |
143 | + | let addressToAsAddress = Address(fromBase58String(getStringValue(this, getOfferAddressFromKey(offerId)))) | |
144 | + | [IntegerEntry(getOfferStatusKey(offerId), offerAcceptedStatus), ScriptTransfer(addressFromAsAddress, askedAsset0Amount, askedAsset0Id), ScriptTransfer(addressToAsAddress, offeredAsset0Amount, offeredAsset0Id)] | |
145 | + | } | |
146 | + | } | |
130 | 147 | } | |
131 | 148 | } | |
132 | 149 | ||
133 | 150 | ||
134 | 151 | ||
135 | 152 | @Callable(i) | |
136 | 153 | func rejectOffer (offerId) = { | |
137 | 154 | let offerStatus = tryGetInteger(getOfferStatusKey(offerId)) | |
138 | 155 | if ((offerStatus != offerOpenStatus)) | |
139 | 156 | then throw("offer status must be open") | |
140 | 157 | else { | |
141 | 158 | let addressTo = getStringValue(this, getOfferAddressToKey(offerId)) | |
142 | 159 | let callerStr = toBase58String(i.caller.bytes) | |
143 | 160 | if ((addressTo != callerStr)) | |
144 | 161 | then throw("offer must be made to caller") | |
145 | 162 | else dropOffer(offerId, offerRejectedStatus) | |
146 | 163 | } | |
147 | 164 | } | |
148 | 165 | ||
149 | 166 |
github/deemru/w8io/026f985 32.88 ms ◑