Skip to content

Commit

Permalink
Support hex and decimal keys for GetStorageAt RPC. Fixes #74
Browse files Browse the repository at this point in the history
  • Loading branch information
Maran committed Jun 24, 2014
1 parent 6146247 commit 0c55a11
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions ethrpc/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/ethereum/eth-go/ethpub"
"github.com/ethereum/eth-go/ethutil"
"math/big"
"strings"
)

type EthereumApi struct {
Expand Down Expand Up @@ -174,9 +175,15 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageArgs, reply *string) error {
return err
}
state := p.ethp.GetStateObject(args.Address)
// Convert the incoming string (which is a bigint) into hex
i, _ := new(big.Int).SetString(args.Key, 10)
hx := ethutil.Hex(i.Bytes())

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
i, _ := new(big.Int).SetString(args.Key, 10)
hx = ethutil.Hex(i.Bytes())
}
value := state.GetStorage(hx)
*reply = NewSuccessRes(GetStorageAtRes{Address: args.Address, Key: args.Key, Value: value})
return nil
Expand Down

0 comments on commit 0c55a11

Please sign in to comment.