mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-24 20:47:16 +00:00
1dcc2b141a
* share config object * create default config and logger * move db connection to common func * move server start to cli package * clear * clear * rename cli to rpc * use unified SetupLogger func * make all root flag persistent * use common flags in different packages * use common flags in different packages * move TraceTx method to eth package * use native slice flags * create package "turbo" * disable geth api * disable geth api * move more data types to turbo/adapter package * add support for customApiList * run more * run more * run more * dog-food * move DoCall * move DoCall * fix tests * fix test
48 lines
1.5 KiB
Go
48 lines
1.5 KiB
Go
package commands
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/holiman/uint256"
|
|
"github.com/ledgerwatch/turbo-geth/common"
|
|
"github.com/ledgerwatch/turbo-geth/turbo/adapter"
|
|
)
|
|
|
|
// StorageRangeResult is the result of a debug_storageRangeAt API call.
|
|
type StorageRangeResult struct {
|
|
Storage StorageMap `json:"storage"`
|
|
NextKey *common.Hash `json:"nextKey"` // nil if Storage includes the last key in the trie.
|
|
}
|
|
|
|
type StorageMap map[common.Hash]StorageEntry
|
|
|
|
type StorageEntry struct {
|
|
Key *common.Hash `json:"key"`
|
|
Value common.Hash `json:"value"`
|
|
}
|
|
|
|
func StorageRangeAt(stateReader *adapter.StateReader, contractAddress common.Address, start []byte, maxResult int) (StorageRangeResult, error) {
|
|
//account, err := stateReader.ReadAccountData(contractAddress)
|
|
//if err != nil {
|
|
// return StorageRangeResult{}, fmt.Errorf("error reading account %x: %v", contractAddress, err)
|
|
//}
|
|
//if account == nil {
|
|
// return StorageRangeResult{}, fmt.Errorf("account %x doesn't exist", contractAddress)
|
|
//}
|
|
result := StorageRangeResult{Storage: StorageMap{}}
|
|
resultCount := 0
|
|
|
|
if err := stateReader.ForEachStorage(contractAddress, start, func(key, seckey common.Hash, value uint256.Int) bool {
|
|
if resultCount < maxResult {
|
|
result.Storage[seckey] = StorageEntry{Key: &key, Value: value.Bytes32()}
|
|
} else {
|
|
result.NextKey = &key
|
|
}
|
|
resultCount++
|
|
return resultCount <= maxResult
|
|
}, maxResult+1); err != nil {
|
|
return StorageRangeResult{}, fmt.Errorf("error walking over storage: %v", err)
|
|
}
|
|
return result, nil
|
|
}
|