From e11987f0c2f63086da7ea99211361bca8c911623 Mon Sep 17 00:00:00 2001 From: Delweng Zheng Date: Wed, 6 Jun 2018 21:57:53 +0800 Subject: [PATCH] core/rawdb: wrappered helper to assemble key --- core/rawdb/schema.go | 55 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/core/rawdb/schema.go b/core/rawdb/schema.go index a4b1596fde..e767cef237 100644 --- a/core/rawdb/schema.go +++ b/core/rawdb/schema.go @@ -77,3 +77,58 @@ func encodeBlockNumber(number uint64) []byte { binary.BigEndian.PutUint64(enc, number) 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...) +}