Skip to content

Commit

Permalink
rpc: update the xeth over RPC API to use the success/failure messages
Browse files Browse the repository at this point in the history
  • Loading branch information
karalabe committed Aug 17, 2015
1 parent f636754 commit 309788d
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions rpc/xeth.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,25 @@ func (self *Xeth) Call(method string, params []interface{}) (map[string]interfac
Method: method,
Params: data,
}
// Send the request over and process the response
// Send the request over and retrieve the response
if err := self.client.Send(req); err != nil {
return nil, err
}
res, err := self.client.Recv()
if err != nil {
return nil, err
}
value, ok := res.(map[string]interface{})
if !ok {
return nil, fmt.Errorf("Invalid response type: have %v, want %v", reflect.TypeOf(res), reflect.TypeOf(make(map[string]interface{})))
// Ensure the response is valid, and extract the results
success, isSuccessResponse := res.(*shared.SuccessResponse)
failure, isFailureResponse := res.(*shared.ErrorResponse)
switch {
case isFailureResponse:
return nil, fmt.Errorf("Method invocation failed: %v", failure.Error)

case isSuccessResponse:
return success.Result.(map[string]interface{}), nil

default:
return nil, fmt.Errorf("Invalid response type: %v", reflect.TypeOf(res))
}
return value, nil
}

0 comments on commit 309788d

Please sign in to comment.