Skip to content

Commit

Permalink
rpc: add jsonrpc version to module request, use json types
Browse files Browse the repository at this point in the history
  • Loading branch information
karalabe committed Feb 4, 2016
1 parent 3274db1 commit 6b939fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
3 changes: 1 addition & 2 deletions eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import (
"sync"
"time"

"gopkg.in/fatih/set.v0"

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

const (
Expand Down
16 changes: 7 additions & 9 deletions rpc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,29 +218,27 @@ func newSubscriptionId() (string, error) {
// SupportedModules returns the collection of API's that the RPC server offers
// on which the given client connects.
func SupportedModules(client Client) (map[string]string, error) {
req := map[string]interface{}{
"id": 1,
"method": "rpc_modules",
req := JSONRequest{
Id: new(int64),
Version: "2.0",
Method: "rpc_modules",
}

if err := client.Send(req); err != nil {
return nil, err
}

var response map[string]interface{}
var response JSONSuccessResponse
if err := client.Recv(&response); err != nil {
return nil, err
}

if payload, ok := response["result"]; ok {
if response.Result != nil {
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 {
mods[m] = fmt.Sprintf("%s", v)
}
return mods, nil
}
}

return nil, fmt.Errorf("unable to retrieve modules")
}

0 comments on commit 6b939fb

Please sign in to comment.