core: add policy check to (*Blockchain).verifyTx method

If any of transaction's script hashes for verifying are included into
Policy blocked accounts list, transaction is invalid.
This commit is contained in:
Anna Shaleva 2020-06-17 14:40:33 +03:00
parent b88863948d
commit ce402a70d2

View file

@ -1123,6 +1123,22 @@ func (bc *Blockchain) verifyTx(t *transaction.Transaction, block *block.Block) e
if t.ValidUntilBlock <= height || t.ValidUntilBlock > height+transaction.MaxValidUntilBlockIncrement { if t.ValidUntilBlock <= height || t.ValidUntilBlock > height+transaction.MaxValidUntilBlockIncrement {
return errors.Errorf("transaction has expired. ValidUntilBlock = %d, current height = %d", t.ValidUntilBlock, height) return errors.Errorf("transaction has expired. ValidUntilBlock = %d, current height = %d", t.ValidUntilBlock, height)
} }
hashes, err := bc.GetScriptHashesForVerifying(t)
if err != nil {
return err
}
blockedAccounts, err := bc.contracts.Policy.GetBlockedAccountsInternal(bc.dao)
if err != nil {
return err
}
for _, h := range hashes {
i := sort.Search(len(blockedAccounts), func(i int) bool {
return !blockedAccounts[i].Less(h)
})
if i != len(blockedAccounts) && blockedAccounts[i].Equals(h) {
return errors.Errorf("policy check failed")
}
}
balance := bc.GetUtilityTokenBalance(t.Sender) balance := bc.GetUtilityTokenBalance(t.Sender)
need := t.SystemFee.Add(t.NetworkFee) need := t.SystemFee.Add(t.NetworkFee)
if balance.LessThan(need) { if balance.LessThan(need) {