2020-02-06 04:08:36 +00:00
|
|
|
package dbutils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/binary"
|
2020-08-21 06:32:11 +00:00
|
|
|
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/common"
|
2020-02-06 04:08:36 +00:00
|
|
|
)
|
|
|
|
|
2021-05-31 16:29:55 +00:00
|
|
|
func AccountIndexChunkKey(key []byte, blockNumber uint64) []byte {
|
|
|
|
blockNumBytes := make([]byte, common.AddressLength+8)
|
|
|
|
copy(blockNumBytes, key)
|
|
|
|
binary.BigEndian.PutUint64(blockNumBytes[common.AddressLength:], blockNumber)
|
2020-02-06 04:08:36 +00:00
|
|
|
|
2021-05-31 16:29:55 +00:00
|
|
|
return blockNumBytes
|
2020-05-23 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2021-05-31 16:29:55 +00:00
|
|
|
func StorageIndexChunkKey(key []byte, blockNumber uint64) []byte {
|
|
|
|
//remove incarnation and add block number
|
|
|
|
blockNumBytes := make([]byte, common.AddressLength+common.HashLength+8)
|
|
|
|
copy(blockNumBytes, key[:common.AddressLength])
|
|
|
|
copy(blockNumBytes[common.AddressLength:], key[common.AddressLength+common.IncarnationLength:])
|
|
|
|
binary.BigEndian.PutUint64(blockNumBytes[common.AddressLength+common.HashLength:], blockNumber)
|
2020-04-20 10:35:33 +00:00
|
|
|
|
|
|
|
return blockNumBytes
|
|
|
|
}
|
2020-12-04 21:16:51 +00:00
|
|
|
|
2020-05-23 09:19:56 +00:00
|
|
|
func CompositeKeyWithoutIncarnation(key []byte) []byte {
|
|
|
|
if len(key) == common.HashLength*2+common.IncarnationLength {
|
|
|
|
kk := make([]byte, common.HashLength*2)
|
|
|
|
copy(kk, key[:common.HashLength])
|
|
|
|
copy(kk[common.HashLength:], key[common.HashLength+common.IncarnationLength:])
|
|
|
|
return kk
|
|
|
|
}
|
2020-05-31 06:57:47 +00:00
|
|
|
if len(key) == common.AddressLength+common.HashLength+common.IncarnationLength {
|
|
|
|
kk := make([]byte, common.AddressLength+common.HashLength)
|
|
|
|
copy(kk, key[:common.AddressLength])
|
|
|
|
copy(kk[common.AddressLength:], key[common.AddressLength+common.IncarnationLength:])
|
|
|
|
return kk
|
|
|
|
}
|
2020-05-23 09:19:56 +00:00
|
|
|
return key
|
|
|
|
}
|