Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. let insuranceToken = base58'8jfD2JBLe23XtCCSQoTx5eAW5QCU6Mbxi3r78aNQLcNf'
  2. #extracting the sender’s address from the transaction
  3. let this = extract(tx.sender)
  4. let freezePeriod = 150000
  5. let insurancePrice = 10000
  6. match tx {
  7. #verifying that if a DataTransaction has arrived, it has just one field and there is no second key in the state
  8. case d : DataTransaction => size(d.data) == 1 && !isDefined(getBinary(this, d.data[0].key))
  9. case e : ExchangeTransaction =>
  10. #if a transaction doesn’t have the seventh proof, we’re verifying the signature
  11. if !isDefined(e.proofs[7]) then
  12. sigVerify(e.bodyBytes, e.proofs[0], e.senderPublicKey)
  13. else
  14. #if the transaction has the seventh proof, we’re extracting from it the transaction and discovering its height
  15. let purchaseTx = transactionById(e.proofs[7])
  16. let purchaseTxHeight = extract(transactionHeightById(e.proofs[7]))
  17. #processing the transaction from the proof
  18. match purchaseTx {
  19. case purchase : ExchangeTransaction =>
  20. let correctSender = purchase.sender == e.sellOrder.sender
  21. let correctAssetPair = e.sellOrder.assetPair.amountAsset == insuranceToken &&
  22. purchase.sellOrder.assetPair.amountAsset == insuranceToken &&
  23. e.sellOrder.assetPair.priceAsset == purchase.sellOrder.assetPair.priceAsset
  24. let correctPrice = e.price == purchase.price - insurancePrice && e.amount == purchase.amount
  25. let correctHeight = height > purchaseTxHeight + freezePeriod
  26. #verifying that the current transaction’s ID is stated correctly in the proof transaction
  27. let correctProof = extract(getBinary(this, toBase58String(purchase.id))) == e.sellOrder.id
  28. correctSender && correctAssetPair && correctPrice && correctHeight && correctProof
  29. case _ => false
  30. }
  31. case _ => sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement