tx · 8z6NkbTPoFneUcnqSVDz6MysQcsgbe8xeHw4VYaVWFBg 3MpFtcdhaB66NB38tW2APSiaVqaAoWoPvRJ: -0.04000000 Waves 2022.04.17 04:41 [2011895] smart account 3MpFtcdhaB66NB38tW2APSiaVqaAoWoPvRJ > SELF 0.00000000 Waves
{ "type": 13, "id": "8z6NkbTPoFneUcnqSVDz6MysQcsgbe8xeHw4VYaVWFBg", "fee": 4000000, "feeAssetId": null, "timestamp": 1650159755567, "version": 2, "chainId": 84, "sender": "3MpFtcdhaB66NB38tW2APSiaVqaAoWoPvRJ", "senderPublicKey": "2eixqLDKJ5kjuY8imH4HG2FBJduT6QsjxLLch1iaAadx", "proofs": [ "5KMmbix6rBpS6PtaWQQ5UDBsRJqpHGoH5z5rVvt3TSiGiRzMrTo7mCiSiaaHZctWPiSJTXm7thwi7bLd9Wpu1A74" ], "script": "base64:AAIFAAAAAAAAABQIAhIFCgMICAESAwoBCBIECgIICAAAAAcAAAAADmRBcHBBZGRyZXNzU3RyAgAAACMzTXZVeXpReE5HbXdFeEFjS2Rob2pmS2VtM1h3a1hka0J5SAAAAAANZEFwcFB1YmxpY0tleQEAAAAg31661xAC2/bUh55LBsmJKngfAJ6tUrEGMVqXTznC6TkAAAAAC2RBcHBBZGRyZXNzCQEAAAAUYWRkcmVzc0Zyb21QdWJsaWNLZXkAAAABBQAAAA1kQXBwUHVibGljS2V5AAAAABJob2xkaW5nc0FkZHJlc3NTdHICAAAAIzNNcEZ0Y2RoYUI2Nk5CMzh0VzJBUFNpYVZxYUFvV29QdlJKAAAAABFob2xkaW5nc1B1YmxpY0tleQEAAAAgGIWfydxTnVbMkjIZvMpVzQFjSrwZd/r8UUAY2zCNBBsAAAAAD2hvbGRpbmdzQWRkcmVzcwkBAAAAFGFkZHJlc3NGcm9tUHVibGljS2V5AAAAAQUAAAARaG9sZGluZ3NQdWJsaWNLZXkAAAAAD3RyYW5zZmVyQ29zdFBjdAAAAAAAAAAAMgAAAAMAAAABaQEAA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AZQAAAAIFAAAADXBheW1lbnRBbW91bnQFAAAAGGFtb3VudFRvUmVtYWluSW5Ib2xkaW5ncwQAAAAMb3duZXJBZGRyZXNzCQEAAAAHQWRkcmVzcwAAAAEJAAJZAAAAAQUAAAAHb3duZXJJZAkABE4AAAACBQAAAAh0cmFuc2ZlcgkABEwAAAACCQEAAAAOU2NyaXB0VHJhbnNmZXIAAAADBQAAAAxvd25lckFkZHJlc3MFAAAAF2Ftb3VudFRvVHJhbnNmZXJUb093bmVyBQAAAAR1bml0BQAAAANuaWwFAAAACHRyYW5zZmVyCQAAAgAAAAECAAAAJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgAAAAEAAAACdHgBAAAABnZlcmlmeQAAAAADAwkAAfQAAAADCAUAAAACdHgAAAAJYm9keUJ5dGVzCQABkQAAAAIIBQAAAAJ0eAAAAAZwcm9vZnMAAAAAAAAAAAAIBQAAAAJ0eAAAAA9zZW5kZXJQdWJsaWNLZXkGCQAAAAAAAAIJAQAAABRhZGRyZXNzRnJvbVB1YmxpY0tleQAAAAEIBQAAAAJ0eAAAAA9zZW5kZXJQdWJsaWNLZXkFAAAAD2hvbGRpbmdzQWRkcmVzcwYJAAAAAAAAAgkBAAAAFGFkZHJlc3NGcm9tUHVibGljS2V5AAAAAQgFAAAAAnR4AAAAD3NlbmRlclB1YmxpY0tleQUAAAALZEFwcEFkZHJlc3PbykJf", "height": 2011895, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 9NV5EcyrcG5eHBwkKNwK8eGPA6r6GEpVAAwXVfUkVejz Next: none Diff:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let | |
4 | + | let dAppAddressStr = "3MvUyzQxNGmwExAcKdhojfKem3XwkXdkByH" | |
5 | 5 | ||
6 | - | let | |
6 | + | let dAppPublicKey = base58'G2whNsDNG7LDDcHiMuFrtDiNuudzqif5tAopWE1Y7oAQ' | |
7 | 7 | ||
8 | - | let | |
8 | + | let dAppAddress = addressFromPublicKey(dAppPublicKey) | |
9 | 9 | ||
10 | - | let | |
10 | + | let holdingsAddressStr = "3MpFtcdhaB66NB38tW2APSiaVqaAoWoPvRJ" | |
11 | 11 | ||
12 | - | let | |
12 | + | let holdingsPublicKey = base58'2eixqLDKJ5kjuY8imH4HG2FBJduT6QsjxLLch1iaAadx' | |
13 | 13 | ||
14 | - | let | |
14 | + | let holdingsAddress = addressFromPublicKey(holdingsPublicKey) | |
15 | 15 | ||
16 | - | let | |
16 | + | let transferCostPct = 50 | |
17 | 17 | ||
18 | - | let dapp = "3MvUyzQxNGmwExAcKdhojfKem3XwkXdkByH" | |
18 | + | @Callable(i) | |
19 | + | func addOwnerAndAmount (ownerId,assetId,amount) = [StringEntry((("sale_" + assetId) + "_originalOwner"), ownerId), IntegerEntry((("sale_" + assetId) + "_amount"), amount)] | |
19 | 20 | ||
20 | - | let dappAddress = Address(fromBase58String(dapp)) | |
21 | - | ||
22 | - | let holdingsPublicKey = "2eixqLDKJ5kjuY8imH4HG2FBJduT6QsjxLLch1iaAadx" | |
23 | - | ||
24 | - | let holdings = "3MpFtcdhaB66NB38tW2APSiaVqaAoWoPvRJ" | |
25 | - | ||
26 | - | let holdingsAddress = Address(fromBase58String(holdings)) | |
27 | - | ||
28 | - | func getAssetName (x,y) = { | |
29 | - | let name = ((x + ",") + y) | |
30 | - | name | |
31 | - | } | |
32 | - | ||
33 | - | ||
34 | - | func getDataKeyPrefix (x,y,gen) = { | |
35 | - | let name = getAssetName(x, y) | |
36 | - | let prefix = ((name + ",") + gen) | |
37 | - | prefix | |
38 | - | } | |
39 | - | ||
40 | - | ||
41 | - | func getXYGenFromName (name) = { | |
42 | - | let parts = split(name, ",") | |
43 | - | let tuple = $Tuple3(parts[0], parts[1], parts[2]) | |
44 | - | tuple | |
45 | - | } | |
46 | - | ||
47 | - | ||
48 | - | func getDataKeyPrefixFromAssetName (name) = { | |
49 | - | let $t010011041 = getXYGenFromName(name) | |
50 | - | let x = $t010011041._1 | |
51 | - | let y = $t010011041._2 | |
52 | - | let gen = $t010011041._3 | |
53 | - | let prefix = getDataKeyPrefix(x, y, gen) | |
54 | - | prefix | |
55 | - | } | |
56 | - | ||
57 | - | ||
58 | - | func claimSquare (x,y,gen,ownerId,transactionId) = { | |
59 | - | let resolvedXStr = x | |
60 | - | let resolvedYStr = y | |
61 | - | let resolvedGenStr = gen | |
62 | - | let assetName = getAssetName(resolvedXStr, resolvedYStr) | |
63 | - | let assetUrl = ((nftDomain + transactionId) + ".png") | |
64 | - | let asset = Issue(((assetName + ",") + resolvedGenStr), assetUrl, 1, 0, false) | |
65 | - | let assetId = calculateAssetId(asset) | |
66 | - | let dataKeyPrefix = getDataKeyPrefix(resolvedXStr, resolvedYStr, gen) | |
67 | - | $Tuple4(asset, assetId, assetUrl, dataKeyPrefix) | |
68 | - | } | |
69 | 21 | ||
70 | 22 | ||
71 | 23 | @Callable(i) | |
72 | - | func purchase (x,y,userText) = { | |
73 | - | let prefix = getDataKeyPrefix(x, y, "1") | |
74 | - | let paymentAmount = valueOrElse(i.payments[0].amount, 0) | |
75 | - | let existingAssetId = match getString(this, (prefix + "_assetId")) { | |
24 | + | func revokeForSale (assetId) = { | |
25 | + | let callerId = toBase58String(i.caller.bytes) | |
26 | + | let ownerId = match getString(this, (("sale_" + assetId) + "_originalOwner")) { | |
76 | 27 | case _: Unit => | |
77 | 28 | "unset" | |
78 | - | case | |
79 | - | | |
29 | + | case x: String => | |
30 | + | x | |
80 | 31 | case _ => | |
81 | 32 | throw("Match error") | |
82 | 33 | } | |
83 | - | if ((minPurchasePrice > paymentAmount)) | |
84 | - | then throw((("You need to send at least " + toString(minPurchasePrice)) + "WAVLETS to purchase a square")) | |
85 | - | else { | |
86 | - | let ownerId = toBase58String(i.caller.bytes) | |
87 | - | let transactionId = toBase58String(i.transactionId) | |
88 | - | let $t022332328 = claimSquare(x, y, "1", ownerId, transactionId) | |
89 | - | let asset = $t022332328._1 | |
90 | - | let assetId = $t022332328._2 | |
91 | - | let assetUrl = $t022332328._3 | |
92 | - | let dataKeyPrefix = $t022332328._4 | |
93 | - | [asset, StringEntry((dataKeyPrefix + "_assetId"), toBase58String(assetId)), StringEntry((dataKeyPrefix + "_asset"), assetUrl), StringEntry((dataKeyPrefix + "_owner"), ownerId), StringEntry((ownerId + "_handle"), userText), StringEntry(transactionId, dataKeyPrefix), ScriptTransfer(i.caller, 1, assetId)] | |
94 | - | } | |
34 | + | if ((callerId != ownerId)) | |
35 | + | then throw("Owners do not match") | |
36 | + | else [StringEntry((("sale_" + assetId) + "_originalOwner"), ""), IntegerEntry((("sale_" + assetId) + "_amount"), 0), ScriptTransfer(i.caller, 1, fromBase58String(assetId))] | |
95 | 37 | } | |
96 | 38 | ||
97 | 39 | ||
98 | 40 | ||
99 | 41 | @Callable(i) | |
100 | - | func autoBuy (x,y) = { | |
101 | - | let callerId = toBase58String(i.caller.bytes) | |
102 | - | if (if ((callerId != holdings)) | |
103 | - | then (callerId != dapp) | |
104 | - | else false) | |
105 | - | then throw("This can only be triggering internally") | |
106 | - | else { | |
107 | - | let transactionId = toBase58String(i.transactionId) | |
108 | - | let $t029553051 = claimSquare(x, y, "1", holdings, transactionId) | |
109 | - | let asset = $t029553051._1 | |
110 | - | let assetId = $t029553051._2 | |
111 | - | let assetUrl = $t029553051._3 | |
112 | - | let dataKeyPrefix = $t029553051._4 | |
113 | - | let assetIdStr = toBase58String(assetId) | |
114 | - | let res = invoke(holdingsAddress, addOwnerAndAmountFunc, [holdings, assetIdStr, 3], [AttachedPayment(unit, 0)]) | |
115 | - | if ((res == res)) | |
116 | - | then [asset, StringEntry((dataKeyPrefix + "_assetId"), assetIdStr), StringEntry((dataKeyPrefix + "_asset"), assetUrl), StringEntry((dataKeyPrefix + "_owner"), holdings), StringEntry(transactionId, dataKeyPrefix), ScriptTransfer(holdingsAddress, 1, assetId)] | |
117 | - | else throw("Strict value is not equal to itself.") | |
118 | - | } | |
42 | + | func buyFromHoldings (assetId,userText) = { | |
43 | + | let ownerId = match getString(this, (("sale_" + assetId) + "_originalOwner")) { | |
44 | + | case _: Unit => | |
45 | + | "unset" | |
46 | + | case x: String => | |
47 | + | x | |
48 | + | case _ => | |
49 | + | throw("Match error") | |
119 | 50 | } | |
120 | - | ||
121 | - | ||
122 | - | ||
123 | - | @Callable(i) | |
124 | - | func promotionPurchase (x,y,desinationAddress) = { | |
125 | - | let callerId = toBase58String(i.caller.bytes) | |
126 | - | if ((callerId != holdings)) | |
127 | - | then throw("This can only be triggering internally") | |
128 | - | else { | |
129 | - | let transactionId = toBase58String(i.transactionId) | |
130 | - | let $t038073912 = claimSquare(x, y, "1", desinationAddress, transactionId) | |
131 | - | let asset = $t038073912._1 | |
132 | - | let assetId = $t038073912._2 | |
133 | - | let assetUrl = $t038073912._3 | |
134 | - | let dataKeyPrefix = $t038073912._4 | |
135 | - | let assetIdStr = toBase58String(assetId) | |
136 | - | [asset, StringEntry((dataKeyPrefix + "_assetId"), assetIdStr), StringEntry((dataKeyPrefix + "_asset"), assetUrl), StringEntry((dataKeyPrefix + "_owner"), desinationAddress), StringEntry(transactionId, dataKeyPrefix), ScriptTransfer(Address(fromBase58String(desinationAddress)), 1, assetId)] | |
137 | - | } | |
51 | + | let paymentAmount = valueOrElse(i.payments[0].amount, 0) | |
52 | + | let amount = match getInteger(this, (("sale_" + assetId) + "_amount")) { | |
53 | + | case _: Unit => | |
54 | + | 0 | |
55 | + | case x: Int => | |
56 | + | x | |
57 | + | case _ => | |
58 | + | throw("Match error") | |
138 | 59 | } | |
139 | - | ||
140 | - | ||
141 | - | ||
142 | - | @Callable(i) | |
143 | - | func evolve (x,y,gen,ownerId) = { | |
144 | - | let callerId = toBase58String(i.caller.bytes) | |
145 | - | if ((callerId != holdings)) | |
146 | - | then throw("This can only be triggering internally") | |
147 | - | else { | |
148 | - | let transactionId = toBase58String(i.transactionId) | |
149 | - | let $t046384733 = claimSquare(x, y, gen, ownerId, transactionId) | |
150 | - | let asset = $t046384733._1 | |
151 | - | let assetId = $t046384733._2 | |
152 | - | let assetUrl = $t046384733._3 | |
153 | - | let dataKeyPrefix = $t046384733._4 | |
154 | - | [asset, StringEntry((dataKeyPrefix + "_assetId"), toBase58String(assetId)), StringEntry((dataKeyPrefix + "_asset"), assetUrl), StringEntry((dataKeyPrefix + "_owner"), ownerId), StringEntry(transactionId, dataKeyPrefix), ScriptTransfer(Address(fromBase58String(ownerId)), 1, assetId)] | |
155 | - | } | |
156 | - | } | |
157 | - | ||
158 | - | ||
159 | - | ||
160 | - | @Callable(i) | |
161 | - | func putForSale (assetId,amount) = { | |
162 | - | let callerId = toBase58String(i.caller.bytes) | |
163 | - | let assetData = match assetInfo(fromBase58String(assetId)) { | |
164 | - | case ass: Asset => | |
165 | - | ass | |
166 | - | case _ => | |
167 | - | throw("Asset not found") | |
168 | - | } | |
169 | - | let dataPrefix = getDataKeyPrefixFromAssetName(assetData.name) | |
170 | - | let ownerId = match getString(this, (dataPrefix + "_owner")) { | |
171 | - | case s: String => | |
172 | - | s | |
173 | - | case _ => | |
174 | - | throw("Owner not found in data") | |
175 | - | } | |
176 | - | if ((minForSaleWavlets > amount)) | |
177 | - | then throw("Amount needs to be more than 1 wave") | |
178 | - | else if (if ((callerId != ownerId)) | |
179 | - | then (callerId != holdings) | |
180 | - | else false) | |
181 | - | then throw("You are not able to put this asset up for sale") | |
60 | + | if (if ((ownerId == "unset")) | |
61 | + | then true | |
62 | + | else (ownerId == "")) | |
63 | + | then throw("Original owner not found ") | |
64 | + | else if (if ((amount == 0)) | |
65 | + | then true | |
66 | + | else (amount > paymentAmount)) | |
67 | + | then throw(((("Payment and amount do not match. This assets costs " + toString(amount)) + "but you sent ") + toString(paymentAmount))) | |
182 | 68 | else { | |
183 | - | let res = invoke(holdingsAddress, addOwnerAndAmountFunc, [callerId, assetId, amount], [AttachedPayment(unit, 0)]) | |
69 | + | let callerId = toBase58String(i.caller.bytes) | |
70 | + | let res = invoke(dAppAddress, "finalizeSale", [assetId, callerId, userText], [AttachedPayment(unit, 0)]) | |
184 | 71 | if ((res == res)) | |
185 | - | then [ScriptTransfer(holdingsAddress, 1, fromBase58String(assetId))] | |
72 | + | then { | |
73 | + | let transfer = [ScriptTransfer(i.caller, 1, fromBase58String(assetId)), StringEntry((("sale_" + assetId) + "_originalOwner"), ""), IntegerEntry((("sale_" + assetId) + "_amount"), 0)] | |
74 | + | if ((ownerId != holdingsAddressStr)) | |
75 | + | then { | |
76 | + | let amountToRemainInHoldings = (paymentAmount / transferCostPct) | |
77 | + | let amountToTransferToOwner = (paymentAmount - amountToRemainInHoldings) | |
78 | + | let ownerAddress = Address(fromBase58String(ownerId)) | |
79 | + | (transfer ++ [ScriptTransfer(ownerAddress, amountToTransferToOwner, unit)]) | |
80 | + | } | |
81 | + | else transfer | |
82 | + | } | |
186 | 83 | else throw("Strict value is not equal to itself.") | |
187 | 84 | } | |
188 | - | } | |
189 | - | ||
190 | - | ||
191 | - | ||
192 | - | @Callable(i) | |
193 | - | func finalizeSale (assetId,ownerId,userText) = { | |
194 | - | let callerId = toBase58String(i.caller.bytes) | |
195 | - | if ((callerId != holdings)) | |
196 | - | then throw("This can only be triggering internally") | |
197 | - | else { | |
198 | - | let prefix = match assetInfo(fromBase58String(assetId)) { | |
199 | - | case asset: Asset => | |
200 | - | asset.name | |
201 | - | case _ => | |
202 | - | throw("Can't find asset") | |
203 | - | } | |
204 | - | [StringEntry((prefix + "_owner"), ownerId), StringEntry((ownerId + "_handle"), userText)] | |
205 | - | } | |
206 | 85 | } | |
207 | 86 | ||
208 | 87 | ||
211 | 90 | then true | |
212 | 91 | else (addressFromPublicKey(tx.senderPublicKey) == holdingsAddress)) | |
213 | 92 | then true | |
214 | - | else (addressFromPublicKey(tx.senderPublicKey) == | |
93 | + | else (addressFromPublicKey(tx.senderPublicKey) == dAppAddress) | |
215 | 94 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let | |
4 | + | let dAppAddressStr = "3MvUyzQxNGmwExAcKdhojfKem3XwkXdkByH" | |
5 | 5 | ||
6 | - | let | |
6 | + | let dAppPublicKey = base58'G2whNsDNG7LDDcHiMuFrtDiNuudzqif5tAopWE1Y7oAQ' | |
7 | 7 | ||
8 | - | let | |
8 | + | let dAppAddress = addressFromPublicKey(dAppPublicKey) | |
9 | 9 | ||
10 | - | let | |
10 | + | let holdingsAddressStr = "3MpFtcdhaB66NB38tW2APSiaVqaAoWoPvRJ" | |
11 | 11 | ||
12 | - | let | |
12 | + | let holdingsPublicKey = base58'2eixqLDKJ5kjuY8imH4HG2FBJduT6QsjxLLch1iaAadx' | |
13 | 13 | ||
14 | - | let | |
14 | + | let holdingsAddress = addressFromPublicKey(holdingsPublicKey) | |
15 | 15 | ||
16 | - | let | |
16 | + | let transferCostPct = 50 | |
17 | 17 | ||
18 | - | let dapp = "3MvUyzQxNGmwExAcKdhojfKem3XwkXdkByH" | |
18 | + | @Callable(i) | |
19 | + | func addOwnerAndAmount (ownerId,assetId,amount) = [StringEntry((("sale_" + assetId) + "_originalOwner"), ownerId), IntegerEntry((("sale_" + assetId) + "_amount"), amount)] | |
19 | 20 | ||
20 | - | let dappAddress = Address(fromBase58String(dapp)) | |
21 | - | ||
22 | - | let holdingsPublicKey = "2eixqLDKJ5kjuY8imH4HG2FBJduT6QsjxLLch1iaAadx" | |
23 | - | ||
24 | - | let holdings = "3MpFtcdhaB66NB38tW2APSiaVqaAoWoPvRJ" | |
25 | - | ||
26 | - | let holdingsAddress = Address(fromBase58String(holdings)) | |
27 | - | ||
28 | - | func getAssetName (x,y) = { | |
29 | - | let name = ((x + ",") + y) | |
30 | - | name | |
31 | - | } | |
32 | - | ||
33 | - | ||
34 | - | func getDataKeyPrefix (x,y,gen) = { | |
35 | - | let name = getAssetName(x, y) | |
36 | - | let prefix = ((name + ",") + gen) | |
37 | - | prefix | |
38 | - | } | |
39 | - | ||
40 | - | ||
41 | - | func getXYGenFromName (name) = { | |
42 | - | let parts = split(name, ",") | |
43 | - | let tuple = $Tuple3(parts[0], parts[1], parts[2]) | |
44 | - | tuple | |
45 | - | } | |
46 | - | ||
47 | - | ||
48 | - | func getDataKeyPrefixFromAssetName (name) = { | |
49 | - | let $t010011041 = getXYGenFromName(name) | |
50 | - | let x = $t010011041._1 | |
51 | - | let y = $t010011041._2 | |
52 | - | let gen = $t010011041._3 | |
53 | - | let prefix = getDataKeyPrefix(x, y, gen) | |
54 | - | prefix | |
55 | - | } | |
56 | - | ||
57 | - | ||
58 | - | func claimSquare (x,y,gen,ownerId,transactionId) = { | |
59 | - | let resolvedXStr = x | |
60 | - | let resolvedYStr = y | |
61 | - | let resolvedGenStr = gen | |
62 | - | let assetName = getAssetName(resolvedXStr, resolvedYStr) | |
63 | - | let assetUrl = ((nftDomain + transactionId) + ".png") | |
64 | - | let asset = Issue(((assetName + ",") + resolvedGenStr), assetUrl, 1, 0, false) | |
65 | - | let assetId = calculateAssetId(asset) | |
66 | - | let dataKeyPrefix = getDataKeyPrefix(resolvedXStr, resolvedYStr, gen) | |
67 | - | $Tuple4(asset, assetId, assetUrl, dataKeyPrefix) | |
68 | - | } | |
69 | 21 | ||
70 | 22 | ||
71 | 23 | @Callable(i) | |
72 | - | func purchase (x,y,userText) = { | |
73 | - | let prefix = getDataKeyPrefix(x, y, "1") | |
74 | - | let paymentAmount = valueOrElse(i.payments[0].amount, 0) | |
75 | - | let existingAssetId = match getString(this, (prefix + "_assetId")) { | |
24 | + | func revokeForSale (assetId) = { | |
25 | + | let callerId = toBase58String(i.caller.bytes) | |
26 | + | let ownerId = match getString(this, (("sale_" + assetId) + "_originalOwner")) { | |
76 | 27 | case _: Unit => | |
77 | 28 | "unset" | |
78 | - | case | |
79 | - | | |
29 | + | case x: String => | |
30 | + | x | |
80 | 31 | case _ => | |
81 | 32 | throw("Match error") | |
82 | 33 | } | |
83 | - | if ((minPurchasePrice > paymentAmount)) | |
84 | - | then throw((("You need to send at least " + toString(minPurchasePrice)) + "WAVLETS to purchase a square")) | |
85 | - | else { | |
86 | - | let ownerId = toBase58String(i.caller.bytes) | |
87 | - | let transactionId = toBase58String(i.transactionId) | |
88 | - | let $t022332328 = claimSquare(x, y, "1", ownerId, transactionId) | |
89 | - | let asset = $t022332328._1 | |
90 | - | let assetId = $t022332328._2 | |
91 | - | let assetUrl = $t022332328._3 | |
92 | - | let dataKeyPrefix = $t022332328._4 | |
93 | - | [asset, StringEntry((dataKeyPrefix + "_assetId"), toBase58String(assetId)), StringEntry((dataKeyPrefix + "_asset"), assetUrl), StringEntry((dataKeyPrefix + "_owner"), ownerId), StringEntry((ownerId + "_handle"), userText), StringEntry(transactionId, dataKeyPrefix), ScriptTransfer(i.caller, 1, assetId)] | |
94 | - | } | |
34 | + | if ((callerId != ownerId)) | |
35 | + | then throw("Owners do not match") | |
36 | + | else [StringEntry((("sale_" + assetId) + "_originalOwner"), ""), IntegerEntry((("sale_" + assetId) + "_amount"), 0), ScriptTransfer(i.caller, 1, fromBase58String(assetId))] | |
95 | 37 | } | |
96 | 38 | ||
97 | 39 | ||
98 | 40 | ||
99 | 41 | @Callable(i) | |
100 | - | func autoBuy (x,y) = { | |
101 | - | let callerId = toBase58String(i.caller.bytes) | |
102 | - | if (if ((callerId != holdings)) | |
103 | - | then (callerId != dapp) | |
104 | - | else false) | |
105 | - | then throw("This can only be triggering internally") | |
106 | - | else { | |
107 | - | let transactionId = toBase58String(i.transactionId) | |
108 | - | let $t029553051 = claimSquare(x, y, "1", holdings, transactionId) | |
109 | - | let asset = $t029553051._1 | |
110 | - | let assetId = $t029553051._2 | |
111 | - | let assetUrl = $t029553051._3 | |
112 | - | let dataKeyPrefix = $t029553051._4 | |
113 | - | let assetIdStr = toBase58String(assetId) | |
114 | - | let res = invoke(holdingsAddress, addOwnerAndAmountFunc, [holdings, assetIdStr, 3], [AttachedPayment(unit, 0)]) | |
115 | - | if ((res == res)) | |
116 | - | then [asset, StringEntry((dataKeyPrefix + "_assetId"), assetIdStr), StringEntry((dataKeyPrefix + "_asset"), assetUrl), StringEntry((dataKeyPrefix + "_owner"), holdings), StringEntry(transactionId, dataKeyPrefix), ScriptTransfer(holdingsAddress, 1, assetId)] | |
117 | - | else throw("Strict value is not equal to itself.") | |
118 | - | } | |
42 | + | func buyFromHoldings (assetId,userText) = { | |
43 | + | let ownerId = match getString(this, (("sale_" + assetId) + "_originalOwner")) { | |
44 | + | case _: Unit => | |
45 | + | "unset" | |
46 | + | case x: String => | |
47 | + | x | |
48 | + | case _ => | |
49 | + | throw("Match error") | |
119 | 50 | } | |
120 | - | ||
121 | - | ||
122 | - | ||
123 | - | @Callable(i) | |
124 | - | func promotionPurchase (x,y,desinationAddress) = { | |
125 | - | let callerId = toBase58String(i.caller.bytes) | |
126 | - | if ((callerId != holdings)) | |
127 | - | then throw("This can only be triggering internally") | |
128 | - | else { | |
129 | - | let transactionId = toBase58String(i.transactionId) | |
130 | - | let $t038073912 = claimSquare(x, y, "1", desinationAddress, transactionId) | |
131 | - | let asset = $t038073912._1 | |
132 | - | let assetId = $t038073912._2 | |
133 | - | let assetUrl = $t038073912._3 | |
134 | - | let dataKeyPrefix = $t038073912._4 | |
135 | - | let assetIdStr = toBase58String(assetId) | |
136 | - | [asset, StringEntry((dataKeyPrefix + "_assetId"), assetIdStr), StringEntry((dataKeyPrefix + "_asset"), assetUrl), StringEntry((dataKeyPrefix + "_owner"), desinationAddress), StringEntry(transactionId, dataKeyPrefix), ScriptTransfer(Address(fromBase58String(desinationAddress)), 1, assetId)] | |
137 | - | } | |
51 | + | let paymentAmount = valueOrElse(i.payments[0].amount, 0) | |
52 | + | let amount = match getInteger(this, (("sale_" + assetId) + "_amount")) { | |
53 | + | case _: Unit => | |
54 | + | 0 | |
55 | + | case x: Int => | |
56 | + | x | |
57 | + | case _ => | |
58 | + | throw("Match error") | |
138 | 59 | } | |
139 | - | ||
140 | - | ||
141 | - | ||
142 | - | @Callable(i) | |
143 | - | func evolve (x,y,gen,ownerId) = { | |
144 | - | let callerId = toBase58String(i.caller.bytes) | |
145 | - | if ((callerId != holdings)) | |
146 | - | then throw("This can only be triggering internally") | |
147 | - | else { | |
148 | - | let transactionId = toBase58String(i.transactionId) | |
149 | - | let $t046384733 = claimSquare(x, y, gen, ownerId, transactionId) | |
150 | - | let asset = $t046384733._1 | |
151 | - | let assetId = $t046384733._2 | |
152 | - | let assetUrl = $t046384733._3 | |
153 | - | let dataKeyPrefix = $t046384733._4 | |
154 | - | [asset, StringEntry((dataKeyPrefix + "_assetId"), toBase58String(assetId)), StringEntry((dataKeyPrefix + "_asset"), assetUrl), StringEntry((dataKeyPrefix + "_owner"), ownerId), StringEntry(transactionId, dataKeyPrefix), ScriptTransfer(Address(fromBase58String(ownerId)), 1, assetId)] | |
155 | - | } | |
156 | - | } | |
157 | - | ||
158 | - | ||
159 | - | ||
160 | - | @Callable(i) | |
161 | - | func putForSale (assetId,amount) = { | |
162 | - | let callerId = toBase58String(i.caller.bytes) | |
163 | - | let assetData = match assetInfo(fromBase58String(assetId)) { | |
164 | - | case ass: Asset => | |
165 | - | ass | |
166 | - | case _ => | |
167 | - | throw("Asset not found") | |
168 | - | } | |
169 | - | let dataPrefix = getDataKeyPrefixFromAssetName(assetData.name) | |
170 | - | let ownerId = match getString(this, (dataPrefix + "_owner")) { | |
171 | - | case s: String => | |
172 | - | s | |
173 | - | case _ => | |
174 | - | throw("Owner not found in data") | |
175 | - | } | |
176 | - | if ((minForSaleWavlets > amount)) | |
177 | - | then throw("Amount needs to be more than 1 wave") | |
178 | - | else if (if ((callerId != ownerId)) | |
179 | - | then (callerId != holdings) | |
180 | - | else false) | |
181 | - | then throw("You are not able to put this asset up for sale") | |
60 | + | if (if ((ownerId == "unset")) | |
61 | + | then true | |
62 | + | else (ownerId == "")) | |
63 | + | then throw("Original owner not found ") | |
64 | + | else if (if ((amount == 0)) | |
65 | + | then true | |
66 | + | else (amount > paymentAmount)) | |
67 | + | then throw(((("Payment and amount do not match. This assets costs " + toString(amount)) + "but you sent ") + toString(paymentAmount))) | |
182 | 68 | else { | |
183 | - | let res = invoke(holdingsAddress, addOwnerAndAmountFunc, [callerId, assetId, amount], [AttachedPayment(unit, 0)]) | |
69 | + | let callerId = toBase58String(i.caller.bytes) | |
70 | + | let res = invoke(dAppAddress, "finalizeSale", [assetId, callerId, userText], [AttachedPayment(unit, 0)]) | |
184 | 71 | if ((res == res)) | |
185 | - | then [ScriptTransfer(holdingsAddress, 1, fromBase58String(assetId))] | |
72 | + | then { | |
73 | + | let transfer = [ScriptTransfer(i.caller, 1, fromBase58String(assetId)), StringEntry((("sale_" + assetId) + "_originalOwner"), ""), IntegerEntry((("sale_" + assetId) + "_amount"), 0)] | |
74 | + | if ((ownerId != holdingsAddressStr)) | |
75 | + | then { | |
76 | + | let amountToRemainInHoldings = (paymentAmount / transferCostPct) | |
77 | + | let amountToTransferToOwner = (paymentAmount - amountToRemainInHoldings) | |
78 | + | let ownerAddress = Address(fromBase58String(ownerId)) | |
79 | + | (transfer ++ [ScriptTransfer(ownerAddress, amountToTransferToOwner, unit)]) | |
80 | + | } | |
81 | + | else transfer | |
82 | + | } | |
186 | 83 | else throw("Strict value is not equal to itself.") | |
187 | 84 | } | |
188 | - | } | |
189 | - | ||
190 | - | ||
191 | - | ||
192 | - | @Callable(i) | |
193 | - | func finalizeSale (assetId,ownerId,userText) = { | |
194 | - | let callerId = toBase58String(i.caller.bytes) | |
195 | - | if ((callerId != holdings)) | |
196 | - | then throw("This can only be triggering internally") | |
197 | - | else { | |
198 | - | let prefix = match assetInfo(fromBase58String(assetId)) { | |
199 | - | case asset: Asset => | |
200 | - | asset.name | |
201 | - | case _ => | |
202 | - | throw("Can't find asset") | |
203 | - | } | |
204 | - | [StringEntry((prefix + "_owner"), ownerId), StringEntry((ownerId + "_handle"), userText)] | |
205 | - | } | |
206 | 85 | } | |
207 | 86 | ||
208 | 87 | ||
209 | 88 | @Verifier(tx) | |
210 | 89 | func verify () = if (if (sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)) | |
211 | 90 | then true | |
212 | 91 | else (addressFromPublicKey(tx.senderPublicKey) == holdingsAddress)) | |
213 | 92 | then true | |
214 | - | else (addressFromPublicKey(tx.senderPublicKey) == | |
93 | + | else (addressFromPublicKey(tx.senderPublicKey) == dAppAddress) | |
215 | 94 |
github/deemru/w8io/169f3d6 39.67 ms ◑