tx · E2AHDVsdo9hLL4FN1wT6FRC3CHziXBgpKdpqCuN87Pxt 3N7a7sTSKaE621QewSqQcL1mUbknJjnLkZc: -0.01000000 Waves 2021.10.21 23:42 [1756548] smart account 3N7a7sTSKaE621QewSqQcL1mUbknJjnLkZc > SELF 0.00000000 Waves
{ "type": 13, "id": "E2AHDVsdo9hLL4FN1wT6FRC3CHziXBgpKdpqCuN87Pxt", "fee": 1000000, "feeAssetId": null, "timestamp": 1634848965479, "version": 2, "chainId": 84, "sender": "3N7a7sTSKaE621QewSqQcL1mUbknJjnLkZc", "senderPublicKey": "6LrPmGtwuADhwHYcxBouLzwfSTGgucbwYG5Pja7LUrcd", "proofs": [ "fkxCFwVy6PqfhZY1qcuMsH9Y1hnFZCRfAFsWK2FK1NrhbZQiLNbUakKHyShjMVE51C5eGn9s6Mt2hc4YzzctHbK" ], "script": "base64:AAIFAAAAAAAAABcIAhIECgIIGBIDCgEBEgMKAQESAwoBAQAAABAAAAAACm9mZmVySWRLZXkCAAAADSRPRkZFUl9OVU1CRVIAAAAAB3Rlc3RLZXkCAAAABSRURVNUAAAAAA9vZmZlck9wZW5TdGF0dXMAAAAAAAAAAAEAAAAAE29mZmVyQ2FuY2VsZWRTdGF0dXMAAAAAAAAAAAIAAAAAE29mZmVyQWNjZXB0ZWRTdGF0dXMAAAAAAAAAAAMAAAAAE29mZmVyUmVqZWN0ZWRTdGF0dXMAAAAAAAAAAAQAAAAAFndhdmVzU3RhbmRJbkJ5dGVWZWN0b3IJAAGbAAAAAQIAAAAFV0FWRVMBAAAAEWdldE9mZmVyU3RhdHVzS2V5AAAAAQAAAAdvZmZlcklkCQABLAAAAAIJAAGkAAAAAQUAAAAHb2ZmZXJJZAIAAAAHX3N0YXR1cwEAAAAWZ2V0T2ZmZXJBZGRyZXNzRnJvbUtleQAAAAEAAAAHb2ZmZXJJZAkAASwAAAACCQABpAAAAAEFAAAAB29mZmVySWQCAAAABV9mcm9tAQAAABRnZXRPZmZlckFkZHJlc3N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NLZXkAAAABBQAAAAdvZmZlcklkAwkBAAAAAiE9AAAAAgUAAAALb2ZmZXJTdGF0dXMFAAAAD29mZmVyT3BlblN0YXR1cwkAAAIAAAABAgAAABlvZmZlciBzdGF0dXMgbXVzdCBiZSBvcGVuBAAAAAlhZGRyZXNzVG8JAQAAABFAZXh0ck5hdGl2ZSgxMDUzKQAAAAIFAAAABHRoaXMJAQAAABRnZXRPZmZlckFkZHJlc3NUb0tleQAAAAEFAAAAB29mZmVySWQEAAAACWNhbGxlclN0cgkAAlgAAAABCAgFAAAAAWkAAAAGY2FsbGVyAAAABWJ5dGVzAwkBAAAAAiE9AAAAAgUAAAAJYWRkcmVzc1RvBQAAAAljYWxsZXJTdHIJAAACAAAAAQIAAAAcb2ZmZXIgbXVzdCBiZSBtYWRlIHRvIGNhbGxlcgkABEwAAAACCQEAAAAMSW50ZWdlckVudHJ5AAAAAgkBAAAAEWdldE9mZmVyU3RhdHVzS2V5AAAAAQUAAAAHb2ZmZXJJZAUAAAATb2ZmZXJSZWplY3RlZFN0YXR1cwUAAAADbmlsAAAAAGd8nhQ=", "height": 1756548, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: AshK3p7zNscKXJwKwy5AH9Zk25mqgcq55zf9ztdZvjnH Next: 9N8EDBLqcnWxKYnRMt6jJHLYw1wzjsmUVfR7xcdVxpGx Diff:
Old | New | Differences | |
---|---|---|---|
12 | 12 | let offerAcceptedStatus = 3 | |
13 | 13 | ||
14 | 14 | let offerRejectedStatus = 4 | |
15 | + | ||
16 | + | let wavesStandInByteVector = toBytes("WAVES") | |
15 | 17 | ||
16 | 18 | func getOfferStatusKey (offerId) = (toString(offerId) + "_status") | |
17 | 19 | ||
45 | 47 | } | |
46 | 48 | ||
47 | 49 | ||
50 | + | func tryGetAssetId (offerId,itemNumber) = { | |
51 | + | let val = fromBase64String(getStringValue(this, getOfferOfferedAssetKey(offerId, itemNumber))) | |
52 | + | if ((val == wavesStandInByteVector)) | |
53 | + | then unit | |
54 | + | else val | |
55 | + | } | |
56 | + | ||
57 | + | ||
48 | 58 | @Callable(i) | |
49 | 59 | func createOffer (toAddress,asset) = { | |
50 | 60 | let offerId = tryGetInteger(offerIdKey) | |
51 | 61 | let firstPayment = value(i.payments[0]) | |
52 | 62 | if (!(isDefined(firstPayment))) | |
53 | 63 | then throw("no payment") | |
54 | - | else [IntegerEntry(getOfferStatusKey(offerId), offerOpenStatus), StringEntry(getOfferAddressFromKey(offerId), toBase58String(i.caller.bytes)), StringEntry(getOfferAddressToKey(offerId), toAddress), StringEntry(getOfferOfferedAssetKey(offerId, 0), | |
64 | + | else [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)] | |
55 | 65 | } | |
56 | 66 | ||
57 | 67 | ||
66 | 76 | let callerStr = toBase58String(i.caller.bytes) | |
67 | 77 | if ((addressFrom != callerStr)) | |
68 | 78 | then throw("offer must be made by caller") | |
69 | - | else [IntegerEntry(getOfferStatusKey(offerId), offerCanceledStatus)] | |
79 | + | else { | |
80 | + | let assetId = tryGetAssetId(offerId, 0) | |
81 | + | let assetAmount = tryGetInteger(getOfferOfferedAmountKey(offerId, 0)) | |
82 | + | [IntegerEntry(getOfferStatusKey(offerId), offerCanceledStatus), ScriptTransfer(i.caller, assetAmount, assetId)] | |
83 | + | } | |
70 | 84 | } | |
71 | 85 | } | |
72 | 86 |
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 | + | ||
16 | + | let wavesStandInByteVector = toBytes("WAVES") | |
15 | 17 | ||
16 | 18 | func getOfferStatusKey (offerId) = (toString(offerId) + "_status") | |
17 | 19 | ||
18 | 20 | ||
19 | 21 | func getOfferAddressFromKey (offerId) = (toString(offerId) + "_from") | |
20 | 22 | ||
21 | 23 | ||
22 | 24 | func getOfferAddressToKey (offerId) = (toString(offerId) + "_to") | |
23 | 25 | ||
24 | 26 | ||
25 | 27 | func getOfferOfferedAssetKey (offerId,itemNumber) = (((toString(offerId) + "_") + toString(itemNumber)) + "_offered_asset_id") | |
26 | 28 | ||
27 | 29 | ||
28 | 30 | func getOfferOfferedAmountKey (offerId,itemNumber) = (((toString(offerId) + "_") + toString(itemNumber)) + "_offered_asset_amount") | |
29 | 31 | ||
30 | 32 | ||
31 | 33 | func getOfferAskedAssetKey (offerId,itemNumber) = (((toString(offerId) + "_") + toString(itemNumber)) + "_asked_asset_id") | |
32 | 34 | ||
33 | 35 | ||
34 | 36 | func getOfferAskedAmountKey (offerId,itemNumber) = (((toString(offerId) + "_") + toString(itemNumber)) + "_asked_asset_amount") | |
35 | 37 | ||
36 | 38 | ||
37 | 39 | func tryGetInteger (key) = { | |
38 | 40 | let val = match getInteger(this, key) { | |
39 | 41 | case b: Int => | |
40 | 42 | b | |
41 | 43 | case _ => | |
42 | 44 | 0 | |
43 | 45 | } | |
44 | 46 | val | |
45 | 47 | } | |
46 | 48 | ||
47 | 49 | ||
50 | + | func tryGetAssetId (offerId,itemNumber) = { | |
51 | + | let val = fromBase64String(getStringValue(this, getOfferOfferedAssetKey(offerId, itemNumber))) | |
52 | + | if ((val == wavesStandInByteVector)) | |
53 | + | then unit | |
54 | + | else val | |
55 | + | } | |
56 | + | ||
57 | + | ||
48 | 58 | @Callable(i) | |
49 | 59 | func createOffer (toAddress,asset) = { | |
50 | 60 | let offerId = tryGetInteger(offerIdKey) | |
51 | 61 | let firstPayment = value(i.payments[0]) | |
52 | 62 | if (!(isDefined(firstPayment))) | |
53 | 63 | then throw("no payment") | |
54 | - | else [IntegerEntry(getOfferStatusKey(offerId), offerOpenStatus), StringEntry(getOfferAddressFromKey(offerId), toBase58String(i.caller.bytes)), StringEntry(getOfferAddressToKey(offerId), toAddress), StringEntry(getOfferOfferedAssetKey(offerId, 0), | |
64 | + | else [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)] | |
55 | 65 | } | |
56 | 66 | ||
57 | 67 | ||
58 | 68 | ||
59 | 69 | @Callable(i) | |
60 | 70 | func cancelOffer (offerId) = { | |
61 | 71 | let offerStatus = tryGetInteger(getOfferStatusKey(offerId)) | |
62 | 72 | if ((offerStatus != offerOpenStatus)) | |
63 | 73 | then throw("offer status must be open") | |
64 | 74 | else { | |
65 | 75 | let addressFrom = getStringValue(this, getOfferAddressFromKey(offerId)) | |
66 | 76 | let callerStr = toBase58String(i.caller.bytes) | |
67 | 77 | if ((addressFrom != callerStr)) | |
68 | 78 | then throw("offer must be made by caller") | |
69 | - | else [IntegerEntry(getOfferStatusKey(offerId), offerCanceledStatus)] | |
79 | + | else { | |
80 | + | let assetId = tryGetAssetId(offerId, 0) | |
81 | + | let assetAmount = tryGetInteger(getOfferOfferedAmountKey(offerId, 0)) | |
82 | + | [IntegerEntry(getOfferStatusKey(offerId), offerCanceledStatus), ScriptTransfer(i.caller, assetAmount, assetId)] | |
83 | + | } | |
70 | 84 | } | |
71 | 85 | } | |
72 | 86 | ||
73 | 87 | ||
74 | 88 | ||
75 | 89 | @Callable(i) | |
76 | 90 | func acceptOffer (offerId) = { | |
77 | 91 | let offerStatus = tryGetInteger(getOfferStatusKey(offerId)) | |
78 | 92 | if ((offerStatus != offerOpenStatus)) | |
79 | 93 | then throw("offer status must be open") | |
80 | 94 | else { | |
81 | 95 | let addressTo = getStringValue(this, getOfferAddressToKey(offerId)) | |
82 | 96 | let callerStr = toBase58String(i.caller.bytes) | |
83 | 97 | if ((addressTo != callerStr)) | |
84 | 98 | then throw("offer must be made to caller") | |
85 | 99 | else [IntegerEntry(getOfferStatusKey(offerId), offerAcceptedStatus)] | |
86 | 100 | } | |
87 | 101 | } | |
88 | 102 | ||
89 | 103 | ||
90 | 104 | ||
91 | 105 | @Callable(i) | |
92 | 106 | func rejectOffer (offerId) = { | |
93 | 107 | let offerStatus = tryGetInteger(getOfferStatusKey(offerId)) | |
94 | 108 | if ((offerStatus != offerOpenStatus)) | |
95 | 109 | then throw("offer status must be open") | |
96 | 110 | else { | |
97 | 111 | let addressTo = getStringValue(this, getOfferAddressToKey(offerId)) | |
98 | 112 | let callerStr = toBase58String(i.caller.bytes) | |
99 | 113 | if ((addressTo != callerStr)) | |
100 | 114 | then throw("offer must be made to caller") | |
101 | 115 | else [IntegerEntry(getOfferStatusKey(offerId), offerRejectedStatus)] | |
102 | 116 | } | |
103 | 117 | } | |
104 | 118 | ||
105 | 119 |
github/deemru/w8io/026f985 30.05 ms ◑