Commit 8d7850ee authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

updated datastore (keytransform)

parent f7c1ed39
......@@ -31,7 +31,7 @@ func makeDatastore(cfg config.Datastore) (ds.ThreadSafeDatastore, error) {
if err != nil {
return nil, err
}
ktd := ktds.WrapDatastore(d, u.DsKeyB58Encode)
ktd := ktds.Wrap(d, u.B58KeyConverter)
return syncds.MutexWrap(ktd), nil
}
......
......@@ -29,24 +29,30 @@ func KeyFromDsKey(dsk ds.Key) Key {
return Key(dsk.BaseNamespace())
}
// DsKeyB58Encode returns a B58 encoded Datastore key
// B58KeyConverter -- for KeyTransform datastores
// (static as only one obj needed)
var B58KeyConverter = b58KeyConverter{}
type b58KeyConverter struct{}
// ConvertKey returns a B58 encoded Datastore key
// TODO: this is hacky because it encodes every path component. some
// path components may be proper strings already...
func DsKeyB58Encode(dsk ds.Key) ds.Key {
func (b58KeyConverter) ConvertKey(dsk ds.Key) ds.Key {
k := ds.NewKey("/")
for _, n := range dsk.Namespaces() {
k = k.Child(b58.Encode([]byte(n)))
k = k.ChildString(b58.Encode([]byte(n)))
}
return k
}
// DsKeyB58Decode returns a b58 decoded Datastore key
// InvertKey returns a b58 decoded Datastore key
// TODO: this is hacky because it encodes every path component. some
// path components may be proper strings already...
func DsKeyB58Decode(dsk ds.Key) ds.Key {
func (b58KeyConverter) InvertKey(dsk ds.Key) ds.Key {
k := ds.NewKey("/")
for _, n := range dsk.Namespaces() {
k = k.Child(string(b58.Decode(n)))
k = k.ChildString(string(b58.Decode(n)))
}
return k
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment