blob: 81130a373a994001af2f8af32c18d03d8c39addb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
package core
import (
"bytes"
"crypto/sha256"
"fmt"
"io"
"strings"
)
func CalculateBlockHash(block []byte) (string, error) {
hash := sha256.New()
if _, err := io.Copy(hash, bytes.NewReader(block)); err != nil {
return "", err
}
hashInBytes := hash.Sum(nil)[:32]
return strings.TrimSpace(fmt.Sprintf("%x", hashInBytes)), nil
}
|