Merge pull request #18 from vulcanize/final_tweaks
fixes from integration
This commit is contained in:
commit
d35140ce1f
@ -22,6 +22,7 @@ type KeyType uint
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
Invalid KeyType = iota
|
Invalid KeyType = iota
|
||||||
|
Static
|
||||||
Keccak
|
Keccak
|
||||||
Prefixed
|
Prefixed
|
||||||
Suffixed
|
Suffixed
|
||||||
@ -30,11 +31,11 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// keyDelineation is used to delineate the key prefixes and suffixes
|
// KeyDelineation is used to delineate the key prefixes and suffixes
|
||||||
KeyDelineation = []byte("/")
|
KeyDelineation = []byte("-fix-")
|
||||||
|
|
||||||
// numberDelineation is used to delineate the block number encoded in a key
|
// NumberDelineation is used to delineate the block number encoded in a key
|
||||||
NumberDelineation = []byte(":")
|
NumberDelineation = []byte("-nmb-")
|
||||||
|
|
||||||
// Data item prefixes (use single byte to avoid mixing data types, avoid `i`, used for indexes).
|
// Data item prefixes (use single byte to avoid mixing data types, avoid `i`, used for indexes).
|
||||||
HeaderPrefix = []byte("h") // headerPrefix + num (uint64 big endian) + hash -> header
|
HeaderPrefix = []byte("h") // headerPrefix + num (uint64 big endian) + hash -> header
|
||||||
@ -45,8 +46,12 @@ var (
|
|||||||
func ResolveKeyType(key []byte) (KeyType, [][]byte) {
|
func ResolveKeyType(key []byte) (KeyType, [][]byte) {
|
||||||
sk := bytes.Split(key, KeyDelineation)
|
sk := bytes.Split(key, KeyDelineation)
|
||||||
|
|
||||||
|
// these heuristics are reliant on the current db key patterns
|
||||||
switch len(sk) {
|
switch len(sk) {
|
||||||
case 1:
|
case 1:
|
||||||
|
if len(sk[0]) < 32 {
|
||||||
|
return Static, sk
|
||||||
|
}
|
||||||
return Keccak, sk
|
return Keccak, sk
|
||||||
case 2:
|
case 2:
|
||||||
switch prefix := sk[0]; {
|
switch prefix := sk[0]; {
|
||||||
|
@ -55,6 +55,8 @@ func DatastoreKeyFromGethKey(h []byte) (string, []byte, error) {
|
|||||||
// I.e. the public.blocks datastore key == the hex representation of the geth key
|
// I.e. the public.blocks datastore key == the hex representation of the geth key
|
||||||
// Alternatively, decompose the data and derive the hash
|
// Alternatively, decompose the data and derive the hash
|
||||||
return common.Bytes2Hex(h), keyComponents[0], nil
|
return common.Bytes2Hex(h), keyComponents[0], nil
|
||||||
|
case Static:
|
||||||
|
return common.Bytes2Hex(h), nil, nil
|
||||||
default:
|
default:
|
||||||
return "", nil, fmt.Errorf("invalid formatting of database key: %x", h)
|
return "", nil, fmt.Errorf("invalid formatting of database key: %x", h)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user