core/rawdb: wrappered helper to assemble key

This commit is contained in:
Delweng Zheng 2018-06-06 21:57:53 +08:00
parent 90b22773e9
commit e11987f0c2

View file

@ -77,3 +77,58 @@ func encodeBlockNumber(number uint64) []byte {
binary.BigEndian.PutUint64(enc, number) binary.BigEndian.PutUint64(enc, number)
return enc return enc
} }
// headerKey = headerPrefix + num (uint64 big endian) + hash
func headerKey(number uint64, suffix []byte) []byte {
return append(append(headerPrefix, encodeBlockNumber(number)...), suffix...)
}
// headerTDKey = headerPrefix + num (uint64 big endian) + hash + headerTDSuffix
func headerTDKey(number uint64, hashBytes []byte) []byte {
return append(headerKey(number, hashBytes), headerTDSuffix...)
}
// headerHashKey = headerPrefix + num (uint64 big endian) + headerHashSuffix
func headerHashKey(number uint64) []byte {
return headerKey(number, headerHashSuffix)
}
// headerNumberKey = headerNumberPrefix + hash
func headerNumberKey(hashBytes []byte) []byte {
return append(headerNumberPrefix, hashBytes...)
}
// blockBodyKey = blockBodyPrefix + num (uint64 big endian) + hash
func blockBodyKey(number uint64, hashBytes []byte) []byte {
return append(append(blockBodyPrefix, encodeBlockNumber(number)...), hashBytes...)
}
// blockReceiptsKey = blockReceiptsPrefix + num (uint64 big endian) + hash
func blockReceiptsKey(number uint64, hashBytes []byte) []byte {
return append(append(blockReceiptsPrefix, encodeBlockNumber(number)...), hashBytes...)
}
// txLookupKey = txLookupPrefix + hash
func txLookupKey(hashBytes []byte) []byte {
return append(txLookupPrefix, hashBytes...)
}
// bloomBitsKey = bloomBitsPrefix + bit (uint16 big endian) + section (uint64 big endian) + hash
func bloomBitsKey(bit uint, section uint64, hashBytes []byte) []byte {
key := append(append(bloomBitsPrefix, make([]byte, 10)...), hashBytes...)
binary.BigEndian.PutUint16(key[1:], uint16(bit))
binary.BigEndian.PutUint64(key[3:], section)
return key
}
// preimageKey = preimagePrefix + hash
func preimageKey(hashBytes []byte) []byte {
return append(preimagePrefix, hashBytes...)
}
// configKey = configPrefix + hash
func configKey(hashBytes []byte) []byte {
return append(configPrefix, hashBytes...)
}