2022-05-13 13:04:54 +00:00
|
|
|
package beaconclient
|
2022-05-13 02:10:31 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
blockstore "github.com/ipfs/go-ipfs-blockstore"
|
|
|
|
dshelp "github.com/ipfs/go-ipfs-ds-help"
|
|
|
|
"github.com/multiformats/go-multihash"
|
2022-05-13 13:04:54 +00:00
|
|
|
"github.com/vulcanize/ipld-ethcl-indexer/pkg/loghelper"
|
2022-05-13 02:10:31 +00:00
|
|
|
)
|
|
|
|
|
2022-05-13 02:22:11 +00:00
|
|
|
const SSZ_SHA2_256_PREFIX uint64 = 0xb501
|
2022-05-13 02:10:31 +00:00
|
|
|
|
|
|
|
// MultihashKeyFromSSZRoot converts a SSZ-SHA2-256 root hash into a blockstore prefixed multihash key
|
|
|
|
func MultihashKeyFromSSZRoot(root []byte) (string, error) {
|
|
|
|
mh, err := multihash.Encode(root, SSZ_SHA2_256_PREFIX)
|
|
|
|
if err != nil {
|
2022-05-13 13:04:54 +00:00
|
|
|
loghelper.LogError(err).Error("Unable to create a multihash Key")
|
2022-05-13 02:10:31 +00:00
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
dbKey := dshelp.MultihashToDsKey(mh)
|
|
|
|
return blockstore.BlockPrefix.String() + dbKey.String(), nil
|
|
|
|
}
|