2020-02-06 04:08:36 +00:00
|
|
|
package dbutils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/binary"
|
2020-08-21 06:32:11 +00:00
|
|
|
|
2022-11-20 03:58:20 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/common/length"
|
2020-02-06 04:08:36 +00:00
|
|
|
)
|
|
|
|
|
2021-05-31 16:29:55 +00:00
|
|
|
func AccountIndexChunkKey(key []byte, blockNumber uint64) []byte {
|
2022-11-20 03:58:20 +00:00
|
|
|
blockNumBytes := make([]byte, length.Addr+8)
|
2021-05-31 16:29:55 +00:00
|
|
|
copy(blockNumBytes, key)
|
2022-11-20 03:58:20 +00:00
|
|
|
binary.BigEndian.PutUint64(blockNumBytes[length.Addr:], 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
|
2022-11-20 03:58:20 +00:00
|
|
|
blockNumBytes := make([]byte, length.Addr+length.Hash+8)
|
|
|
|
copy(blockNumBytes, key[:length.Addr])
|
|
|
|
copy(blockNumBytes[length.Addr:], key[length.Addr+length.Incarnation:])
|
|
|
|
binary.BigEndian.PutUint64(blockNumBytes[length.Addr+length.Hash:], 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 {
|
2022-11-20 03:58:20 +00:00
|
|
|
if len(key) == length.Hash*2+length.Incarnation {
|
|
|
|
kk := make([]byte, length.Hash*2)
|
|
|
|
copy(kk, key[:length.Hash])
|
|
|
|
copy(kk[length.Hash:], key[length.Hash+length.Incarnation:])
|
2020-05-23 09:19:56 +00:00
|
|
|
return kk
|
|
|
|
}
|
2022-11-20 03:58:20 +00:00
|
|
|
if len(key) == length.Addr+length.Hash+length.Incarnation {
|
|
|
|
kk := make([]byte, length.Addr+length.Hash)
|
|
|
|
copy(kk, key[:length.Addr])
|
|
|
|
copy(kk[length.Addr:], key[length.Addr+length.Incarnation:])
|
2020-05-31 06:57:47 +00:00
|
|
|
return kk
|
|
|
|
}
|
2020-05-23 09:19:56 +00:00
|
|
|
return key
|
|
|
|
}
|