Skip to content

Commit

Permalink
Add support for CodeAt
Browse files Browse the repository at this point in the history
  • Loading branch information
tgerring committed Jan 13, 2015
1 parent b178414 commit 961e4da
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
8 changes: 6 additions & 2 deletions rpc/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ func (self jsonWrapper) GetRequestReply(xeth *EthereumApi, req *RpcRequest, repl
return err
}
return xeth.GetTxCountAt(args, reply)
// case "eth_codeAt":
// return nil
case "eth_codeAt":
args, err := req.ToGetCodeAtArgs()
if err != nil {
return err
}
return xeth.GetCodeAt(args, reply)
case "eth_balanceAt":
args, err := req.ToGetBalanceArgs()
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions rpc/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,21 @@ func (req *RpcRequest) ToGetBalanceArgs() (*GetBalanceArgs, error) {
return args, nil
}

func (req *RpcRequest) ToGetCodeAtArgs() (*GetCodeAtArgs, error) {
if len(req.Params) < 1 {
return nil, NewErrorResponse(ErrorArguments)
}

args := new(GetCodeAtArgs)
r := bytes.NewReader(req.Params[0])
err := json.NewDecoder(r).Decode(args)
if err != nil {
return nil, NewErrorResponse(ErrorDecodeArgs)
}
jsonlogger.DebugDetailf("%T %v", args, args)
return args, nil
}

// func NewSuccessRes(object JsonResponse) string {
// e := SuccessRes{Error: false, Result: object}
// res, err := json.Marshal(e)
Expand Down
37 changes: 37 additions & 0 deletions rpc/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ func (p *EthereumApi) GetBalanceAt(args *GetBalanceArgs, reply *interface{}) err
return nil
}

func (p *EthereumApi) GetCodeAt(args *GetCodeAtArgs, reply *interface{}) error {
err := args.requirements()
if err != nil {
return err
}
*reply = p.pipe.CodeAt(args.Address)
return nil
}

type GetBlockArgs struct {
BlockNumber int32
Hash string
Expand Down Expand Up @@ -236,6 +245,15 @@ type GetStorageArgs struct {
Key string
}

func (obj *GetStorageArgs) UnmarshalJSON(b []byte) (err error) {
arg0 := ""
if err = json.Unmarshal(b, arg0); err == nil {
obj.Address = arg0
return
}
return NewErrorResponse(ErrorDecodeArgs)
}

func (a *GetStorageArgs) requirements() error {
if a.Address == "" {
return NewErrorResponse("GetStorageAt requires an 'address' value as argument")
Expand Down Expand Up @@ -316,3 +334,22 @@ type BalanceRes struct {
Balance string `json:"balance"`
Address string `json:"address"`
}
type GetCodeAtArgs struct {
Address string
}

func (obj *GetCodeAtArgs) UnmarshalJSON(b []byte) (err error) {
arg0 := ""
if err = json.Unmarshal(b, &arg0); err == nil {
obj.Address = arg0
return
}
return NewErrorResponse(ErrorDecodeArgs)
}

func (a *GetCodeAtArgs) requirements() error {
if a.Address == "" {
return NewErrorResponse("GetCodeAt requires an 'address' value as argument")
}
return nil
}

0 comments on commit 961e4da

Please sign in to comment.