Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let asset = base58'8jfD2JBLe23XtCCSQoTx5eAW5QCU6Mbxi3r78aNQLcNf'
- let addingStartHeight = 1000
- let votingStartHeight = 2000
- let votingEndHeight = 3000
- #extracting the sender’s address from the transaction
- let this = extract(tx.sender)
- #извлекаем адрес из пруфа транзакции
- #extracting the address from the transaction’s proof
- let address = addressFromPublicKey(tx.proofs[1])
- match tx {
- case t: DataTransaction =>
- if(height > addingStartHeight)
- then(
- if(height < votingStartHeight)
- then(
- #adding
- #выясняем, есть ли этот ассет у этого адреса
- #checking if this address has this asset
- let hasTokens = assetBalance(address, asset) > 0
- size(t.data) == 1
- #убеждаемся, что этот ассет еще не был добавлен
- #making sure this assets has not yet been added
- && !isDefined(getInteger(this, toBase58String(asset)))
- #убеждаемся, что по ключу-ассету добавляется значение равное 0
- #checking if 0 has been added by the asset key
- && extract(getInteger(t.data, toBase58String(asset))) == 0
- && hasTokens
- )
- else(
- if(height < votingEndHeight)
- then
- (
- #voting
- #узнаем текущее количество голосов за данный ассет и задаваемое количество
- #finding out the current number of votes for this asset and the base number
- let currentAmount = extract(getInteger(this, toBase58String(asset)))
- let newAmount = extract(getInteger(t.data, toBase58String(asset)))
- let betString = toBase58String(address.bytes) + toBase58String(asset)
- #убеждаемся, что этот адрес еще не голосовал за этот ассет
- #checking that this address has not yet voted for this asset
- let noBetBefore = !isDefined(getInteger(this, betString))
- let isBetCorrect = extract(getInteger(t.data, betString)) > 0
- && extract(getInteger(t.data, betString)) <= 10
- #убеждаемся, что у голосующего есть необходимые токены
- #checking if the voter has enough tokens
- let hasTokens = assetBalance(address, asset) > 0
- #проверяем корректность значений транзакции
- #checking that the transaction is defined correctly
- size(t.data) == 2 && isDefined(getInteger(this, toBase58String(asset)))
- && newAmount == currentAmount + 1
- && noBetBefore && isBetCorrect && hasTokens
- )
- else false
- ) && sigVerify(tx.bodyBytes, tx.proofs[0], tx.proofs[1])
- )
- else false
- case _ => false
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement