Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let insuranceToken = base58'8jfD2JBLe23XtCCSQoTx5eAW5QCU6Mbxi3r78aNQLcNf'
- #extracting the sender’s address from the transaction
- let this = extract(tx.sender)
- let freezePeriod = 150000
- let insurancePrice = 10000
- match tx {
- #verifying that if a DataTransaction has arrived, it has just one field and there is no second key in the state
- case d : DataTransaction => size(d.data) == 1 && !isDefined(getBinary(this, d.data[0].key))
- case e : ExchangeTransaction =>
- #if a transaction doesn’t have the seventh proof, we’re verifying the signature
- if !isDefined(e.proofs[7]) then
- sigVerify(e.bodyBytes, e.proofs[0], e.senderPublicKey)
- else
- #if the transaction has the seventh proof, we’re extracting from it the transaction and discovering its height
- let purchaseTx = transactionById(e.proofs[7])
- let purchaseTxHeight = extract(transactionHeightById(e.proofs[7]))
- #processing the transaction from the proof
- match purchaseTx {
- case purchase : ExchangeTransaction =>
- let correctSender = purchase.sender == e.sellOrder.sender
- let correctAssetPair = e.sellOrder.assetPair.amountAsset == insuranceToken &&
- purchase.sellOrder.assetPair.amountAsset == insuranceToken &&
- e.sellOrder.assetPair.priceAsset == purchase.sellOrder.assetPair.priceAsset
- let correctPrice = e.price == purchase.price - insurancePrice && e.amount == purchase.amount
- let correctHeight = height > purchaseTxHeight + freezePeriod
- #verifying that the current transaction’s ID is stated correctly in the proof transaction
- let correctProof = extract(getBinary(this, toBase58String(purchase.id))) == e.sellOrder.id
- correctSender && correctAssetPair && correctPrice && correctHeight && correctProof
- case _ => false
- }
- case _ => sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement