81 | | - | func inRange (integer,mini,maxi) = if ((integer >= mini)) |
---|
82 | | - | then (maxi >= integer) |
---|
83 | | - | else false |
---|
84 | | - | |
---|
85 | | - | |
---|
86 | | - | func with (str1,str2) = ((str1 + separator) + str2) |
---|
87 | | - | |
---|
88 | | - | |
---|
89 | | - | func assetTypeValidation (info,enforceType) = if ((info.issuer != this)) |
---|
90 | | - | then throw("Unknown issuer") |
---|
91 | | - | else { |
---|
92 | | - | let type = getStringValue(this, with(keyType, toBase58String(info.id))) |
---|
93 | | - | let isInsurance = if ((info.name == insuranceName)) |
---|
94 | | - | then (type == insuranceType) |
---|
95 | | - | else false |
---|
96 | | - | let isReceipt = if ((info.name == receiptType)) |
---|
97 | | - | then (type == receiptType) |
---|
98 | | - | else false |
---|
99 | | - | match enforceType { |
---|
100 | | - | case isType: String => |
---|
101 | | - | if (if (if (isInsurance) |
---|
102 | | - | then (isType == insuranceType) |
---|
103 | | - | else false) |
---|
104 | | - | then true |
---|
105 | | - | else if (isReceipt) |
---|
106 | | - | then (isType == receiptType) |
---|
107 | | - | else false) |
---|
108 | | - | then info |
---|
109 | | - | else throw("Unknown type") |
---|
110 | | - | case _ => |
---|
111 | | - | if (if (!(isInsurance)) |
---|
112 | | - | then !(isReceipt) |
---|
113 | | - | else false) |
---|
114 | | - | then throw("Unknown type") |
---|
115 | | - | else info |
---|
116 | | - | } |
---|
117 | | - | } |
---|
118 | | - | |
---|
119 | | - | |
---|
120 | | - | @Callable(i) |
---|
121 | | - | func deposit () = valueOrElse(hasAccess(i.caller), if (if ((size(i.payments) != 1)) |
---|
122 | | - | then true |
---|
123 | | - | else !(inRange(i.payments[0].amount, 1, maxInt))) |
---|
124 | | - | then throw("Require one valid payment") |
---|
125 | | - | else { |
---|
126 | | - | let assetId = match i.payments[0].assetId { |
---|
127 | | - | case isAsset: ByteVector => |
---|
128 | | - | toBase58String(valueOrErrorMessage(assetInfo(isAsset), "Unknown asset").id) |
---|
129 | | - | case isWaves: Unit => |
---|
130 | | - | waves |
---|
131 | | - | case _ => |
---|
132 | | - | throw("Unknown asset type") |
---|
133 | | - | } |
---|
134 | | - | let nonce = getNonce() |
---|
135 | | - | let insuranceSigner = toString(i.caller) |
---|
136 | | - | let insuranceDesc = makeString([appName, insuranceName, "| Height:", toString(height), "| Signer:", insuranceSigner, "| Asset ID:", assetId, "| Amount:", toString(i.payments[0].amount), "(includes decimals)"], " ") |
---|
137 | | - | let insuranceIssue = Issue(insuranceName, insuranceDesc, 1, 0, false, unit, nonce) |
---|
138 | | - | let insuranceId = calculateAssetId(insuranceIssue) |
---|
139 | | - | let id = toBase58String(insuranceId) |
---|
140 | | - | [IntegerEntry(keyNonce, nonce), insuranceIssue, ScriptTransfer(i.caller, 1, insuranceId), StringEntry(with(keyType, id), insuranceType), IntegerEntry(with(keyHeight, id), height), StringEntry(with(keySigner, id), insuranceSigner), StringEntry(with(keyAsset, id), assetId), IntegerEntry(with(keyAmount, id), i.payments[0].amount)] |
---|
141 | | - | }) |
---|
142 | | - | |
---|
143 | | - | |
---|
144 | | - | |
---|
145 | | - | @Callable(i) |
---|
146 | | - | func withdraw () = valueOrElse(hasAccess(i.caller), if (if ((size(i.payments) != 1)) |
---|
147 | | - | then true |
---|
148 | | - | else (i.payments[0].amount != 1)) |
---|
149 | | - | then throw("Require one NFT payment") |
---|
150 | | - | else { |
---|
151 | | - | let insuranceInfo = assetTypeValidation(valueOrErrorMessage(assetInfo(valueOrErrorMessage(i.payments[0].assetId, "No Waves payment")), "Unknown asset"), insuranceType) |
---|
152 | | - | let insuranceId = toBase58String(insuranceInfo.id) |
---|
153 | | - | let insuranceHeight = getIntegerValue(this, with(keyHeight, insuranceId)) |
---|
154 | | - | let insuranceSigner = getStringValue(this, with(keySigner, insuranceId)) |
---|
155 | | - | let insuranceAsset = getStringValue(this, with(keyAsset, insuranceId)) |
---|
156 | | - | let insuranceAssetAmount = getIntegerValue(this, with(keyAmount, insuranceId)) |
---|
157 | | - | let nonce = getNonce() |
---|
158 | | - | let receiptSigner = toString(i.caller) |
---|
159 | | - | let receiptDesc = makeString([appName, receiptName, "| Insurance Height:", toString(insuranceHeight), "| Insurance Signer:", insuranceSigner, "| Insurance ID:", insuranceId, "| Asset ID:", insuranceAsset, "| Amount:", toString(insuranceAssetAmount), "(includes decimals)", "| Height:", toString(height), "| Signer:", receiptSigner], " ") |
---|
160 | | - | let receiptIssue = Issue(receiptName, receiptDesc, 1, 0, false, unit, nonce) |
---|
161 | | - | let receiptId = calculateAssetId(receiptIssue) |
---|
162 | | - | let id = toBase58String(receiptId) |
---|
163 | | - | let receiptAssetTranfer = match assetInfo(fromBase58String(insuranceAsset)) { |
---|
164 | | - | case isAsset: Asset => |
---|
165 | | - | ScriptTransfer(i.caller, insuranceAssetAmount, isAsset.id) |
---|
166 | | - | case maybeWaves => |
---|
167 | | - | if ((insuranceAsset == waves)) |
---|
168 | | - | then ScriptTransfer(i.caller, insuranceAssetAmount, unit) |
---|
169 | | - | else throw("Unknown asset") |
---|
170 | | - | } |
---|
171 | | - | [IntegerEntry(keyNonce, nonce), Burn(insuranceInfo.id, 1), receiptIssue, ScriptTransfer(i.caller, 1, receiptId), receiptAssetTranfer, StringEntry(with(keyType, insuranceId), conclusionType), StringEntry(with(keyReceiptId, insuranceId), id), StringEntry(with(keyType, id), receiptType), IntegerEntry(with(keyInsuranceHeight, id), insuranceHeight), StringEntry(with(keyInsuranceSigner, id), insuranceSigner), StringEntry(with(keyInsuranceId, id), insuranceId), StringEntry(with(keyAsset, id), insuranceAsset), IntegerEntry(with(keyAmount, id), insuranceAssetAmount), IntegerEntry(with(keyHeight, id), height), StringEntry(with(keySigner, id), receiptSigner)] |
---|
172 | | - | }) |
---|
173 | | - | |
---|
174 | | - | |
---|
175 | | - | |
---|
176 | | - | @Callable(i) |
---|
177 | | - | func claim (claimAssetId) = valueOrElse(hasAccess(i.caller), if ((size(i.payments) != 0)) |
---|
178 | | - | then throw("No need payment") |
---|
179 | | - | else { |
---|
180 | | - | let claimAssetInfo = assetTypeValidation(valueOrErrorMessage(assetInfo(fromBase58String(claimAssetId)), "Unknown asset"), unit) |
---|
181 | | - | if ((assetBalance(this, claimAssetInfo.id) != 1)) |
---|
182 | | - | then throw("Insuffisant balance") |
---|
183 | | - | else if ((toString(i.caller) != getStringValue(this, with(keySigner, claimAssetId)))) |
---|
184 | | - | then throw("Caller isn't last signer") |
---|
185 | | - | else [ScriptTransfer(i.caller, 1, claimAssetInfo.id)] |
---|
186 | | - | }) |
---|
187 | | - | |
---|
188 | | - | |
---|
189 | | - | |
---|
190 | | - | @Callable(i) |
---|
191 | | - | func duplicate (toDuplicateId) = valueOrElse(hasAccess(i.caller), if ((size(i.payments) != 0)) |
---|
192 | | - | then throw("No need payment") |
---|
193 | | - | else { |
---|
194 | | - | let toDuplicateInfo = assetTypeValidation(valueOrErrorMessage(assetInfo(fromBase58String(toDuplicateId)), "Unknown asset"), unit) |
---|
195 | | - | let toDuplicateType = getStringValue(this, with(keyType, toDuplicateId)) |
---|
196 | | - | if ((assetBalance(i.caller, toDuplicateInfo.id) != 1)) |
---|
197 | | - | then throw("Caller isn't owner") |
---|
198 | | - | else { |
---|
199 | | - | let nonce = getNonce() |
---|
200 | | - | let duplicateSigner = toString(i.caller) |
---|
201 | | - | let $t079328406 = if ((toDuplicateType == insuranceType)) |
---|
202 | | - | then $Tuple2(iDuplicateName, makeString([appName, iDuplicateName, "| Insurance ID:", toDuplicateId, "| Height:", toString(height), "| Duplicate Signer:", duplicateSigner], " ")) |
---|
203 | | - | else $Tuple2(rDuplicateName, makeString([appName, rDuplicateName, "| Receipt ID:", toDuplicateId, "| Height:", toString(height), "| Duplicate Signer:", duplicateSigner], " ")) |
---|
204 | | - | let duplicateName = $t079328406._1 |
---|
205 | | - | let duplicateDesc = $t079328406._2 |
---|
206 | | - | let duplicateIssue = Issue(duplicateName, duplicateDesc, 1, 0, false, unit, nonce) |
---|
207 | | - | let duplicateId = calculateAssetId(duplicateIssue) |
---|
208 | | - | let id = toBase58String(duplicateId) |
---|
209 | | - | [IntegerEntry(keyNonce, nonce), duplicateIssue, ScriptTransfer(i.caller, 1, duplicateId), StringEntry(with(keyType, id), duplicateType), IntegerEntry(with(keyHeight, id), height), StringEntry(with(keyDuplicateType, id), toDuplicateType), StringEntry(with(keyDuplicateOf, id), toDuplicateId), StringEntry(with(keySigner, id), duplicateSigner)] |
---|
210 | | - | } |
---|
211 | | - | }) |
---|
212 | | - | |
---|
213 | | - | |
---|
214 | | - | |
---|
215 | | - | @Callable(i) |
---|
216 | | - | func freedom (privKey) = if (if ((this != i.caller)) |
---|
217 | | - | then true |
---|
218 | | - | else valueOrElse(getBoolean(this, keyAppIsFree), false)) |
---|
219 | | - | then throw("Access denied") |
---|
220 | | - | else [BooleanEntry(keyAppIsFree, true), StringEntry(keyAppPrivateKey, privKey), IntegerEntry(keyAppVersion, appVersion), StringEntry(keyAppName, appName), IntegerEntry(keyAppFreeSinceHeight, height)] |
---|
221 | | - | |
---|
222 | | - | |
---|