Support hex and decimal keys for GetStorageAt RPC. Fixes ethereum/go-ethereum#74

This commit is contained in:
Maran 2014-06-24 11:15:26 +02:00
parent 614624754d
commit 0c55a11318
1 changed files with 10 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import (
"github.com/ethereum/eth-go/ethpub" "github.com/ethereum/eth-go/ethpub"
"github.com/ethereum/eth-go/ethutil" "github.com/ethereum/eth-go/ethutil"
"math/big" "math/big"
"strings"
) )
type EthereumApi struct { type EthereumApi struct {
@ -174,9 +175,15 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageArgs, reply *string) error {
return err return err
} }
state := p.ethp.GetStateObject(args.Address) state := p.ethp.GetStateObject(args.Address)
var hx string
if strings.Index(args.Key, "0x") == 0 {
hx = string([]byte(args.Key)[2:])
} else {
// Convert the incoming string (which is a bigint) into hex // Convert the incoming string (which is a bigint) into hex
i, _ := new(big.Int).SetString(args.Key, 10) i, _ := new(big.Int).SetString(args.Key, 10)
hx := ethutil.Hex(i.Bytes()) hx = ethutil.Hex(i.Bytes())
}
value := state.GetStorage(hx) value := state.GetStorage(hx)
*reply = NewSuccessRes(GetStorageAtRes{Address: args.Address, Key: args.Key, Value: value}) *reply = NewSuccessRes(GetStorageAtRes{Address: args.Address, Key: args.Key, Value: value})
return nil return nil