aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-08-17 19:04:20 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-08-17 19:04:20 +0800
commit309788de37505253293416c3323962f9a16bbd07 (patch)
treebcdc48332beb6e7f9f1d3e56ed9898f5ffd18f44
parentf6367548e4a28fcadbb6f669aa39d27109c07a56 (diff)
downloaddexon-309788de37505253293416c3323962f9a16bbd07.tar.gz
dexon-309788de37505253293416c3323962f9a16bbd07.tar.zst
dexon-309788de37505253293416c3323962f9a16bbd07.zip
rpc: update the xeth over RPC API to use the success/failure messages
-rw-r--r--rpc/xeth.go18
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
}