block: return error from Verify

Don't hide real problem behind the bool value. Makes it easier to identify
problems when looking at log messages.
This commit is contained in:
Roman Khimov 2019-10-11 11:40:54 +03:00
parent 258f397b9a
commit 16bc5296cb
3 changed files with 14 additions and 10 deletions

View file

@ -1,6 +1,9 @@
package core
import (
"errors"
"fmt"
"github.com/CityOfZion/neo-go/pkg/core/transaction"
"github.com/CityOfZion/neo-go/pkg/crypto"
"github.com/CityOfZion/neo-go/pkg/io"
@ -45,26 +48,26 @@ func (b *Block) rebuildMerkleRoot() error {
}
// Verify the integrity of the block.
func (b *Block) Verify(full bool) bool {
func (b *Block) Verify(full bool) error {
// There has to be some transaction inside.
if len(b.Transactions) == 0 {
return false
return errors.New("no transactions")
}
// The first TX has to be a miner transaction.
if b.Transactions[0].Type != transaction.MinerType {
return false
return fmt.Errorf("the first transaction is %s", b.Transactions[0].Type)
}
// If the first TX is a minerTX then all others cant.
for _, tx := range b.Transactions[1:] {
if tx.Type == transaction.MinerType {
return false
return fmt.Errorf("miner transaction %s is not the first one", tx.Hash().ReverseString())
}
}
// TODO: When full is true, do a full verification.
if full {
log.Warn("full verification of blocks is not yet implemented")
}
return true
return nil
}
// NewBlockFromTrimmedBytes returns a new block from trimmed data.