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:BgI6CAISBAoCCAgSBAoCCAESAwoBCBIGCgQICAgIEgUKAwgICBIDCgECEgMKAQgSBgoECAEBARIECgIBARMADmNvbGxlY3Rpb25OYW1lCQERQGV4dHJOYXRpdmUoMTA1OCkBAg5jb2xsZWN0aW9uTmFtZQAGc3ltYm9sCQERQGV4dHJOYXRpdmUoMTA1OCkBAgZzeW1ib2wAC2Rlc2NyaXB0aW9uCQERQGV4dHJOYXRpdmUoMTA1OCkBAgtkZXNjcmlwdGlvbgALdG90YWxBbW91bnQJARFAZXh0ck5hdGl2ZSgxMDU1KQECC3RvdGFsQW1vdW50AAdiYXNlVVJJCQERQGV4dHJOYXRpdmUoMTA1OCkBAgdiYXNlVVJJAAhkQXBwSnNvbgkBB0FkZHJlc3MBCQDZBAECIzNNckdhWlZSaGtuRUdmSEoxOXR0VVBObkRSb0ZxY0hoVk43AAx0b2tlblBheW1lbnQJARFAZXh0ck5hdGl2ZSgxMDU3KQECDHRva2VuUGF5bWVudAARdG9rZW5QYXltZW50QXNzZXQJARN2YWx1ZU9yRXJyb3JNZXNzYWdlA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0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgCefXkL", "height": 2500031, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 9dgVmxNtsfMkYsJB5QzDYDTwBojPRNUGJh8ZXCUiThc4 Next: none Diff:
OldNewDifferences
99
1010 let totalAmount = getIntegerValue("totalAmount")
1111
12+let baseURI = getStringValue("baseURI")
13+
1214 let dAppJson = Address(fromBase58String("3MrGaZVRhknEGfHJ19ttUPNnDRoFqcHhVN7"))
1315
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+
1526
1627 func onlyInternal (caller) = if ((caller == this))
1728 then unit
1930
2031
2132 func transferOrNot (to,assetId) = if ((to == this))
22- then StringEntry("костыль", "костыль")
33+ then StringEntry("smth", "smth")
2334 else ScriptTransfer(to, 1, assetId)
24-
25-
26-func parseIdtoAsset (assetId) = valueOrErrorMessage(assetInfo(fromBase58String(assetId)), "Can't find asset by asset id")
2735
2836
2937 func checkAssetOwner (caller,assetId) = if ((assetBalance(caller, fromBase58String(assetId)) == 1))
3139 else throw("Only asset owner")
3240
3341
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+
3484 @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)])
4186
4287
4388
4489 @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)])
5191
5292
5393
5494 @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)])
6196
6297
6398
6499 @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)])
76101
77102
78103
92117
93118
94119 @Callable(i)
95-func setTokenPayment (assetId) = valueOrElse(onlyInternal(i.caller), [BinaryEntry("tokenPayment", assetId)])
120+func setTokenPayment (assetBinary) = valueOrElse(onlyInternal(i.caller), [BinaryEntry("tokenPayment", assetBinary)])
96121
97122
98123
99124 @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) = {
116126 let tokenId = (totalAmount + 1)
117- let preName = ((symbol + "#") + toString(tokenId))
127+ let tokenIdString = toString(tokenId)
128+ let preName = ((symbol + "#") + tokenIdString)
118129 let name = if ((16 >= size(preName)))
119130 then preName
120- else toString(tokenId)
131+ else tokenIdString
132+ let tokenURI = (baseURI + tokenIdString)
121133 let json = {
122134 let @ = invoke(dAppJson, "makeJSON", [["tokenURI"], [tokenURI]], nil)
123135 if ($isInstanceOf(@, "String"))
146158 }
147159 if ((tokenURI == tokenURI))
148160 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"))
153164 then @
154- else throw(($getType(@) + " couldn't be cast to (String, String)"))
165+ else throw(($getType(@) + " couldn't be cast to String"))
155166 }
156- if ((delete == delete))
167+ if ((lendJson == lendJson))
157168 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)]
179171 }
180172 else throw("Strict value is not equal to itself.")
181173 }
185177
186178
187179 @Callable(i)
188-func initRent (lendId,timeUnitCount) = {
180+func initRent (lendId,timeUnitCount) = valueOrElse(checkPayment(i.payments, calcLendCost(lendId, timeUnitCount)), {
189181 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"))
194188 then @
195- else throw(($getType(@) + " couldn't be cast to (String, String)"))
189+ else throw(($getType(@) + " couldn't be cast to String"))
196190 }
197- if ((deleteLendCount == deleteLendCount))
191+ if ((timeUnitSeconds == timeUnitSeconds))
198192 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+ }
207206 else throw("Strict value is not equal to itself.")
208207 }
209208 else throw("Strict value is not equal to itself.")
210- }
209+ })
211210
212211
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let collectionName = getStringValue("collectionName")
55
66 let symbol = getStringValue("symbol")
77
88 let description = getStringValue("description")
99
1010 let totalAmount = getIntegerValue("totalAmount")
1111
12+let baseURI = getStringValue("baseURI")
13+
1214 let dAppJson = Address(fromBase58String("3MrGaZVRhknEGfHJ19ttUPNnDRoFqcHhVN7"))
1315
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+
1526
1627 func onlyInternal (caller) = if ((caller == this))
1728 then unit
1829 else throw("Only internal call")
1930
2031
2132 func transferOrNot (to,assetId) = if ((to == this))
22- then StringEntry("костыль", "костыль")
33+ then StringEntry("smth", "smth")
2334 else ScriptTransfer(to, 1, assetId)
24-
25-
26-func parseIdtoAsset (assetId) = valueOrErrorMessage(assetInfo(fromBase58String(assetId)), "Can't find asset by asset id")
2735
2836
2937 func checkAssetOwner (caller,assetId) = if ((assetBalance(caller, fromBase58String(assetId)) == 1))
3038 then unit
3139 else throw("Only asset owner")
3240
3341
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+
3484 @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)])
4186
4287
4388
4489 @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)])
5191
5292
5393
5494 @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)])
6196
6297
6398
6499 @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)])
76101
77102
78103
79104 @Callable(i)
80105 func setUser (assetId,user,expires) = {
81106 let res = invoke(dAppJson, "makeJSON", [["user", "expires"], [user, expires]], nil)
82107 if ((res == res))
83108 then $Tuple2([StringEntry(("userOf-" + assetId), {
84109 let @ = res
85110 if ($isInstanceOf(@, "String"))
86111 then @
87112 else throw(($getType(@) + " couldn't be cast to String"))
88113 })], res)
89114 else throw("Strict value is not equal to itself.")
90115 }
91116
92117
93118
94119 @Callable(i)
95-func setTokenPayment (assetId) = valueOrElse(onlyInternal(i.caller), [BinaryEntry("tokenPayment", assetId)])
120+func setTokenPayment (assetBinary) = valueOrElse(onlyInternal(i.caller), [BinaryEntry("tokenPayment", assetBinary)])
96121
97122
98123
99124 @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) = {
116126 let tokenId = (totalAmount + 1)
117- let preName = ((symbol + "#") + toString(tokenId))
127+ let tokenIdString = toString(tokenId)
128+ let preName = ((symbol + "#") + tokenIdString)
118129 let name = if ((16 >= size(preName)))
119130 then preName
120- else toString(tokenId)
131+ else tokenIdString
132+ let tokenURI = (baseURI + tokenIdString)
121133 let json = {
122134 let @ = invoke(dAppJson, "makeJSON", [["tokenURI"], [tokenURI]], nil)
123135 if ($isInstanceOf(@, "String"))
124136 then @
125137 else throw(($getType(@) + " couldn't be cast to String"))
126138 }
127139 let asset = Issue(name, json, 1, 0, false, unit, height)
128140 let assetId = calculateAssetId(asset)
129141 let toAddress = Address(fromBase58String(to))
130142 let transfer = transferOrNot(toAddress, assetId)
131143 if ((transfer == transfer))
132144 then [asset, transfer, IntegerEntry("totalAmount", tokenId), StringEntry(name, tokenURI)]
133145 else throw("Strict value is not equal to itself.")
134146 }
135147
136148
137149
138150 @Callable(i)
139151 func initLend (assetId,timeUnitSeconds,timeUnitPrice,timeUnitCount) = valueOrElse(checkAssetOwner(i.caller, assetId), {
140152 let asset = parseIdtoAsset(assetId)
141153 let tokenURI = {
142154 let @ = invoke(dAppJson, "readByJSONKey", [asset.description, "tokenURI"], nil)
143155 if ($isInstanceOf(@, "String"))
144156 then @
145157 else throw(($getType(@) + " couldn't be cast to String"))
146158 }
147159 if ((tokenURI == tokenURI))
148160 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"))
153164 then @
154- else throw(($getType(@) + " couldn't be cast to (String, String)"))
165+ else throw(($getType(@) + " couldn't be cast to String"))
155166 }
156- if ((delete == delete))
167+ if ((lendJson == lendJson))
157168 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)]
179171 }
180172 else throw("Strict value is not equal to itself.")
181173 }
182174 else throw("Strict value is not equal to itself.")
183175 })
184176
185177
186178
187179 @Callable(i)
188-func initRent (lendId,timeUnitCount) = {
180+func initRent (lendId,timeUnitCount) = valueOrElse(checkPayment(i.payments, calcLendCost(lendId, timeUnitCount)), {
189181 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"))
194188 then @
195- else throw(($getType(@) + " couldn't be cast to (String, String)"))
189+ else throw(($getType(@) + " couldn't be cast to String"))
196190 }
197- if ((deleteLendCount == deleteLendCount))
191+ if ((timeUnitSeconds == timeUnitSeconds))
198192 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+ }
207206 else throw("Strict value is not equal to itself.")
208207 }
209208 else throw("Strict value is not equal to itself.")
210- }
209+ })
211210
212211

github/deemru/w8io/026f985 
37.63 ms