42 | | - | func hasSeparatorInString (foundSeparator,stringToCheck) = if ((foundSeparator == true)) |
---|
43 | | - | then true |
---|
44 | | - | else contains(stringToCheck, separator) |
---|
45 | | - | |
---|
46 | | - | |
---|
47 | | - | @Callable(i) |
---|
48 | | - | func deposit () = if ((genesisHeight > height)) |
---|
49 | | - | then throw("Waiting for genesis height") |
---|
50 | | - | else if ((this == i.caller)) |
---|
51 | | - | then throw("Self call is forbidden") |
---|
52 | | - | else if (if (if ((size(i.payments) != 1)) |
---|
53 | | - | then true |
---|
54 | | - | else (1 > i.payments[0].amount)) |
---|
55 | | - | then true |
---|
56 | | - | else (i.payments[0].amount > maxInt)) |
---|
57 | | - | then throw("Attached payment issue") |
---|
58 | | - | else { |
---|
59 | | - | let contractAssetId = match i.payments[0].assetId { |
---|
60 | | - | case isByteVector: ByteVector => |
---|
61 | | - | toBase58String(valueOrErrorMessage(assetInfo(isByteVector), "Unknown asset").id) |
---|
62 | | - | case isWaves: Unit => |
---|
63 | | - | wavesId |
---|
64 | | - | case _ => |
---|
65 | | - | throw("Wrong asset type") |
---|
66 | | - | } |
---|
67 | | - | let contractFields = [contractTag, toString(height), toString(i.caller), contractAssetId, toString(i.payments[0].amount)] |
---|
68 | | - | if (({ |
---|
69 | | - | let $list33533405 = contractFields |
---|
70 | | - | let $size33533405 = size($list33533405) |
---|
71 | | - | let $acc033533405 = false |
---|
72 | | - | if (($size33533405 == 0)) |
---|
73 | | - | then $acc033533405 |
---|
74 | | - | else { |
---|
75 | | - | let $acc133533405 = hasSeparatorInString($acc033533405, $list33533405[0]) |
---|
76 | | - | if (($size33533405 == 1)) |
---|
77 | | - | then $acc133533405 |
---|
78 | | - | else { |
---|
79 | | - | let $acc233533405 = hasSeparatorInString($acc133533405, $list33533405[1]) |
---|
80 | | - | if (($size33533405 == 2)) |
---|
81 | | - | then $acc233533405 |
---|
82 | | - | else { |
---|
83 | | - | let $acc333533405 = hasSeparatorInString($acc233533405, $list33533405[2]) |
---|
84 | | - | if (($size33533405 == 3)) |
---|
85 | | - | then $acc333533405 |
---|
86 | | - | else { |
---|
87 | | - | let $acc433533405 = hasSeparatorInString($acc333533405, $list33533405[3]) |
---|
88 | | - | if (($size33533405 == 4)) |
---|
89 | | - | then $acc433533405 |
---|
90 | | - | else { |
---|
91 | | - | let $acc533533405 = hasSeparatorInString($acc433533405, $list33533405[4]) |
---|
92 | | - | if (($size33533405 == 5)) |
---|
93 | | - | then $acc533533405 |
---|
94 | | - | else { |
---|
95 | | - | let $acc633533405 = hasSeparatorInString($acc533533405, $list33533405[5]) |
---|
96 | | - | throw("List size exceed 5") |
---|
97 | | - | } |
---|
98 | | - | } |
---|
99 | | - | } |
---|
100 | | - | } |
---|
101 | | - | } |
---|
102 | | - | } |
---|
103 | | - | } == true)) |
---|
104 | | - | then throw("Separator found in fields") |
---|
105 | | - | else { |
---|
106 | | - | let contractDescription = makeString(contractFields, separator) |
---|
107 | | - | if ((size(toBytes(contractDescription)) > maxDescriptionBytes)) |
---|
108 | | - | then throw("Too long contract") |
---|
109 | | - | else { |
---|
110 | | - | let nonce = generateNonce() |
---|
111 | | - | let actionIssue = Issue(contractName, contractDescription, 1, 0, false, unit, nonce) |
---|
112 | | - | let actionTransfer = ScriptTransfer(i.caller, actionIssue.quantity, calculateAssetId(actionIssue)) |
---|
113 | | - | [IntegerEntry(keyNonceCount, nonce), actionIssue, actionTransfer] |
---|
114 | | - | } |
---|
115 | | - | } |
---|
116 | | - | } |
---|
117 | | - | |
---|
118 | | - | |
---|
119 | | - | |
---|
120 | | - | @Callable(i) |
---|
121 | | - | func withdraw () = if ((this == i.caller)) |
---|
122 | | - | then throw("Self call is forbidden") |
---|
123 | | - | else if (if ((size(i.payments) != 1)) |
---|
124 | | - | then true |
---|
125 | | - | else (i.payments[0].amount != 1)) |
---|
126 | | - | then throw("Attached payment issue") |
---|
127 | | - | else { |
---|
128 | | - | let contractInfo = valueOrErrorMessage(assetInfo(valueOrErrorMessage(i.payments[0].assetId, "Wrong asset type")), "Unknown asset") |
---|
129 | | - | if ((contractInfo.issuer != this)) |
---|
130 | | - | then throw("Unknown issuer") |
---|
131 | | - | else { |
---|
132 | | - | let contractFields = split(contractInfo.description, separator) |
---|
133 | | - | if ((size(contractFields) != 5)) |
---|
134 | | - | then throw("Wrong fields amount") |
---|
135 | | - | else if ((contractFields[0] != contractTag)) |
---|
136 | | - | then throw("Not a contract") |
---|
137 | | - | else { |
---|
138 | | - | let contractHeight = valueOrErrorMessage(parseInt(contractFields[1]), "Not a height") |
---|
139 | | - | if ((isDefined(addressFromString(contractFields[2])) != true)) |
---|
140 | | - | then throw("Not an address") |
---|
141 | | - | else { |
---|
142 | | - | let contractAssetQuantity = valueOrErrorMessage(parseInt(contractFields[4]), "Not a quantity") |
---|
143 | | - | let contractAsset = match assetInfo(fromBase58String(contractFields[3])) { |
---|
144 | | - | case isAsset: Asset => |
---|
145 | | - | $Tuple2(isAsset.id, assetBalance(this, isAsset.id)) |
---|
146 | | - | case maybeWaves: Unit => |
---|
147 | | - | if ((contractFields[3] == wavesId)) |
---|
148 | | - | then $Tuple2(unit, wavesBalance(this).available) |
---|
149 | | - | else throw("Unknown asset") |
---|
150 | | - | case _ => |
---|
151 | | - | throw("Unknown asset") |
---|
152 | | - | } |
---|
153 | | - | if (if ((genesisHeight > contractHeight)) |
---|
154 | | - | then true |
---|
155 | | - | else (contractHeight >= height)) |
---|
156 | | - | then throw("Not in height scope") |
---|
157 | | - | else if (if ((1 > contractAssetQuantity)) |
---|
158 | | - | then true |
---|
159 | | - | else (contractAssetQuantity > maxInt)) |
---|
160 | | - | then throw("Quantity out-of-range") |
---|
161 | | - | else if ((contractAssetQuantity > contractAsset._2)) |
---|
162 | | - | then throw("Insuffisant balance") |
---|
163 | | - | else { |
---|
164 | | - | let receiptFields = [receiptTag, toString(contractHeight), contractFields[2], contractFields[3], toString(contractAssetQuantity), toString(height), toBase58String(contractInfo.id), toString(i.caller)] |
---|
165 | | - | if (({ |
---|
166 | | - | let $list63416392 = receiptFields |
---|
167 | | - | let $size63416392 = size($list63416392) |
---|
168 | | - | let $acc063416392 = false |
---|
169 | | - | if (($size63416392 == 0)) |
---|
170 | | - | then $acc063416392 |
---|
171 | | - | else { |
---|
172 | | - | let $acc163416392 = hasSeparatorInString($acc063416392, $list63416392[0]) |
---|
173 | | - | if (($size63416392 == 1)) |
---|
174 | | - | then $acc163416392 |
---|
175 | | - | else { |
---|
176 | | - | let $acc263416392 = hasSeparatorInString($acc163416392, $list63416392[1]) |
---|
177 | | - | if (($size63416392 == 2)) |
---|
178 | | - | then $acc263416392 |
---|
179 | | - | else { |
---|
180 | | - | let $acc363416392 = hasSeparatorInString($acc263416392, $list63416392[2]) |
---|
181 | | - | if (($size63416392 == 3)) |
---|
182 | | - | then $acc363416392 |
---|
183 | | - | else { |
---|
184 | | - | let $acc463416392 = hasSeparatorInString($acc363416392, $list63416392[3]) |
---|
185 | | - | if (($size63416392 == 4)) |
---|
186 | | - | then $acc463416392 |
---|
187 | | - | else { |
---|
188 | | - | let $acc563416392 = hasSeparatorInString($acc463416392, $list63416392[4]) |
---|
189 | | - | if (($size63416392 == 5)) |
---|
190 | | - | then $acc563416392 |
---|
191 | | - | else { |
---|
192 | | - | let $acc663416392 = hasSeparatorInString($acc563416392, $list63416392[5]) |
---|
193 | | - | if (($size63416392 == 6)) |
---|
194 | | - | then $acc663416392 |
---|
195 | | - | else { |
---|
196 | | - | let $acc763416392 = hasSeparatorInString($acc663416392, $list63416392[6]) |
---|
197 | | - | if (($size63416392 == 7)) |
---|
198 | | - | then $acc763416392 |
---|
199 | | - | else { |
---|
200 | | - | let $acc863416392 = hasSeparatorInString($acc763416392, $list63416392[7]) |
---|
201 | | - | if (($size63416392 == 8)) |
---|
202 | | - | then $acc863416392 |
---|
203 | | - | else { |
---|
204 | | - | let $acc963416392 = hasSeparatorInString($acc863416392, $list63416392[8]) |
---|
205 | | - | throw("List size exceed 8") |
---|
206 | | - | } |
---|
207 | | - | } |
---|
208 | | - | } |
---|
209 | | - | } |
---|
210 | | - | } |
---|
211 | | - | } |
---|
212 | | - | } |
---|
213 | | - | } |
---|
214 | | - | } |
---|
215 | | - | } == true)) |
---|
216 | | - | then throw("Separator found in fields") |
---|
217 | | - | else { |
---|
218 | | - | let receiptDescription = makeString(receiptFields, separator) |
---|
219 | | - | if ((size(toBytes(receiptDescription)) > maxDescriptionBytes)) |
---|
220 | | - | then throw("Too long contract") |
---|
221 | | - | else { |
---|
222 | | - | let nonce = generateNonce() |
---|
223 | | - | let receiptIssue = Issue(receiptName, receiptDescription, 1, 0, false, unit, nonce) |
---|
224 | | - | let receiptId = calculateAssetId(receiptIssue) |
---|
225 | | - | [IntegerEntry(keyNonceCount, nonce), Burn(contractInfo.id, 1), receiptIssue, ScriptTransfer(i.caller, receiptIssue.quantity, receiptId), ScriptTransfer(i.caller, contractAssetQuantity, contractAsset._1)] |
---|
226 | | - | } |
---|
227 | | - | } |
---|
228 | | - | } |
---|
229 | | - | } |
---|
230 | | - | } |
---|
231 | | - | } |
---|
232 | | - | } |
---|
233 | | - | |
---|
234 | | - | |
---|
235 | | - | |
---|
236 | | - | @Callable(i) |
---|
237 | | - | func claim (assetId) = if ((this == i.caller)) |
---|
238 | | - | then throw("Self call is forbidden") |
---|
239 | | - | else if ((1 > size(assetId))) |
---|
240 | | - | then throw("Empty asset id") |
---|
241 | | - | else if ((size(i.payments) != 0)) |
---|
242 | | - | then throw("No need payment") |
---|
243 | | - | else { |
---|
244 | | - | let assetData = valueOrErrorMessage(assetInfo(fromBase58String(assetId)), "Unknown asset") |
---|
245 | | - | if ((assetData.issuer != this)) |
---|
246 | | - | then throw("Unknown issuer") |
---|
247 | | - | else if ((assetBalance(this, assetData.id) != 1)) |
---|
248 | | - | then throw("Unavailable") |
---|
249 | | - | else { |
---|
250 | | - | let callerAddress = valueOrErrorMessage(addressFromString(valueOrErrorMessage(split(assetData.description, separator)[2], "Address field missing")), "Not an address") |
---|
251 | | - | if ((i.caller != callerAddress)) |
---|
252 | | - | then throw("Not owner") |
---|
253 | | - | else [ScriptTransfer(i.caller, 1, assetData.id)] |
---|
254 | | - | } |
---|
255 | | - | } |
---|
256 | | - | |
---|
257 | | - | |
---|
258 | | - | |
---|
259 | | - | @Callable(i) |
---|
260 | | - | func duplicate (assetId) = if ((this == i.caller)) |
---|
261 | | - | then throw("Self call is forbidden") |
---|
262 | | - | else if ((1 > size(assetId))) |
---|
263 | | - | then throw("Empty asset id") |
---|
264 | | - | else if ((size(i.payments) != 0)) |
---|
265 | | - | then throw("No need payment") |
---|
266 | | - | else { |
---|
267 | | - | let assetData = valueOrErrorMessage(assetInfo(fromBase58String(assetId)), "Unknown asset") |
---|
268 | | - | if ((assetData.issuer != this)) |
---|
269 | | - | then throw("Unknown issuer") |
---|
270 | | - | else if ((assetBalance(i.caller, assetData.id) != 1)) |
---|
271 | | - | then throw("Not owner") |
---|
272 | | - | else { |
---|
273 | | - | let assetFields = split(assetData.description, separator) |
---|
274 | | - | if ((1 > size(assetFields))) |
---|
275 | | - | then throw("No tag found") |
---|
276 | | - | else if (if ((assetFields[0] != contractTag)) |
---|
277 | | - | then (assetFields[0] != receiptTag) |
---|
278 | | - | else false) |
---|
279 | | - | then throw("Not a contract or receipt") |
---|
280 | | - | else { |
---|
281 | | - | let duplicateName = (duplicateTag + assetData.name) |
---|
282 | | - | let duplicateDescription = (duplicateTag + assetData.description) |
---|
283 | | - | if (if ((size(toBytes(duplicateDescription)) > maxDescriptionBytes)) |
---|
284 | | - | then true |
---|
285 | | - | else (size(toBytes(duplicateName)) > maxNameBytes)) |
---|
286 | | - | then throw("Too long, can't duplicate") |
---|
287 | | - | else { |
---|
288 | | - | let nonce = generateNonce() |
---|
289 | | - | let duplicateIssue = Issue(duplicateName, duplicateDescription, 1, 0, false, unit, nonce) |
---|
290 | | - | let duplicateId = calculateAssetId(duplicateIssue) |
---|
291 | | - | [IntegerEntry(keyNonceCount, nonce), duplicateIssue, ScriptTransfer(i.caller, 1, assetData.id)] |
---|
292 | | - | } |
---|
293 | | - | } |
---|
294 | | - | } |
---|
295 | | - | } |
---|
296 | | - | |
---|
297 | | - | |
---|
298 | | - | |
---|
299 | | - | @Callable(i) |
---|
300 | | - | func makeFree (privKey) = if (if ((this != i.caller)) |
---|
301 | | - | then true |
---|
302 | | - | else (valueOrElse(getBoolean(this, keyIsFree), false) == true)) |
---|
303 | | - | then throw("Access denied") |
---|
304 | | - | else [BooleanEntry(keyIsFree, true), StringEntry(keyPrivateKey, privKey)] |
---|
305 | | - | |
---|
306 | | - | |
---|