diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-08-18 02:47:55 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-08-18 02:47:55 +0800 |
commit | 36081505c4b258400756ad004f986d638e0e8156 (patch) | |
tree | 6e438e7d49188f71444c88db03805035b2d5b050 /rpc | |
parent | 2497f28aa9d74f84468055fbc4675f379b7e4a5a (diff) | |
parent | 309788de37505253293416c3323962f9a16bbd07 (diff) | |
download | go-tangerine-36081505c4b258400756ad004f986d638e0e8156.tar.gz go-tangerine-36081505c4b258400756ad004f986d638e0e8156.tar.zst go-tangerine-36081505c4b258400756ad004f986d638e0e8156.zip |
Merge pull request #1673 from karalabe/fix-api-xeth-responses
rpc: update the xeth over RPC API to use the success/failure messages
Diffstat (limited to 'rpc')
-rw-r--r-- | rpc/xeth.go | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/rpc/xeth.go b/rpc/xeth.go index 65a1edeb8..9527a96c0 100644 --- a/rpc/xeth.go +++ b/rpc/xeth.go @@ -53,7 +53,7 @@ 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 } @@ -61,9 +61,17 @@ func (self *Xeth) Call(method string, params []interface{}) (map[string]interfac 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 } |