Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. Insurance / Crowdfunding
  2. In this case, we want to add token's users' protection from financial loss. For example, users want to have a guarantee that in the case of token depreciation they will get a full initial price of this tokens, For this service, they must pay some reasonable amount of money in addition to token price.
  3.  
  4. For an implementation of token insurance, you can issue “insured tokens”. Then you need to set a script to the wallet-account which allows ExchangeTransactions that satisfy the following conditions. To prevent double-spending you should ask a client to send a DataTransaction beforehand to your account with (key, value) = (purchaseTransactionId, sellOrderId) and prohibit setting DataTransactions with the same keys. It is the reason why the proof must contain the ID of the insured-token purchase transaction. Asset pair must be the same as in the purchase transaction, the price must be equal to the purchase price minus the price of the insurance itself.
  5.  
  6. It is implied that you're gonna buy insured-tokens from a client at a price not lower than the purchase price: you create an ExchangeTransaction, the client signs an order (if everything suits them), you sign the second order and the whole transaction and put it in the blockchain. If you do not do this, then after a certain time the client is able to an ExchangeTransaction according to the rules described in the script, and put it in the blockchain - that is, the client is able to return the money for which this token was bought.
  7.  
  8. # insuranceWalletAccount
  9. let insuranceToken = base58'8jfD2JBLe23XtCCSQoTx5eAW5QCU6Mbxi3r78aNQLcNf'
  10.  
  11. let this = extract(tx.sender)
  12. let freezePeriod = 150000
  13. let insurancePrice = 10000
  14.  
  15. match tx {
  16. case d : DataTransaction => size(d.data) == 1 && !isDefined(getBinary(this, d.data[0].key))
  17. case e : ExchangeTransaction =>
  18. if !isDefined(e.proofs[7]) then
  19. sigVerify(e.bodyBytes, e.proofs[0], e.senderPublicKey)
  20. else
  21. let purchaseTx = transactionById(e.proofs[7])
  22. let purchaseTxHeight = extract(transactionHeightById(e.proofs[7]))
  23.  
  24. match purchaseTx {
  25. case purchase : ExchangeTransaction =>
  26. let correctSender = purchase.sender == e.sellOrder.sender
  27. let correctAssetPair = e.sellOrder.assetPair.amountAsset == insuranceToken &&
  28. purchase.sellOrder.assetPair.amountAsset == insuranceToken &&
  29. e.sellOrder.assetPair.priceAsset == purchase.sellOrder.assetPair.priceAsset
  30. let correctPrice = e.price == purchase.price - insurancePrice && e.amount == purchase.amount
  31. let correctHeight = height > purchaseTxHeight + freezePeriod
  32. let correctProof = extract(getBinary(this, toBase58String(purchase.id))) == e.sellOrder.id
  33.  
  34. correctSender && correctAssetPair && correctPrice && correctHeight && correctProof
  35. case _ => false
  36. }
  37. case _ => sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement