diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-10-29 16:45:43 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-29 16:45:43 +0800 |
commit | 51904f3e9b821f3313d3ab1f268efb28f739eb5f (patch) | |
tree | 235f636525027fccf42aee2520afcc9e2463f49e /core/utils.go | |
parent | dcc2319797d3ab78ff0611b82c56d43803675e3c (diff) | |
download | dexon-consensus-51904f3e9b821f3313d3ab1f268efb28f739eb5f.tar.gz dexon-consensus-51904f3e9b821f3313d3ab1f268efb28f739eb5f.tar.zst dexon-consensus-51904f3e9b821f3313d3ab1f268efb28f739eb5f.zip |
core: Add BlockSkeleton and Verify functions (#271)
Diffstat (limited to 'core/utils.go')
-rw-r--r-- | core/utils.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/core/utils.go b/core/utils.go index ac95678..38e8746 100644 --- a/core/utils.go +++ b/core/utils.go @@ -131,6 +131,27 @@ func HashConfigurationBlock( ) } +// VerifyBlock verifies the signature of types.Block. +func VerifyBlock(b *types.Block) (err error) { + hash, err := hashBlock(b) + if err != nil { + return + } + if hash != b.Hash { + err = ErrIncorrectHash + return + } + pubKey, err := crypto.SigToPub(b.Hash, b.Signature) + if err != nil { + return + } + if !b.ProposerID.Equal(types.NewNodeID(pubKey)) { + err = ErrIncorrectSignature + return + } + return +} + // DiffUint64 calculates difference between two uint64. func DiffUint64(a, b uint64) uint64 { if a > b { |