Browse Source

rpc: myriad little fixes

pull/43/merge
Ethan Buchman 10 years ago
parent
commit
8fe1274323
4 changed files with 29 additions and 8 deletions
  1. +0
    -2
      rpc/client.go
  2. +2
    -2
      rpc/core/accounts.go
  3. +2
    -2
      rpc/http_server.go
  4. +25
    -2
      rpc/test/test.go

+ 0
- 2
rpc/client.go View File

@ -2,7 +2,6 @@ package rpc
import ( import (
"bytes" "bytes"
"encoding/hex"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/tendermint/tendermint2/binary" "github.com/tendermint/tendermint2/binary"
@ -10,7 +9,6 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"reflect" "reflect"
"strconv"
) )
type Response struct { type Response struct {


+ 2
- 2
rpc/core/accounts.go View File

@ -10,9 +10,9 @@ func GenPrivAccount() (*ResponseGenPrivAccount, error) {
return &ResponseGenPrivAccount{account.GenPrivAccount()}, nil return &ResponseGenPrivAccount{account.GenPrivAccount()}, nil
} }
func GetAccount(addr []byte) (*ResponseGetAccount, error) {
func GetAccount(address []byte) (*ResponseGetAccount, error) {
cache := mempoolReactor.Mempool.GetCache() cache := mempoolReactor.Mempool.GetCache()
return &ResponseGetAccount{cache.GetAccount(addr)}, nil
return &ResponseGetAccount{cache.GetAccount(address)}, nil
} }
func GetStorage(address, slot []byte) (*ResponseGetStorage, error) { func GetStorage(address, slot []byte) (*ResponseGetStorage, error) {


+ 2
- 2
rpc/http_server.go View File

@ -27,7 +27,7 @@ type RPCResponse struct {
Result interface{} `json:"result"` Result interface{} `json:"result"`
Error string `json:"error"` Error string `json:"error"`
Id string `json:"id"` Id string `json:"id"`
JSONRPC int `json:"jsonrpc"`
JSONRPC string `json:"jsonrpc"`
} }
func NewRPCResponse(res interface{}, err string) RPCResponse { func NewRPCResponse(res interface{}, err string) RPCResponse {
@ -38,7 +38,7 @@ func NewRPCResponse(res interface{}, err string) RPCResponse {
Result: res, Result: res,
Error: err, Error: err,
Id: "", Id: "",
JSONRPC: 2,
JSONRPC: "2.0",
} }
} }


+ 25
- 2
rpc/test/test.go View File

@ -3,7 +3,6 @@ package rpc
import ( import (
"bytes" "bytes"
"encoding/hex" "encoding/hex"
"encoding/json"
"github.com/tendermint/tendermint2/account" "github.com/tendermint/tendermint2/account"
"github.com/tendermint/tendermint2/binary" "github.com/tendermint/tendermint2/binary"
"github.com/tendermint/tendermint2/config" "github.com/tendermint/tendermint2/config"
@ -12,6 +11,7 @@ import (
"github.com/tendermint/tendermint2/p2p" "github.com/tendermint/tendermint2/p2p"
"github.com/tendermint/tendermint2/rpc" "github.com/tendermint/tendermint2/rpc"
"github.com/tendermint/tendermint2/rpc/core" "github.com/tendermint/tendermint2/rpc/core"
"github.com/tendermint/tendermint2/state"
"github.com/tendermint/tendermint2/types" "github.com/tendermint/tendermint2/types"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
@ -61,12 +61,35 @@ func init() {
app.Set("Log.Stdout.Level", "debug") app.Set("Log.Stdout.Level", "debug")
config.SetApp(app) config.SetApp(app)
logger.Reset() logger.Reset()
priv := state.LoadPrivValidator(rootDir + "/priv_validator.json")
priv.LastHeight = 0
priv.LastRound = 0
priv.LastStep = 0
priv.Save()
// start a node // start a node
ready := make(chan struct{}) ready := make(chan struct{})
go newNode(ready) go newNode(ready)
<-ready <-ready
} }
func getAccount(t *testing.T, typ string, addr []byte) *account.Account {
var client rpc.Client
switch typ {
case "JSONRPC":
client = rpc.NewClient(requestAddr, "JSONRPC")
case "HTTP":
client = rpc.NewClient(requestAddr, "HTTP")
}
ac, err := client.GetAccount(addr)
if err != nil {
t.Fatal(err)
}
return ac.Account
}
/*
func getAccount(t *testing.T, typ string, addr []byte) *account.Account { func getAccount(t *testing.T, typ string, addr []byte) *account.Account {
var resp *http.Response var resp *http.Response
var err error var err error
@ -107,7 +130,7 @@ func getAccount(t *testing.T, typ string, addr []byte) *account.Account {
t.Fatal(err) t.Fatal(err)
} }
return response.Result.Account return response.Result.Account
}
}*/
func makeSendTx(t *testing.T, typ string, from, to []byte, amt uint64) *types.SendTx { func makeSendTx(t *testing.T, typ string, from, to []byte, amt uint64) *types.SendTx {
acc := getAccount(t, typ, from) acc := getAccount(t, typ, from)


Loading…
Cancel
Save