Merge pull request #2171 from karalabe/rpc-modules-fix

rpc: add jsonrpc version to module request, use json types
This commit is contained in:
Péter Szilágyi 2016-02-05 11:33:10 +02:00
commit 2128289631
2 changed files with 8 additions and 11 deletions

View File

@ -27,8 +27,6 @@ import (
"sync" "sync"
"time" "time"
"gopkg.in/fatih/set.v0"
"github.com/ethereum/ethash" "github.com/ethereum/ethash"
"github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
@ -46,6 +44,7 @@ import (
"github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
"gopkg.in/fatih/set.v0"
) )
const ( const (

View File

@ -218,29 +218,27 @@ func newSubscriptionId() (string, error) {
// SupportedModules returns the collection of API's that the RPC server offers // SupportedModules returns the collection of API's that the RPC server offers
// on which the given client connects. // on which the given client connects.
func SupportedModules(client Client) (map[string]string, error) { func SupportedModules(client Client) (map[string]string, error) {
req := map[string]interface{}{ req := JSONRequest{
"id": 1, Id: new(int64),
"method": "rpc_modules", Version: "2.0",
Method: "rpc_modules",
} }
if err := client.Send(req); err != nil { if err := client.Send(req); err != nil {
return nil, err return nil, err
} }
var response map[string]interface{} var response JSONSuccessResponse
if err := client.Recv(&response); err != nil { if err := client.Recv(&response); err != nil {
return nil, err return nil, err
} }
if response.Result != nil {
if payload, ok := response["result"]; ok {
mods := make(map[string]string) mods := make(map[string]string)
if modules, ok := payload.(map[string]interface{}); ok { if modules, ok := response.Result.(map[string]interface{}); ok {
for m, v := range modules { for m, v := range modules {
mods[m] = fmt.Sprintf("%s", v) mods[m] = fmt.Sprintf("%s", v)
} }
return mods, nil return mods, nil
} }
} }
return nil, fmt.Errorf("unable to retrieve modules") return nil, fmt.Errorf("unable to retrieve modules")
} }