blockstore: fix TODO and avoid calling ds.NewKey

License: MIT
Signed-off-by: Kevin Atkinson <k@kevina.org>
This commit is contained in:
Kevin Atkinson 2016-11-14 01:49:39 -05:00
parent 8d6ac7a83f
commit d48d90447b
2 changed files with 9 additions and 1 deletions

View File

@ -196,7 +196,7 @@ func (bs *blockstore) AllKeysChan(ctx context.Context) (<-chan *cid.Cid, error)
}
// need to convert to key.Key using key.KeyFromDsKey.
c, err := dshelp.DsKeyToCid(ds.NewKey(e.Key)) // TODO: calling NewKey isnt free
c, err := dshelp.DsKeyStringToCid(e.Key)
if err != nil {
log.Warningf("error parsing key from DsKey: ", err)
return nil, true

View File

@ -26,3 +26,11 @@ func DsKeyToCid(dsKey ds.Key) (*cid.Cid, error) {
}
return cid.Cast(kb)
}
func DsKeyStringToCid(dsKey string) (*cid.Cid, error) {
kb, err := base32.RawStdEncoding.DecodeString(dsKey[1:])
if err != nil {
return nil, err
}
return cid.Cast(kb)
}