aboutsummaryrefslogtreecommitdiff
path: root/core/storage.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/storage.go')
-rw-r--r--core/storage.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/core/storage.go b/core/storage.go
index 7475bef..8c76c52 100644
--- a/core/storage.go
+++ b/core/storage.go
@@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"os"
+ "strings"
bolt "go.etcd.io/bbolt"
)
@@ -131,3 +132,14 @@ func GetNode(checksum string, db *bolt.DB) (Node, error) {
}
return node, err
}
+
+func VerifyNode(node Node, nextNode Node) error {
+ nodeHash, err := calculateStringHash(fmt.Sprintf("%d%d%s%s", node.BlockStart, node.BlockEnd, node.BlockSum, node.PrevNodeSum))
+ if err != nil {
+ return err
+ }
+ if strings.Compare(nodeHash, nextNode.PrevNodeSum) != 0 {
+ return fmt.Errorf("Node %s is not valid!", node.PrevNodeSum)
+ }
+ return nil
+}