Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. let asset = base58'8jfD2JBLe23XtCCSQoTx5eAW5QCU6Mbxi3r78aNQLcNf'
  2. let addingStartHeight = 1000
  3. let votingStartHeight = 2000
  4. let votingEndHeight = 3000
  5.  
  6. #extracting the sender’s address from the transaction
  7. let this = extract(tx.sender)
  8.  
  9. #извлекаем адрес из пруфа транзакции
  10. #extracting the address from the transaction’s proof
  11.  
  12. let address = addressFromPublicKey(tx.proofs[1])
  13. match tx {
  14. case t: DataTransaction =>
  15. if(height > addingStartHeight)
  16. then(
  17. if(height < votingStartHeight)
  18. then(
  19. #adding
  20. #выясняем, есть ли этот ассет у этого адреса
  21. #checking if this address has this asset
  22. let hasTokens = assetBalance(address, asset) > 0
  23. size(t.data) == 1
  24. #убеждаемся, что этот ассет еще не был добавлен
  25. #making sure this assets has not yet been added
  26. && !isDefined(getInteger(this, toBase58String(asset)))
  27. #убеждаемся, что по ключу-ассету добавляется значение равное 0
  28. #checking if 0 has been added by the asset key
  29. && extract(getInteger(t.data, toBase58String(asset))) == 0
  30. && hasTokens
  31. )
  32. else(
  33. if(height < votingEndHeight)
  34. then
  35. (
  36. #voting
  37. #узнаем текущее количество голосов за данный ассет и задаваемое количество
  38. #finding out the current number of votes for this asset and the base number
  39. let currentAmount = extract(getInteger(this, toBase58String(asset)))
  40. let newAmount = extract(getInteger(t.data, toBase58String(asset)))
  41. let betString = toBase58String(address.bytes) + toBase58String(asset)
  42.  
  43. #убеждаемся, что этот адрес еще не голосовал за этот ассет
  44. #checking that this address has not yet voted for this asset
  45. let noBetBefore = !isDefined(getInteger(this, betString))
  46. let isBetCorrect = extract(getInteger(t.data, betString)) > 0
  47. && extract(getInteger(t.data, betString)) <= 10
  48.  
  49. #убеждаемся, что у голосующего есть необходимые токены
  50. #checking if the voter has enough tokens
  51. let hasTokens = assetBalance(address, asset) > 0
  52. #проверяем корректность значений транзакции
  53. #checking that the transaction is defined correctly
  54. size(t.data) == 2 && isDefined(getInteger(this, toBase58String(asset)))
  55. && newAmount == currentAmount + 1
  56. && noBetBefore && isBetCorrect && hasTokens
  57. )
  58. else false
  59. ) && sigVerify(tx.bodyBytes, tx.proofs[0], tx.proofs[1])
  60. )
  61. else false
  62. case _ => false
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement