tx · CXd5K5d2okxiagrheUKZAJMR6Voz2MRwB6uHF3zSbLjH 3MrQ4g9YCsAN2Wr4QUXiWAPhNPv7DGdQNWb: -0.00700000 Waves 2023.03.21 19:54 [2500031] smart account 3MrQ4g9YCsAN2Wr4QUXiWAPhNPv7DGdQNWb > SELF 0.00000000 Waves
{ "type": 13, "id": "CXd5K5d2okxiagrheUKZAJMR6Voz2MRwB6uHF3zSbLjH", "fee": 700000, "feeAssetId": null, "timestamp": 1679417653340, "version": 2, "chainId": 84, "sender": "3MrQ4g9YCsAN2Wr4QUXiWAPhNPv7DGdQNWb", "senderPublicKey": "2VQGRNRWyFAZvjDtkgZwdZcTwZvBJJ61n8zJfYYxm5eK", "proofs": [ "5TsKVBxGvtt7uZUjqQU3Td2Bk4htA1sJcJ4YC4p1KsvnkcsvmJn33kaZ9hDGisHVPBy39YbgggaQxM9gDiv8Yznc" ], "script": "base64:BgI6CAISBAoCCAgSBAoCCAESAwoBCBIGCgQICAgIEgUKAwgICBIDCgECEgMKAQgSBgoECAEBARIECgIBARMADmNvbGxlY3Rpb25OYW1lCQERQGV4dHJOYXRpdmUoMTA1OCkBAg5jb2xsZWN0aW9uTmFtZQAGc3ltYm9sCQERQGV4dHJOYXRpdmUoMTA1OCkBAgZzeW1ib2wAC2Rlc2NyaXB0aW9uCQERQGV4dHJOYXRpdmUoMTA1OCkBAgtkZXNjcmlwdGlvbgALdG90YWxBbW91bnQJARFAZXh0ck5hdGl2ZSgxMDU1KQECC3RvdGFsQW1vdW50AAdiYXNlVVJJCQERQGV4dHJOYXRpdmUoMTA1OCkBAgdiYXNlVVJJAAhkQXBwSnNvbgkBB0FkZHJlc3MBCQDZBAECIzNNckdhWlZSaGtuRUdmSEoxOXR0VVBObkRSb0ZxY0hoVk43AAx0b2tlblBheW1lbnQJARFAZXh0ck5hdGl2ZSgxMDU3KQECDHRva2VuUGF5bWVudAARdG9rZW5QYXltZW50QXNzZXQJARN2YWx1ZU9yRXJyb3JNZXNzYWdlAg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cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgCefXkL", "height": 2500031, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 9dgVmxNtsfMkYsJB5QzDYDTwBojPRNUGJh8ZXCUiThc4 Next: none Diff:
Old | New | Differences | |
---|---|---|---|
9 | 9 | ||
10 | 10 | let totalAmount = getIntegerValue("totalAmount") | |
11 | 11 | ||
12 | + | let baseURI = getStringValue("baseURI") | |
13 | + | ||
12 | 14 | let dAppJson = Address(fromBase58String("3MrGaZVRhknEGfHJ19ttUPNnDRoFqcHhVN7")) | |
13 | 15 | ||
14 | - | let tokenPayment = Address(getBinaryValue("tokenPayment")) | |
16 | + | let tokenPayment = getBinaryValue("tokenPayment") | |
17 | + | ||
18 | + | let tokenPaymentAsset = valueOrErrorMessage(assetInfo(getBinaryValue("tokenPayment")), "token payment asset doesn't connect") | |
19 | + | ||
20 | + | let lendCount = getIntegerValue("lendCount") | |
21 | + | ||
22 | + | let lendCurrentCount = getIntegerValue("lendCurrentCount") | |
23 | + | ||
24 | + | func parseIdtoAsset (assetId) = valueOrErrorMessage(assetInfo(fromBase58String(assetId)), "Can't find asset by asset id") | |
25 | + | ||
15 | 26 | ||
16 | 27 | func onlyInternal (caller) = if ((caller == this)) | |
17 | 28 | then unit | |
19 | 30 | ||
20 | 31 | ||
21 | 32 | func transferOrNot (to,assetId) = if ((to == this)) | |
22 | - | then StringEntry(" | |
33 | + | then StringEntry("smth", "smth") | |
23 | 34 | else ScriptTransfer(to, 1, assetId) | |
24 | - | ||
25 | - | ||
26 | - | func parseIdtoAsset (assetId) = valueOrErrorMessage(assetInfo(fromBase58String(assetId)), "Can't find asset by asset id") | |
27 | 35 | ||
28 | 36 | ||
29 | 37 | func checkAssetOwner (caller,assetId) = if ((assetBalance(caller, fromBase58String(assetId)) == 1)) | |
31 | 39 | else throw("Only asset owner") | |
32 | 40 | ||
33 | 41 | ||
42 | + | func checkPayment (payments,amount) = if ((payments[0].amount >= amount)) | |
43 | + | then unit | |
44 | + | else throw("amount less then need") | |
45 | + | ||
46 | + | ||
47 | + | func getLendJson (lendId) = { | |
48 | + | let lendIdString = toString(lendId) | |
49 | + | getStringValue(("lend-" + lendIdString)) | |
50 | + | } | |
51 | + | ||
52 | + | ||
53 | + | func getKey (lendJson,key) = { | |
54 | + | let timeUnitSeconds = { | |
55 | + | let @ = invoke(dAppJson, "readByJSONKey", [lendJson, key], nil) | |
56 | + | if ($isInstanceOf(@, "String")) | |
57 | + | then @ | |
58 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
59 | + | } | |
60 | + | if ((timeUnitSeconds == timeUnitSeconds)) | |
61 | + | then timeUnitSeconds | |
62 | + | else throw("Strict value is not equal to itself.") | |
63 | + | } | |
64 | + | ||
65 | + | ||
66 | + | func getRentCount (lendId) = { | |
67 | + | let lendIdString = toString(lendId) | |
68 | + | getIntegerValue(("lend-rentCount-" + lendIdString)) | |
69 | + | } | |
70 | + | ||
71 | + | ||
72 | + | func calcLendCost (lendId,timeUnitSeconds) = { | |
73 | + | let lendJson = getLendJson(lendId) | |
74 | + | let timeUnitPriceString = getKey(lendJson, "timeUnitPrice") | |
75 | + | if ((timeUnitPriceString == timeUnitPriceString)) | |
76 | + | then { | |
77 | + | let timeUnitPrice = parseIntValue(timeUnitPriceString) | |
78 | + | (timeUnitSeconds * timeUnitPrice) | |
79 | + | } | |
80 | + | else throw("Strict value is not equal to itself.") | |
81 | + | } | |
82 | + | ||
83 | + | ||
34 | 84 | @Callable(i) | |
35 | - | func makeJSONInternal (arrKeys,arrValues) = valueOrElse(onlyInternal(i.caller), { | |
36 | - | let res = invoke(dAppJson, "makeJSON", [arrKeys, arrValues], nil) | |
37 | - | if ((res == res)) | |
38 | - | then $Tuple2(nil, res) | |
39 | - | else throw("Strict value is not equal to itself.") | |
40 | - | }) | |
85 | + | func setString (_key,_value) = valueOrElse(onlyInternal(i.caller), [StringEntry(_key, _value)]) | |
41 | 86 | ||
42 | 87 | ||
43 | 88 | ||
44 | 89 | @Callable(i) | |
45 | - | func addToJSONInternal (json,arrKeys,arrValues) = valueOrElse(onlyInternal(i.caller), { | |
46 | - | let res = invoke(dAppJson, "addToJSON", [json, arrKeys, arrValues], nil) | |
47 | - | if ((res == res)) | |
48 | - | then $Tuple2(nil, res) | |
49 | - | else throw("Strict value is not equal to itself.") | |
50 | - | }) | |
90 | + | func setInt (_key,_value) = valueOrElse(onlyInternal(i.caller), [IntegerEntry(_key, _value)]) | |
51 | 91 | ||
52 | 92 | ||
53 | 93 | ||
54 | 94 | @Callable(i) | |
55 | - | func readByJSONKeyInternal (json,key) = valueOrElse(onlyInternal(i.caller), { | |
56 | - | let res = invoke(dAppJson, "readByJSONKey", [json, key], nil) | |
57 | - | if ((res == res)) | |
58 | - | then $Tuple2(nil, res) | |
59 | - | else throw("Strict value is not equal to itself.") | |
60 | - | }) | |
95 | + | func deleteEntry (_key) = valueOrElse(onlyInternal(i.caller), [DeleteEntry(_key)]) | |
61 | 96 | ||
62 | 97 | ||
63 | 98 | ||
64 | 99 | @Callable(i) | |
65 | - | func deleteByJSONKeyInternal (json,key) = valueOrElse(onlyInternal(i.caller), { | |
66 | - | let res = invoke(dAppJson, "deleteByJSONKey", [json, key], nil) | |
67 | - | if ((res == res)) | |
68 | - | then $Tuple2(nil, res) | |
69 | - | else throw("Strict value is not equal to itself.") | |
70 | - | }) | |
71 | - | ||
72 | - | ||
73 | - | ||
74 | - | @Callable(i) | |
75 | - | func storageJsonInternal (jsonKey,jsonString) = valueOrElse(onlyInternal(i.caller), [StringEntry(jsonKey, jsonString)]) | |
100 | + | func init (_collectionName,_symbol,_description,_baseURI) = valueOrElse(onlyInternal(i.caller), [StringEntry("collectionName", _collectionName), StringEntry("symbol", _symbol), StringEntry("description", _description), IntegerEntry("totalAmount", 0), StringEntry("baseURI", _baseURI)]) | |
76 | 101 | ||
77 | 102 | ||
78 | 103 | ||
92 | 117 | ||
93 | 118 | ||
94 | 119 | @Callable(i) | |
95 | - | func setTokenPayment ( | |
120 | + | func setTokenPayment (assetBinary) = valueOrElse(onlyInternal(i.caller), [BinaryEntry("tokenPayment", assetBinary)]) | |
96 | 121 | ||
97 | 122 | ||
98 | 123 | ||
99 | 124 | @Callable(i) | |
100 | - | func deleteValueByKey (key) = valueOrElse(onlyInternal(i.caller), [DeleteEntry(key)]) | |
101 | - | ||
102 | - | ||
103 | - | ||
104 | - | @Callable(i) | |
105 | - | func setString (key,value) = valueOrElse(onlyInternal(i.caller), [StringEntry(key, value)]) | |
106 | - | ||
107 | - | ||
108 | - | ||
109 | - | @Callable(i) | |
110 | - | func init (collectionName,symbol,description) = valueOrElse(onlyInternal(i.caller), [StringEntry("collectionName", collectionName), StringEntry("symbol", symbol), StringEntry("description", description), IntegerEntry("totalAmount", 0)]) | |
111 | - | ||
112 | - | ||
113 | - | ||
114 | - | @Callable(i) | |
115 | - | func mint (to,tokenURI) = { | |
125 | + | func mint (to) = { | |
116 | 126 | let tokenId = (totalAmount + 1) | |
117 | - | let preName = ((symbol + "#") + toString(tokenId)) | |
127 | + | let tokenIdString = toString(tokenId) | |
128 | + | let preName = ((symbol + "#") + tokenIdString) | |
118 | 129 | let name = if ((16 >= size(preName))) | |
119 | 130 | then preName | |
120 | - | else toString(tokenId) | |
131 | + | else tokenIdString | |
132 | + | let tokenURI = (baseURI + tokenIdString) | |
121 | 133 | let json = { | |
122 | 134 | let @ = invoke(dAppJson, "makeJSON", [["tokenURI"], [tokenURI]], nil) | |
123 | 135 | if ($isInstanceOf(@, "String")) | |
146 | 158 | } | |
147 | 159 | if ((tokenURI == tokenURI)) | |
148 | 160 | then { | |
149 | - | let lends = getStringValue("Lends") | |
150 | - | let delete = { | |
151 | - | let @ = invoke(dAppJson, "deleteByJSONKey", [lends, "lendCount"], nil) | |
152 | - | if ($isInstanceOf(@, "(String, String)")) | |
161 | + | let lendJson = { | |
162 | + | let @ = invoke(dAppJson, "makeJSON", [["supportedInterface", "assetdId", "tokenURI", "owner", "timeUnitSeconds", "timeUnitPrice", "timeUnitCount", "startTimestamp", "endTimestamp", "deposit", "claimed"], ["0", assetId, tokenURI, toString(i.caller), toString(timeUnitSeconds), toString(timeUnitPrice), toString(timeUnitCount), toString(lastBlock.timestamp), toString((lastBlock.timestamp + (timeUnitSeconds * timeUnitCount))), "0", "0"]], nil) | |
163 | + | if ($isInstanceOf(@, "String")) | |
153 | 164 | then @ | |
154 | - | else throw(($getType(@) + " couldn't be cast to | |
165 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
155 | 166 | } | |
156 | - | if (( | |
167 | + | if ((lendJson == lendJson)) | |
157 | 168 | then { | |
158 | - | let lendId = delete._1 | |
159 | - | let newCount = toString((parseIntValue(lendId) + 1)) | |
160 | - | let make = { | |
161 | - | let @ = invoke(dAppJson, "makeJSON", [["supportedInterface", "assetdId", "tokenURI", "owner", "timeUnitSeconds", "timeUnitPrice", "timeUnitCount", "startTimestamp", "endTimestamp", "deposit", "claimed", "rents"], ["0", assetId, tokenURI, toString(i.caller), toString(timeUnitSeconds), toString(timeUnitPrice), toString(timeUnitCount), toString(lastBlock.timestamp), toString((lastBlock.timestamp + (timeUnitSeconds * timeUnitCount))), "0", "0", "{\"name\":\"Rents\",\"rentCount\":\"0\"}"]], nil) | |
162 | - | if ($isInstanceOf(@, "String")) | |
163 | - | then @ | |
164 | - | else throw(($getType(@) + " couldn't be cast to String")) | |
165 | - | } | |
166 | - | if ((make == make)) | |
167 | - | then { | |
168 | - | let insert = { | |
169 | - | let @ = invoke(dAppJson, "addToJSON", [delete._2, [lendId, "lendCount"], [make, newCount]], nil) | |
170 | - | if ($isInstanceOf(@, "String")) | |
171 | - | then @ | |
172 | - | else throw(($getType(@) + " couldn't be cast to String")) | |
173 | - | } | |
174 | - | if ((insert == insert)) | |
175 | - | then [StringEntry("Lends", insert)] | |
176 | - | else throw("Strict value is not equal to itself.") | |
177 | - | } | |
178 | - | else throw("Strict value is not equal to itself.") | |
169 | + | let lendIdString = toString(lendCount) | |
170 | + | [IntegerEntry("lendCount", (lendCount + 1)), IntegerEntry("lendCurrentCount", (lendCurrentCount + 1)), IntegerEntry(("lend-rentCount-" + lendIdString), 0), StringEntry(("lend-" + lendIdString), lendJson)] | |
179 | 171 | } | |
180 | 172 | else throw("Strict value is not equal to itself.") | |
181 | 173 | } | |
185 | 177 | ||
186 | 178 | ||
187 | 179 | @Callable(i) | |
188 | - | func initRent (lendId,timeUnitCount) = { | |
180 | + | func initRent (lendId,timeUnitCount) = valueOrElse(checkPayment(i.payments, calcLendCost(lendId, timeUnitCount)), { | |
189 | 181 | let lendIdString = toString(lendId) | |
190 | - | let lends = getStringValue("Lends") | |
191 | - | let deleteLendCount = { | |
192 | - | let @ = invoke(dAppJson, "deleteByJSONKey", [lends, "lendCount"], nil) | |
193 | - | if ($isInstanceOf(@, "(String, String)")) | |
182 | + | let lendJson = getStringValue(("lend-" + lendIdString)) | |
183 | + | let rentId = getRentCount(lendId) | |
184 | + | let rentIdString = toString(rentId) | |
185 | + | let timeUnitSeconds = { | |
186 | + | let @ = invoke(dAppJson, "readByJSONKey", [lendJson, "timeUnitSeconds"], nil) | |
187 | + | if ($isInstanceOf(@, "String")) | |
194 | 188 | then @ | |
195 | - | else throw(($getType(@) + " couldn't be cast to | |
189 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
196 | 190 | } | |
197 | - | if (( | |
191 | + | if ((timeUnitSeconds == timeUnitSeconds)) | |
198 | 192 | then { | |
199 | - | let deleteLend = { | |
200 | - | let @ = invoke(dAppJson, "deleteByJSONKey", [deleteLendCount._2, lendIdString], nil) | |
201 | - | if ($isInstanceOf(@, "(String, String)")) | |
202 | - | then @ | |
203 | - | else throw(($getType(@) + " couldn't be cast to (String, String)")) | |
204 | - | } | |
205 | - | if ((deleteLend == deleteLend)) | |
206 | - | then [StringEntry("Debug", deleteLend._1)] | |
193 | + | let timeUnitSecondsInt = parseIntValue(timeUnitSeconds) | |
194 | + | if ((timeUnitSecondsInt == timeUnitSecondsInt)) | |
195 | + | then { | |
196 | + | let rentJson = { | |
197 | + | let @ = invoke(dAppJson, "makeJSON", [["customer", "timeUnitCount", "startTimestamp", "endTimestamp", "closed"], [toString(i.caller), toString(timeUnitCount), toString(lastBlock.timestamp), toString((lastBlock.timestamp + (timeUnitSecondsInt * timeUnitCount))), "0"]], nil) | |
198 | + | if ($isInstanceOf(@, "String")) | |
199 | + | then @ | |
200 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
201 | + | } | |
202 | + | if ((rentJson == rentJson)) | |
203 | + | then [IntegerEntry(("lend-rentCount-" + lendIdString), (rentId + 1)), StringEntry(((("lend-rent-" + lendIdString) + "-") + rentIdString), rentJson)] | |
204 | + | else throw("Strict value is not equal to itself.") | |
205 | + | } | |
207 | 206 | else throw("Strict value is not equal to itself.") | |
208 | 207 | } | |
209 | 208 | else throw("Strict value is not equal to itself.") | |
210 | - | } | |
209 | + | }) | |
211 | 210 | ||
212 | 211 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let collectionName = getStringValue("collectionName") | |
5 | 5 | ||
6 | 6 | let symbol = getStringValue("symbol") | |
7 | 7 | ||
8 | 8 | let description = getStringValue("description") | |
9 | 9 | ||
10 | 10 | let totalAmount = getIntegerValue("totalAmount") | |
11 | 11 | ||
12 | + | let baseURI = getStringValue("baseURI") | |
13 | + | ||
12 | 14 | let dAppJson = Address(fromBase58String("3MrGaZVRhknEGfHJ19ttUPNnDRoFqcHhVN7")) | |
13 | 15 | ||
14 | - | let tokenPayment = Address(getBinaryValue("tokenPayment")) | |
16 | + | let tokenPayment = getBinaryValue("tokenPayment") | |
17 | + | ||
18 | + | let tokenPaymentAsset = valueOrErrorMessage(assetInfo(getBinaryValue("tokenPayment")), "token payment asset doesn't connect") | |
19 | + | ||
20 | + | let lendCount = getIntegerValue("lendCount") | |
21 | + | ||
22 | + | let lendCurrentCount = getIntegerValue("lendCurrentCount") | |
23 | + | ||
24 | + | func parseIdtoAsset (assetId) = valueOrErrorMessage(assetInfo(fromBase58String(assetId)), "Can't find asset by asset id") | |
25 | + | ||
15 | 26 | ||
16 | 27 | func onlyInternal (caller) = if ((caller == this)) | |
17 | 28 | then unit | |
18 | 29 | else throw("Only internal call") | |
19 | 30 | ||
20 | 31 | ||
21 | 32 | func transferOrNot (to,assetId) = if ((to == this)) | |
22 | - | then StringEntry(" | |
33 | + | then StringEntry("smth", "smth") | |
23 | 34 | else ScriptTransfer(to, 1, assetId) | |
24 | - | ||
25 | - | ||
26 | - | func parseIdtoAsset (assetId) = valueOrErrorMessage(assetInfo(fromBase58String(assetId)), "Can't find asset by asset id") | |
27 | 35 | ||
28 | 36 | ||
29 | 37 | func checkAssetOwner (caller,assetId) = if ((assetBalance(caller, fromBase58String(assetId)) == 1)) | |
30 | 38 | then unit | |
31 | 39 | else throw("Only asset owner") | |
32 | 40 | ||
33 | 41 | ||
42 | + | func checkPayment (payments,amount) = if ((payments[0].amount >= amount)) | |
43 | + | then unit | |
44 | + | else throw("amount less then need") | |
45 | + | ||
46 | + | ||
47 | + | func getLendJson (lendId) = { | |
48 | + | let lendIdString = toString(lendId) | |
49 | + | getStringValue(("lend-" + lendIdString)) | |
50 | + | } | |
51 | + | ||
52 | + | ||
53 | + | func getKey (lendJson,key) = { | |
54 | + | let timeUnitSeconds = { | |
55 | + | let @ = invoke(dAppJson, "readByJSONKey", [lendJson, key], nil) | |
56 | + | if ($isInstanceOf(@, "String")) | |
57 | + | then @ | |
58 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
59 | + | } | |
60 | + | if ((timeUnitSeconds == timeUnitSeconds)) | |
61 | + | then timeUnitSeconds | |
62 | + | else throw("Strict value is not equal to itself.") | |
63 | + | } | |
64 | + | ||
65 | + | ||
66 | + | func getRentCount (lendId) = { | |
67 | + | let lendIdString = toString(lendId) | |
68 | + | getIntegerValue(("lend-rentCount-" + lendIdString)) | |
69 | + | } | |
70 | + | ||
71 | + | ||
72 | + | func calcLendCost (lendId,timeUnitSeconds) = { | |
73 | + | let lendJson = getLendJson(lendId) | |
74 | + | let timeUnitPriceString = getKey(lendJson, "timeUnitPrice") | |
75 | + | if ((timeUnitPriceString == timeUnitPriceString)) | |
76 | + | then { | |
77 | + | let timeUnitPrice = parseIntValue(timeUnitPriceString) | |
78 | + | (timeUnitSeconds * timeUnitPrice) | |
79 | + | } | |
80 | + | else throw("Strict value is not equal to itself.") | |
81 | + | } | |
82 | + | ||
83 | + | ||
34 | 84 | @Callable(i) | |
35 | - | func makeJSONInternal (arrKeys,arrValues) = valueOrElse(onlyInternal(i.caller), { | |
36 | - | let res = invoke(dAppJson, "makeJSON", [arrKeys, arrValues], nil) | |
37 | - | if ((res == res)) | |
38 | - | then $Tuple2(nil, res) | |
39 | - | else throw("Strict value is not equal to itself.") | |
40 | - | }) | |
85 | + | func setString (_key,_value) = valueOrElse(onlyInternal(i.caller), [StringEntry(_key, _value)]) | |
41 | 86 | ||
42 | 87 | ||
43 | 88 | ||
44 | 89 | @Callable(i) | |
45 | - | func addToJSONInternal (json,arrKeys,arrValues) = valueOrElse(onlyInternal(i.caller), { | |
46 | - | let res = invoke(dAppJson, "addToJSON", [json, arrKeys, arrValues], nil) | |
47 | - | if ((res == res)) | |
48 | - | then $Tuple2(nil, res) | |
49 | - | else throw("Strict value is not equal to itself.") | |
50 | - | }) | |
90 | + | func setInt (_key,_value) = valueOrElse(onlyInternal(i.caller), [IntegerEntry(_key, _value)]) | |
51 | 91 | ||
52 | 92 | ||
53 | 93 | ||
54 | 94 | @Callable(i) | |
55 | - | func readByJSONKeyInternal (json,key) = valueOrElse(onlyInternal(i.caller), { | |
56 | - | let res = invoke(dAppJson, "readByJSONKey", [json, key], nil) | |
57 | - | if ((res == res)) | |
58 | - | then $Tuple2(nil, res) | |
59 | - | else throw("Strict value is not equal to itself.") | |
60 | - | }) | |
95 | + | func deleteEntry (_key) = valueOrElse(onlyInternal(i.caller), [DeleteEntry(_key)]) | |
61 | 96 | ||
62 | 97 | ||
63 | 98 | ||
64 | 99 | @Callable(i) | |
65 | - | func deleteByJSONKeyInternal (json,key) = valueOrElse(onlyInternal(i.caller), { | |
66 | - | let res = invoke(dAppJson, "deleteByJSONKey", [json, key], nil) | |
67 | - | if ((res == res)) | |
68 | - | then $Tuple2(nil, res) | |
69 | - | else throw("Strict value is not equal to itself.") | |
70 | - | }) | |
71 | - | ||
72 | - | ||
73 | - | ||
74 | - | @Callable(i) | |
75 | - | func storageJsonInternal (jsonKey,jsonString) = valueOrElse(onlyInternal(i.caller), [StringEntry(jsonKey, jsonString)]) | |
100 | + | func init (_collectionName,_symbol,_description,_baseURI) = valueOrElse(onlyInternal(i.caller), [StringEntry("collectionName", _collectionName), StringEntry("symbol", _symbol), StringEntry("description", _description), IntegerEntry("totalAmount", 0), StringEntry("baseURI", _baseURI)]) | |
76 | 101 | ||
77 | 102 | ||
78 | 103 | ||
79 | 104 | @Callable(i) | |
80 | 105 | func setUser (assetId,user,expires) = { | |
81 | 106 | let res = invoke(dAppJson, "makeJSON", [["user", "expires"], [user, expires]], nil) | |
82 | 107 | if ((res == res)) | |
83 | 108 | then $Tuple2([StringEntry(("userOf-" + assetId), { | |
84 | 109 | let @ = res | |
85 | 110 | if ($isInstanceOf(@, "String")) | |
86 | 111 | then @ | |
87 | 112 | else throw(($getType(@) + " couldn't be cast to String")) | |
88 | 113 | })], res) | |
89 | 114 | else throw("Strict value is not equal to itself.") | |
90 | 115 | } | |
91 | 116 | ||
92 | 117 | ||
93 | 118 | ||
94 | 119 | @Callable(i) | |
95 | - | func setTokenPayment ( | |
120 | + | func setTokenPayment (assetBinary) = valueOrElse(onlyInternal(i.caller), [BinaryEntry("tokenPayment", assetBinary)]) | |
96 | 121 | ||
97 | 122 | ||
98 | 123 | ||
99 | 124 | @Callable(i) | |
100 | - | func deleteValueByKey (key) = valueOrElse(onlyInternal(i.caller), [DeleteEntry(key)]) | |
101 | - | ||
102 | - | ||
103 | - | ||
104 | - | @Callable(i) | |
105 | - | func setString (key,value) = valueOrElse(onlyInternal(i.caller), [StringEntry(key, value)]) | |
106 | - | ||
107 | - | ||
108 | - | ||
109 | - | @Callable(i) | |
110 | - | func init (collectionName,symbol,description) = valueOrElse(onlyInternal(i.caller), [StringEntry("collectionName", collectionName), StringEntry("symbol", symbol), StringEntry("description", description), IntegerEntry("totalAmount", 0)]) | |
111 | - | ||
112 | - | ||
113 | - | ||
114 | - | @Callable(i) | |
115 | - | func mint (to,tokenURI) = { | |
125 | + | func mint (to) = { | |
116 | 126 | let tokenId = (totalAmount + 1) | |
117 | - | let preName = ((symbol + "#") + toString(tokenId)) | |
127 | + | let tokenIdString = toString(tokenId) | |
128 | + | let preName = ((symbol + "#") + tokenIdString) | |
118 | 129 | let name = if ((16 >= size(preName))) | |
119 | 130 | then preName | |
120 | - | else toString(tokenId) | |
131 | + | else tokenIdString | |
132 | + | let tokenURI = (baseURI + tokenIdString) | |
121 | 133 | let json = { | |
122 | 134 | let @ = invoke(dAppJson, "makeJSON", [["tokenURI"], [tokenURI]], nil) | |
123 | 135 | if ($isInstanceOf(@, "String")) | |
124 | 136 | then @ | |
125 | 137 | else throw(($getType(@) + " couldn't be cast to String")) | |
126 | 138 | } | |
127 | 139 | let asset = Issue(name, json, 1, 0, false, unit, height) | |
128 | 140 | let assetId = calculateAssetId(asset) | |
129 | 141 | let toAddress = Address(fromBase58String(to)) | |
130 | 142 | let transfer = transferOrNot(toAddress, assetId) | |
131 | 143 | if ((transfer == transfer)) | |
132 | 144 | then [asset, transfer, IntegerEntry("totalAmount", tokenId), StringEntry(name, tokenURI)] | |
133 | 145 | else throw("Strict value is not equal to itself.") | |
134 | 146 | } | |
135 | 147 | ||
136 | 148 | ||
137 | 149 | ||
138 | 150 | @Callable(i) | |
139 | 151 | func initLend (assetId,timeUnitSeconds,timeUnitPrice,timeUnitCount) = valueOrElse(checkAssetOwner(i.caller, assetId), { | |
140 | 152 | let asset = parseIdtoAsset(assetId) | |
141 | 153 | let tokenURI = { | |
142 | 154 | let @ = invoke(dAppJson, "readByJSONKey", [asset.description, "tokenURI"], nil) | |
143 | 155 | if ($isInstanceOf(@, "String")) | |
144 | 156 | then @ | |
145 | 157 | else throw(($getType(@) + " couldn't be cast to String")) | |
146 | 158 | } | |
147 | 159 | if ((tokenURI == tokenURI)) | |
148 | 160 | then { | |
149 | - | let lends = getStringValue("Lends") | |
150 | - | let delete = { | |
151 | - | let @ = invoke(dAppJson, "deleteByJSONKey", [lends, "lendCount"], nil) | |
152 | - | if ($isInstanceOf(@, "(String, String)")) | |
161 | + | let lendJson = { | |
162 | + | let @ = invoke(dAppJson, "makeJSON", [["supportedInterface", "assetdId", "tokenURI", "owner", "timeUnitSeconds", "timeUnitPrice", "timeUnitCount", "startTimestamp", "endTimestamp", "deposit", "claimed"], ["0", assetId, tokenURI, toString(i.caller), toString(timeUnitSeconds), toString(timeUnitPrice), toString(timeUnitCount), toString(lastBlock.timestamp), toString((lastBlock.timestamp + (timeUnitSeconds * timeUnitCount))), "0", "0"]], nil) | |
163 | + | if ($isInstanceOf(@, "String")) | |
153 | 164 | then @ | |
154 | - | else throw(($getType(@) + " couldn't be cast to | |
165 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
155 | 166 | } | |
156 | - | if (( | |
167 | + | if ((lendJson == lendJson)) | |
157 | 168 | then { | |
158 | - | let lendId = delete._1 | |
159 | - | let newCount = toString((parseIntValue(lendId) + 1)) | |
160 | - | let make = { | |
161 | - | let @ = invoke(dAppJson, "makeJSON", [["supportedInterface", "assetdId", "tokenURI", "owner", "timeUnitSeconds", "timeUnitPrice", "timeUnitCount", "startTimestamp", "endTimestamp", "deposit", "claimed", "rents"], ["0", assetId, tokenURI, toString(i.caller), toString(timeUnitSeconds), toString(timeUnitPrice), toString(timeUnitCount), toString(lastBlock.timestamp), toString((lastBlock.timestamp + (timeUnitSeconds * timeUnitCount))), "0", "0", "{\"name\":\"Rents\",\"rentCount\":\"0\"}"]], nil) | |
162 | - | if ($isInstanceOf(@, "String")) | |
163 | - | then @ | |
164 | - | else throw(($getType(@) + " couldn't be cast to String")) | |
165 | - | } | |
166 | - | if ((make == make)) | |
167 | - | then { | |
168 | - | let insert = { | |
169 | - | let @ = invoke(dAppJson, "addToJSON", [delete._2, [lendId, "lendCount"], [make, newCount]], nil) | |
170 | - | if ($isInstanceOf(@, "String")) | |
171 | - | then @ | |
172 | - | else throw(($getType(@) + " couldn't be cast to String")) | |
173 | - | } | |
174 | - | if ((insert == insert)) | |
175 | - | then [StringEntry("Lends", insert)] | |
176 | - | else throw("Strict value is not equal to itself.") | |
177 | - | } | |
178 | - | else throw("Strict value is not equal to itself.") | |
169 | + | let lendIdString = toString(lendCount) | |
170 | + | [IntegerEntry("lendCount", (lendCount + 1)), IntegerEntry("lendCurrentCount", (lendCurrentCount + 1)), IntegerEntry(("lend-rentCount-" + lendIdString), 0), StringEntry(("lend-" + lendIdString), lendJson)] | |
179 | 171 | } | |
180 | 172 | else throw("Strict value is not equal to itself.") | |
181 | 173 | } | |
182 | 174 | else throw("Strict value is not equal to itself.") | |
183 | 175 | }) | |
184 | 176 | ||
185 | 177 | ||
186 | 178 | ||
187 | 179 | @Callable(i) | |
188 | - | func initRent (lendId,timeUnitCount) = { | |
180 | + | func initRent (lendId,timeUnitCount) = valueOrElse(checkPayment(i.payments, calcLendCost(lendId, timeUnitCount)), { | |
189 | 181 | let lendIdString = toString(lendId) | |
190 | - | let lends = getStringValue("Lends") | |
191 | - | let deleteLendCount = { | |
192 | - | let @ = invoke(dAppJson, "deleteByJSONKey", [lends, "lendCount"], nil) | |
193 | - | if ($isInstanceOf(@, "(String, String)")) | |
182 | + | let lendJson = getStringValue(("lend-" + lendIdString)) | |
183 | + | let rentId = getRentCount(lendId) | |
184 | + | let rentIdString = toString(rentId) | |
185 | + | let timeUnitSeconds = { | |
186 | + | let @ = invoke(dAppJson, "readByJSONKey", [lendJson, "timeUnitSeconds"], nil) | |
187 | + | if ($isInstanceOf(@, "String")) | |
194 | 188 | then @ | |
195 | - | else throw(($getType(@) + " couldn't be cast to | |
189 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
196 | 190 | } | |
197 | - | if (( | |
191 | + | if ((timeUnitSeconds == timeUnitSeconds)) | |
198 | 192 | then { | |
199 | - | let deleteLend = { | |
200 | - | let @ = invoke(dAppJson, "deleteByJSONKey", [deleteLendCount._2, lendIdString], nil) | |
201 | - | if ($isInstanceOf(@, "(String, String)")) | |
202 | - | then @ | |
203 | - | else throw(($getType(@) + " couldn't be cast to (String, String)")) | |
204 | - | } | |
205 | - | if ((deleteLend == deleteLend)) | |
206 | - | then [StringEntry("Debug", deleteLend._1)] | |
193 | + | let timeUnitSecondsInt = parseIntValue(timeUnitSeconds) | |
194 | + | if ((timeUnitSecondsInt == timeUnitSecondsInt)) | |
195 | + | then { | |
196 | + | let rentJson = { | |
197 | + | let @ = invoke(dAppJson, "makeJSON", [["customer", "timeUnitCount", "startTimestamp", "endTimestamp", "closed"], [toString(i.caller), toString(timeUnitCount), toString(lastBlock.timestamp), toString((lastBlock.timestamp + (timeUnitSecondsInt * timeUnitCount))), "0"]], nil) | |
198 | + | if ($isInstanceOf(@, "String")) | |
199 | + | then @ | |
200 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
201 | + | } | |
202 | + | if ((rentJson == rentJson)) | |
203 | + | then [IntegerEntry(("lend-rentCount-" + lendIdString), (rentId + 1)), StringEntry(((("lend-rent-" + lendIdString) + "-") + rentIdString), rentJson)] | |
204 | + | else throw("Strict value is not equal to itself.") | |
205 | + | } | |
207 | 206 | else throw("Strict value is not equal to itself.") | |
208 | 207 | } | |
209 | 208 | else throw("Strict value is not equal to itself.") | |
210 | - | } | |
209 | + | }) | |
211 | 210 | ||
212 | 211 |
github/deemru/w8io/026f985 37.63 ms ◑