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