tx · 5ZxKaZqKrWFUA9r44xAPgMSpZKfHSVRicfvqsASXkzsK 3NCTUyjM4SX4hK2kaFTkYv4J2fzcQHtvSjv: -0.05000000 Waves 2020.06.21 10:55 [1053078] smart account 3NCTUyjM4SX4hK2kaFTkYv4J2fzcQHtvSjv > SELF 0.00000000 Waves
{ "type": 13, "id": "5ZxKaZqKrWFUA9r44xAPgMSpZKfHSVRicfvqsASXkzsK", "fee": 5000000, "feeAssetId": null, "timestamp": 1592726137345, "version": 1, "sender": "3NCTUyjM4SX4hK2kaFTkYv4J2fzcQHtvSjv", "senderPublicKey": "CCEAkP4AnTM1HmKyRheQLmgNxPKACsL5hcH72JUeCiDJ", "proofs": [ "5raoFQWMk8KnUQFgtWDfYUKqY21cCXzstJyXnXTcSeGszMmrncDFsrtoPaLK1ZcqnWyeyWbEBT53ar2CAmRrYUkW" ], "script": "base64:AAIDAAAAAAAAABoIARIHCgUIAQEICBIDCgEIEgMKAQgSAwoBCAAAAAMAAAAADm93bmVyUHVibGljS2V5AQAAACCmUNWS0Pf/tmct+/B/I05Ro9F4HTOauOin2of4SgTvNQEAAAAKcmFuZG9taXplcgAAAAEAAAADaW52BAAAAARyYW5kCQAAywAAAAIJAADLAAAAAgkAAMsAAAACCQAAywAAAAIIBQAAAANpbnYAAAANdHJhbnNhY3Rpb25JZAgFAAAAA2ludgAAAA9jYWxsZXJQdWJsaWNLZXkIBQAAAAlsYXN0QmxvY2sAAAATZ2VuZXJhdGlvblNpZ25hdHVyZQkAAZoAAAABCAUAAAAJbGFzdEJsb2NrAAAACXRpbWVzdGFtcAkAAZoAAAABCAUAAAAJbGFzdEJsb2NrAAAABmhlaWdodAkAAfcAAAABBQAAAARyYW5kAQAAABFvZmZlckVycm9ySGFuZGxlcgAAAAYAAAAFdG9rZW4AAAAGYW1vdW50AAAABXByaWNlAAAABHR5cGUAAAAFYXNzZXQAAAADaW52AwMDAwkBAAAAASEAAAABCQEAAAAJaXNEZWZpbmVkAAAAAQUAAAAFdG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J5dGVzCQABkQAAAAIIBQAAAAJ0eAAAAAZwcm9vZnMAAAAAAAAAAAAFAAAADm93bmVyUHVibGljS2V5AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAABdJbnZva2VTY3JpcHRUcmFuc2FjdGlvbgkAAfQAAAADCAUAAAACdHgAAAAJYm9keUJ5dGVzCQABkQAAAAIIBQAAAAJ0eAAAAAZwcm9vZnMAAAAAAAAAAAAIBQAAAAJ0eAAAAA9zZW5kZXJQdWJsaWNLZXkHCuzIAQ==", "chainId": 84, "height": 1053078, "spentComplexity": 0 } View: original | compacted Prev: E6EJN2SfxwKA1EZk4EyRKasZp9wjNrAmWFELSfJpshDP Next: hb1KvygDyKWXft2iZRAnAopvqAKgoNxnTCjDR33N6CW Diff:
Old | New | Differences | |
---|---|---|---|
9 | 9 | } | |
10 | 10 | ||
11 | 11 | ||
12 | - | func offerErrorHandler (token,amount,price,type,inv) = if (if (if (if (!(isDefined(token))) | |
12 | + | func offerErrorHandler (token,amount,price,type,asset,inv) = if (if (if (if (!(isDefined(token))) | |
13 | 13 | then true | |
14 | 14 | else !(isDefined(amount))) | |
15 | 15 | then true | |
28 | 28 | let payment = extract(inv.payment) | |
29 | 29 | if ((payment.amount != (amount * 100000000))) | |
30 | 30 | then throw("Payment amount insufficient") | |
31 | - | else true | |
31 | + | else if ((asset != token)) | |
32 | + | then throw("AssetId invalid") | |
33 | + | else true | |
32 | 34 | } | |
33 | 35 | else true | |
34 | 36 | ||
35 | 37 | ||
36 | 38 | @Callable(i) | |
37 | - | func postOffer (tokenIn,amountIn,priceIn,typeIn) = if (offerErrorHandler(tokenIn, amountIn, priceIn, typeIn, i)) | |
39 | + | func postOffer (tokenIn,amountIn,priceIn,typeIn,assetIn) = if (offerErrorHandler(tokenIn, amountIn, priceIn, typeIn, assetIn, i)) | |
38 | 40 | then { | |
39 | 41 | let offerId = toBase64String(randomizer(i)) | |
40 | - | let offerDetails = ((((((tokenIn + ",") + toString(amountIn)) + ",") + toString(priceIn)) + ",") + typeIn) | |
41 | - | WriteSet([DataEntry(offerId, "open"), DataEntry((offerId + "_tokenId"), tokenIn), DataEntry((offerId + "_amount"), amountIn), DataEntry((offerId + "_price"), priceIn), DataEntry((offerId + "_type"), typeIn), DataEntry((offerId + "_firstParty"), toBase58String(i.caller.bytes))]) | |
42 | + | WriteSet([DataEntry(offerId, "op en"), DataEntry((offerId + "_tokenId"), tokenIn), DataEntry((offerId + "_amount"), amountIn), DataEntry((offerId + "_price"), priceIn), DataEntry((offerId + "_type"), typeIn), DataEntry((offerId + "_firstParty"), toBase58String(i.caller.bytes)), DataEntry((offerId + "_assetId"), assetIn)]) | |
42 | 43 | } | |
43 | 44 | else throw("Conditions not met") | |
44 | 45 | ||
48 | 49 | func acceptOffer (offerId) = { | |
49 | 50 | let offerType = getString(this, (offerId + "_type")) | |
50 | 51 | let offerStatus = getString(this, offerId) | |
52 | + | let assetId = getString(this, (offerId + "_assetId")) | |
51 | 53 | let offerAmount = getInteger(this, (offerId + "_amount")) | |
52 | 54 | if ((offerStatus == "open")) | |
53 | 55 | then if ((offerType == "buy")) | |
57 | 59 | let payment = extract(i.payment) | |
58 | 60 | if (((payment.amount / 100000000) != offerAmount)) | |
59 | 61 | then throw("Insufficient Payment Amount") | |
60 | - | else WriteSet([DataEntry(offerId, "accepted"), DataEntry((offerId + "_secondParty"), toBase58String(i.caller.bytes))]) | |
62 | + | else if ((payment.assetId != assetId)) | |
63 | + | then throw("AssetId invalid") | |
64 | + | else WriteSet([DataEntry(offerId, "accepted"), DataEntry((offerId + "_secondParty"), toBase58String(i.caller.bytes))]) | |
61 | 65 | } | |
62 | 66 | else if ((offerType == "sell")) | |
63 | 67 | then WriteSet([DataEntry(offerId, "accepted"), DataEntry((offerId + "_secondParty"), toBase58String(i.caller.bytes))]) | |
74 | 78 | let secondParty = getStringValue(this, (offerId + "_secondParty")) | |
75 | 79 | let offerType = getString(this, (offerId + "_type")) | |
76 | 80 | let amount = getIntegerValue(this, (offerId + "_amount")) | |
81 | + | let assetId = getStringValue(this, (offerId + "_assetId")) | |
77 | 82 | if ((offerStatus == "accepted")) | |
78 | 83 | then if ((firstParty != toBase58String(i.caller.bytes))) | |
79 | 84 | then throw("User not allowed to sign") | |
80 | 85 | else if ((offerType == "buy")) | |
81 | - | then ScriptResult(WriteSet([DataEntry(offerId, "closed")]), TransferSet([ScriptTransfer(i.caller, (amount * 100000000), | |
86 | + | then ScriptResult(WriteSet([DataEntry(offerId, "closed")]), TransferSet([ScriptTransfer(i.caller, (amount * 100000000), toBytes(assetId))])) | |
82 | 87 | else if ((offerType == "sell")) | |
83 | - | then ScriptResult(WriteSet([DataEntry(offerId, "closed")]), TransferSet([ScriptTransfer(addressFromStringValue(secondParty), (amount * 100000000), | |
88 | + | then ScriptResult(WriteSet([DataEntry(offerId, "closed")]), TransferSet([ScriptTransfer(addressFromStringValue(secondParty), (amount * 100000000), toBytes(assetId))])) | |
84 | 89 | else throw("Offer Type Error") | |
85 | 90 | else throw("Wrong offer status - forbidden") | |
86 | 91 | } | |
98 | 103 | ||
99 | 104 | @Verifier(tx) | |
100 | 105 | func verify () = match tx { | |
101 | - | case | |
106 | + | case _: SetScriptTransaction => | |
102 | 107 | sigVerify(tx.bodyBytes, tx.proofs[0], ownerPublicKey) | |
103 | - | case | |
108 | + | case _: InvokeScriptTransaction => | |
104 | 109 | sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
105 | 110 | case _ => | |
106 | 111 | false |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let ownerPublicKey = base58'CCEAkP4AnTM1HmKyRheQLmgNxPKACsL5hcH72JUeCiDJ' | |
5 | 5 | ||
6 | 6 | func randomizer (inv) = { | |
7 | 7 | let rand = ((((inv.transactionId + inv.callerPublicKey) + lastBlock.generationSignature) + toBytes(lastBlock.timestamp)) + toBytes(lastBlock.height)) | |
8 | 8 | sha256(rand) | |
9 | 9 | } | |
10 | 10 | ||
11 | 11 | ||
12 | - | func offerErrorHandler (token,amount,price,type,inv) = if (if (if (if (!(isDefined(token))) | |
12 | + | func offerErrorHandler (token,amount,price,type,asset,inv) = if (if (if (if (!(isDefined(token))) | |
13 | 13 | then true | |
14 | 14 | else !(isDefined(amount))) | |
15 | 15 | then true | |
16 | 16 | else !(isDefined(price))) | |
17 | 17 | then true | |
18 | 18 | else !(isDefined(type))) | |
19 | 19 | then throw("Invalid Transaction") | |
20 | 20 | else if (if ((type == "sell")) | |
21 | 21 | then !(isDefined(inv.payment)) | |
22 | 22 | else false) | |
23 | 23 | then throw("No payment attached") | |
24 | 24 | else if (if ((type == "sell")) | |
25 | 25 | then isDefined(inv.payment) | |
26 | 26 | else false) | |
27 | 27 | then { | |
28 | 28 | let payment = extract(inv.payment) | |
29 | 29 | if ((payment.amount != (amount * 100000000))) | |
30 | 30 | then throw("Payment amount insufficient") | |
31 | - | else true | |
31 | + | else if ((asset != token)) | |
32 | + | then throw("AssetId invalid") | |
33 | + | else true | |
32 | 34 | } | |
33 | 35 | else true | |
34 | 36 | ||
35 | 37 | ||
36 | 38 | @Callable(i) | |
37 | - | func postOffer (tokenIn,amountIn,priceIn,typeIn) = if (offerErrorHandler(tokenIn, amountIn, priceIn, typeIn, i)) | |
39 | + | func postOffer (tokenIn,amountIn,priceIn,typeIn,assetIn) = if (offerErrorHandler(tokenIn, amountIn, priceIn, typeIn, assetIn, i)) | |
38 | 40 | then { | |
39 | 41 | let offerId = toBase64String(randomizer(i)) | |
40 | - | let offerDetails = ((((((tokenIn + ",") + toString(amountIn)) + ",") + toString(priceIn)) + ",") + typeIn) | |
41 | - | WriteSet([DataEntry(offerId, "open"), DataEntry((offerId + "_tokenId"), tokenIn), DataEntry((offerId + "_amount"), amountIn), DataEntry((offerId + "_price"), priceIn), DataEntry((offerId + "_type"), typeIn), DataEntry((offerId + "_firstParty"), toBase58String(i.caller.bytes))]) | |
42 | + | WriteSet([DataEntry(offerId, "op en"), DataEntry((offerId + "_tokenId"), tokenIn), DataEntry((offerId + "_amount"), amountIn), DataEntry((offerId + "_price"), priceIn), DataEntry((offerId + "_type"), typeIn), DataEntry((offerId + "_firstParty"), toBase58String(i.caller.bytes)), DataEntry((offerId + "_assetId"), assetIn)]) | |
42 | 43 | } | |
43 | 44 | else throw("Conditions not met") | |
44 | 45 | ||
45 | 46 | ||
46 | 47 | ||
47 | 48 | @Callable(i) | |
48 | 49 | func acceptOffer (offerId) = { | |
49 | 50 | let offerType = getString(this, (offerId + "_type")) | |
50 | 51 | let offerStatus = getString(this, offerId) | |
52 | + | let assetId = getString(this, (offerId + "_assetId")) | |
51 | 53 | let offerAmount = getInteger(this, (offerId + "_amount")) | |
52 | 54 | if ((offerStatus == "open")) | |
53 | 55 | then if ((offerType == "buy")) | |
54 | 56 | then if (!(isDefined(i.payment))) | |
55 | 57 | then throw("Payment needed for buy offer") | |
56 | 58 | else { | |
57 | 59 | let payment = extract(i.payment) | |
58 | 60 | if (((payment.amount / 100000000) != offerAmount)) | |
59 | 61 | then throw("Insufficient Payment Amount") | |
60 | - | else WriteSet([DataEntry(offerId, "accepted"), DataEntry((offerId + "_secondParty"), toBase58String(i.caller.bytes))]) | |
62 | + | else if ((payment.assetId != assetId)) | |
63 | + | then throw("AssetId invalid") | |
64 | + | else WriteSet([DataEntry(offerId, "accepted"), DataEntry((offerId + "_secondParty"), toBase58String(i.caller.bytes))]) | |
61 | 65 | } | |
62 | 66 | else if ((offerType == "sell")) | |
63 | 67 | then WriteSet([DataEntry(offerId, "accepted"), DataEntry((offerId + "_secondParty"), toBase58String(i.caller.bytes))]) | |
64 | 68 | else throw("Offer Type Error") | |
65 | 69 | else throw("Wrong offer status - forbidden") | |
66 | 70 | } | |
67 | 71 | ||
68 | 72 | ||
69 | 73 | ||
70 | 74 | @Callable(i) | |
71 | 75 | func signOffer (offerId) = { | |
72 | 76 | let offerStatus = getString(this, offerId) | |
73 | 77 | let firstParty = getString(this, (offerId + "_firstParty")) | |
74 | 78 | let secondParty = getStringValue(this, (offerId + "_secondParty")) | |
75 | 79 | let offerType = getString(this, (offerId + "_type")) | |
76 | 80 | let amount = getIntegerValue(this, (offerId + "_amount")) | |
81 | + | let assetId = getStringValue(this, (offerId + "_assetId")) | |
77 | 82 | if ((offerStatus == "accepted")) | |
78 | 83 | then if ((firstParty != toBase58String(i.caller.bytes))) | |
79 | 84 | then throw("User not allowed to sign") | |
80 | 85 | else if ((offerType == "buy")) | |
81 | - | then ScriptResult(WriteSet([DataEntry(offerId, "closed")]), TransferSet([ScriptTransfer(i.caller, (amount * 100000000), | |
86 | + | then ScriptResult(WriteSet([DataEntry(offerId, "closed")]), TransferSet([ScriptTransfer(i.caller, (amount * 100000000), toBytes(assetId))])) | |
82 | 87 | else if ((offerType == "sell")) | |
83 | - | then ScriptResult(WriteSet([DataEntry(offerId, "closed")]), TransferSet([ScriptTransfer(addressFromStringValue(secondParty), (amount * 100000000), | |
88 | + | then ScriptResult(WriteSet([DataEntry(offerId, "closed")]), TransferSet([ScriptTransfer(addressFromStringValue(secondParty), (amount * 100000000), toBytes(assetId))])) | |
84 | 89 | else throw("Offer Type Error") | |
85 | 90 | else throw("Wrong offer status - forbidden") | |
86 | 91 | } | |
87 | 92 | ||
88 | 93 | ||
89 | 94 | ||
90 | 95 | @Callable(i) | |
91 | 96 | func deleteOffer (offerId) = { | |
92 | 97 | let firstParty = getString(this, (offerId + "_firstParty")) | |
93 | 98 | if ((firstParty != toBase58String(i.caller.bytes))) | |
94 | 99 | then throw("User not allowed to sign") | |
95 | 100 | else WriteSet([DataEntry(offerId, "deleted")]) | |
96 | 101 | } | |
97 | 102 | ||
98 | 103 | ||
99 | 104 | @Verifier(tx) | |
100 | 105 | func verify () = match tx { | |
101 | - | case | |
106 | + | case _: SetScriptTransaction => | |
102 | 107 | sigVerify(tx.bodyBytes, tx.proofs[0], ownerPublicKey) | |
103 | - | case | |
108 | + | case _: InvokeScriptTransaction => | |
104 | 109 | sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
105 | 110 | case _ => | |
106 | 111 | false | |
107 | 112 | } | |
108 | 113 |
github/deemru/w8io/169f3d6 63.34 ms ◑