2022-01-14 13:08:41 +00:00
package commands
import (
2022-03-17 20:16:02 +00:00
"fmt"
"github.com/ledgerwatch/erigon/cmd/devnettest/services"
2022-01-14 13:08:41 +00:00
"strings"
"github.com/ledgerwatch/erigon/cmd/devnettest/requests"
"github.com/ledgerwatch/erigon/common"
"github.com/spf13/cobra"
)
var (
offsetAddr string
quantity int
)
func init ( ) {
2022-03-31 12:40:09 +00:00
listStorageKeysCmd . Flags ( ) . StringVar ( & accountAddr , "addr" , "" , "String address to list keys" )
2022-01-14 13:08:41 +00:00
listStorageKeysCmd . MarkFlagRequired ( "addr" )
listStorageKeysCmd . Flags ( ) . StringVar ( & offsetAddr , "offset" , "" , "Offset storage key from which the batch should start" )
listStorageKeysCmd . Flags ( ) . IntVar ( & quantity , "quantity" , 10 , "Integer number of addresses to display in a batch" )
2022-02-08 13:02:18 +00:00
listStorageKeysCmd . Flags ( ) . StringVar ( & blockNum , "block" , "latest" , "Integer block number, or the string 'latest', 'earliest' or 'pending'; now only 'latest' is available" )
2022-01-14 13:08:41 +00:00
rootCmd . AddCommand ( listStorageKeysCmd )
}
var listStorageKeysCmd = & cobra . Command {
Use : "parity-list" ,
Short : "Returns all storage keys of the given address" ,
2022-02-08 13:02:18 +00:00
RunE : func ( cmd * cobra . Command , args [ ] string ) error {
2022-01-14 13:08:41 +00:00
if clearDev {
2022-03-17 20:16:02 +00:00
defer services . ClearDevDB ( )
2022-01-14 13:08:41 +00:00
}
2022-03-31 12:40:09 +00:00
if ! common . IsHexAddress ( accountAddr ) {
return fmt . Errorf ( "address: %v, is not a valid hex address\n" , accountAddr )
}
toAddress := common . HexToAddress ( accountAddr )
2022-01-14 13:08:41 +00:00
offset := common . Hex2Bytes ( strings . TrimSuffix ( offsetAddr , "0x" ) )
2022-03-17 20:16:02 +00:00
if err := requests . ParityList ( reqId , toAddress , quantity , offset , blockNum ) ; err != nil {
2022-03-18 11:57:23 +00:00
fmt . Printf ( "error getting parity list: %v\n" , err )
2022-03-17 20:16:02 +00:00
}
2022-02-08 13:02:18 +00:00
return nil
2022-01-14 13:08:41 +00:00
} ,
}