aboutsummaryrefslogtreecommitdiffstats
path: root/core/utils.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-10-29 16:45:43 +0800
committerGitHub <noreply@github.com>2018-10-29 16:45:43 +0800
commit51904f3e9b821f3313d3ab1f268efb28f739eb5f (patch)
tree235f636525027fccf42aee2520afcc9e2463f49e /core/utils.go
parentdcc2319797d3ab78ff0611b82c56d43803675e3c (diff)
downloaddexon-consensus-51904f3e9b821f3313d3ab1f268efb28f739eb5f.tar
dexon-consensus-51904f3e9b821f3313d3ab1f268efb28f739eb5f.tar.gz
dexon-consensus-51904f3e9b821f3313d3ab1f268efb28f739eb5f.tar.bz2
dexon-consensus-51904f3e9b821f3313d3ab1f268efb28f739eb5f.tar.lz
dexon-consensus-51904f3e9b821f3313d3ab1f268efb28f739eb5f.tar.xz
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.go21
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 {