mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-11 10:36:18 +00:00
namereg rpc and tests
This commit is contained in:
@@ -5,8 +5,6 @@ import (
|
||||
"fmt"
|
||||
"github.com/tendermint/tendermint/binary"
|
||||
rpctypes "github.com/tendermint/tendermint/rpc/types"
|
||||
// NOTE: do not import rpc/core.
|
||||
// What kind of client imports all of core logic? :P
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -30,6 +28,7 @@ var reverseFuncMap = map[string]string{
|
||||
"DumpStorage": "dump_storage",
|
||||
"BroadcastTx": "broadcast_tx",
|
||||
"ListAccounts": "list_accounts",
|
||||
"NameRegEntry": "name_reg_entry",
|
||||
"GenPrivAccount": "unsafe/gen_priv_account",
|
||||
"SignTx": "unsafe/sign_tx",
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ type Client interface {
|
||||
ListAccounts() (*ctypes.ResponseListAccounts, error)
|
||||
ListUnconfirmedTxs() (*ctypes.ResponseListUnconfirmedTxs, error)
|
||||
ListValidators() (*ctypes.ResponseListValidators, error)
|
||||
NameRegEntry(name []byte) (*ctypes.ResponseNameRegEntry, error)
|
||||
NetInfo() (*ctypes.ResponseNetInfo, error)
|
||||
SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*ctypes.ResponseSignTx, error)
|
||||
Status() (*ctypes.ResponseStatus, error)
|
||||
@@ -453,6 +454,36 @@ func (c *ClientHTTP) ListValidators() (*ctypes.ResponseListValidators, error) {
|
||||
return response.Result, nil
|
||||
}
|
||||
|
||||
func (c *ClientHTTP) NameRegEntry(name []byte) (*ctypes.ResponseNameRegEntry, error) {
|
||||
values, err := argsToURLValues([]string{"name"}, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := http.PostForm(c.addr+reverseFuncMap["NameRegEntry"], values)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response struct {
|
||||
Result *ctypes.ResponseNameRegEntry `json:"result"`
|
||||
Error string `json:"error"`
|
||||
Id string `json:"id"`
|
||||
JSONRPC string `json:"jsonrpc"`
|
||||
}
|
||||
binary.ReadJSON(&response, body, &err)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if response.Error != "" {
|
||||
return nil, fmt.Errorf(response.Error)
|
||||
}
|
||||
return response.Result, nil
|
||||
}
|
||||
|
||||
func (c *ClientHTTP) NetInfo() (*ctypes.ResponseNetInfo, error) {
|
||||
values, err := argsToURLValues(nil)
|
||||
if err != nil {
|
||||
@@ -921,6 +952,33 @@ func (c *ClientJSON) ListValidators() (*ctypes.ResponseListValidators, error) {
|
||||
return response.Result, nil
|
||||
}
|
||||
|
||||
func (c *ClientJSON) NameRegEntry(name []byte) (*ctypes.ResponseNameRegEntry, error) {
|
||||
request := rpctypes.RPCRequest{
|
||||
JSONRPC: "2.0",
|
||||
Method: reverseFuncMap["NameRegEntry"],
|
||||
Params: []interface{}{name},
|
||||
Id: 0,
|
||||
}
|
||||
body, err := c.RequestResponse(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response struct {
|
||||
Result *ctypes.ResponseNameRegEntry `json:"result"`
|
||||
Error string `json:"error"`
|
||||
Id string `json:"id"`
|
||||
JSONRPC string `json:"jsonrpc"`
|
||||
}
|
||||
binary.ReadJSON(&response, body, &err)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if response.Error != "" {
|
||||
return nil, fmt.Errorf(response.Error)
|
||||
}
|
||||
return response.Result, nil
|
||||
}
|
||||
|
||||
func (c *ClientJSON) NetInfo() (*ctypes.ResponseNetInfo, error) {
|
||||
request := rpctypes.RPCRequest{
|
||||
JSONRPC: "2.0",
|
||||
|
||||
Reference in New Issue
Block a user