Skip to content

Commit

Permalink
allow configuration of ipldStores default hash function
Browse files Browse the repository at this point in the history
  • Loading branch information
whyrusleeping committed Jan 26, 2023
1 parent a12de32 commit a73d038
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion store.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
cbg "github.com/whyrusleeping/cbor-gen"
)

const DefaultMultihash = uint64(mh.BLAKE2B_MIN + 31)

// IpldStore wraps a Blockstore and provides an interface for storing and retrieving CBOR encoded data.
type IpldStore interface {
Get(ctx context.Context, c cid.Cid, out interface{}) error
Expand Down Expand Up @@ -41,6 +43,8 @@ type BasicIpldStore struct {
Viewer IpldBlockstoreViewer

Atlas *atlas.Atlas

DefaultMultihash uint64
}

var _ IpldStore = &BasicIpldStore{}
Expand Down Expand Up @@ -89,7 +93,11 @@ type cidProvider interface {

// Put marshals and writes content `v` to the backing blockstore returning its CID.
func (s *BasicIpldStore) Put(ctx context.Context, v interface{}) (cid.Cid, error) {
mhType := uint64(mh.BLAKE2B_MIN + 31)
mhType := DefaultMultihash
if s.DefaultMultihash != 0 {
mhType = s.DefaultMultihash
}

mhLen := -1
codec := uint64(cid.DagCBOR)

Expand Down

0 comments on commit a73d038

Please sign in to comment.