Encode watched address path bytes to hex for comparison

This commit is contained in:
Prathamesh Musale 2022-06-16 18:32:30 +05:30 committed by nabarun
parent 4c6a521139
commit 038b25a41d
3 changed files with 15 additions and 2 deletions

View File

@ -159,7 +159,8 @@ func (c *FileConfig) Init() error {
func (c *ServiceConfig) Init() error { func (c *ServiceConfig) Init() error {
viper.BindEnv(SNAPSHOT_ACCOUNTS_TOML, SNAPSHOT_ACCOUNTS) viper.BindEnv(SNAPSHOT_ACCOUNTS_TOML, SNAPSHOT_ACCOUNTS)
allowedAccounts := viper.GetStringSlice(SNAPSHOT_ACCOUNTS) var allowedAccounts []string
viper.UnmarshalKey(SNAPSHOT_ACCOUNTS_TOML, &allowedAccounts)
accountsLen := len(allowedAccounts) accountsLen := len(allowedAccounts)
if accountsLen != 0 { if accountsLen != 0 {
c.AllowedAccounts = make(map[common.Address]struct{}, accountsLen) c.AllowedAccounts = make(map[common.Address]struct{}, accountsLen)

View File

@ -87,7 +87,7 @@ type SnapshotParams struct {
func (s *Service) CreateSnapshot(params SnapshotParams) error { func (s *Service) CreateSnapshot(params SnapshotParams) error {
paths := make([][]byte, 0, len(params.WatchedAddresses)) paths := make([][]byte, 0, len(params.WatchedAddresses))
for addr := range params.WatchedAddresses { for addr := range params.WatchedAddresses {
paths = append(paths, crypto.Keccak256(addr.Bytes())) paths = append(paths, keybytesToHex(crypto.Keccak256(addr.Bytes())))
} }
s.watchingAddresses = len(paths) > 0 s.watchingAddresses = len(paths) > 0
// extract header from lvldb and publish to PG-IPFS // extract header from lvldb and publish to PG-IPFS

View File

@ -51,3 +51,15 @@ func decrementPath(path []byte) bool {
} }
return true return true
} }
// https://github.com/ethereum/go-ethereum/blob/master/trie/encoding.go#L97
func keybytesToHex(str []byte) []byte {
l := len(str)*2 + 1
var nibbles = make([]byte, l)
for i, b := range str {
nibbles[i*2] = b / 16
nibbles[i*2+1] = b % 16
}
nibbles[l-1] = 16
return nibbles
}