rpc-gen update
This commit is contained in:
parent
41502e05c1
commit
293aa31f64
|
@ -16,21 +16,25 @@ import (
|
||||||
|
|
||||||
// maps camel-case function names to lower case rpc version
|
// maps camel-case function names to lower case rpc version
|
||||||
var reverseFuncMap = map[string]string{
|
var reverseFuncMap = map[string]string{
|
||||||
"Status": "status",
|
"Status": "status",
|
||||||
"NetInfo": "net_info",
|
"NetInfo": "net_info",
|
||||||
"BlockchainInfo": "blockchain",
|
"BlockchainInfo": "blockchain",
|
||||||
"GetBlock": "get_block",
|
"Genesis": "genesis",
|
||||||
"GetAccount": "get_account",
|
"GetBlock": "get_block",
|
||||||
"GetStorage": "get_storage",
|
"GetAccount": "get_account",
|
||||||
"Call": "call",
|
"GetStorage": "get_storage",
|
||||||
"CallCode": "call_code",
|
"Call": "call",
|
||||||
"ListValidators": "list_validators",
|
"CallCode": "call_code",
|
||||||
"DumpStorage": "dump_storage",
|
"ListValidators": "list_validators",
|
||||||
"BroadcastTx": "broadcast_tx",
|
"DumpConsensusState": "dump_consensus_state",
|
||||||
"ListAccounts": "list_accounts",
|
"DumpStorage": "dump_storage",
|
||||||
"NameRegEntry": "name_reg_entry",
|
"BroadcastTx": "broadcast_tx",
|
||||||
"GenPrivAccount": "unsafe/gen_priv_account",
|
"ListUnconfirmedTxs": "list_unconfirmed_txs",
|
||||||
"SignTx": "unsafe/sign_tx",
|
"ListAccounts": "list_accounts",
|
||||||
|
"GetName": "get_name",
|
||||||
|
"ListNames": "list_names",
|
||||||
|
"GenPrivAccount": "unsafe/gen_priv_account",
|
||||||
|
"SignTx": "unsafe/sign_tx",
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -24,11 +24,12 @@ type Client interface {
|
||||||
Genesis() (*string, error)
|
Genesis() (*string, error)
|
||||||
GetAccount(address []byte) (*ctypes.ResponseGetAccount, error)
|
GetAccount(address []byte) (*ctypes.ResponseGetAccount, error)
|
||||||
GetBlock(height uint) (*ctypes.ResponseGetBlock, error)
|
GetBlock(height uint) (*ctypes.ResponseGetBlock, error)
|
||||||
|
GetName(name string) (*types.NameRegEntry, error)
|
||||||
GetStorage(address []byte, key []byte) (*ctypes.ResponseGetStorage, error)
|
GetStorage(address []byte, key []byte) (*ctypes.ResponseGetStorage, error)
|
||||||
ListAccounts() (*ctypes.ResponseListAccounts, error)
|
ListAccounts() (*ctypes.ResponseListAccounts, error)
|
||||||
|
ListNames() (*ctypes.ResponseListNames, error)
|
||||||
ListUnconfirmedTxs() (*ctypes.ResponseListUnconfirmedTxs, error)
|
ListUnconfirmedTxs() (*ctypes.ResponseListUnconfirmedTxs, error)
|
||||||
ListValidators() (*ctypes.ResponseListValidators, error)
|
ListValidators() (*ctypes.ResponseListValidators, error)
|
||||||
NameRegEntry(name string) (*ctypes.ResponseNameRegEntry, error)
|
|
||||||
NetInfo() (*ctypes.ResponseNetInfo, error)
|
NetInfo() (*ctypes.ResponseNetInfo, error)
|
||||||
SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*ctypes.ResponseSignTx, error)
|
SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*ctypes.ResponseSignTx, error)
|
||||||
Status() (*ctypes.ResponseStatus, error)
|
Status() (*ctypes.ResponseStatus, error)
|
||||||
|
@ -334,6 +335,36 @@ func (c *ClientHTTP) GetBlock(height uint) (*ctypes.ResponseGetBlock, error) {
|
||||||
return response.Result, nil
|
return response.Result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *ClientHTTP) GetName(name string) (*types.NameRegEntry, error) {
|
||||||
|
values, err := argsToURLValues([]string{"name"}, name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err := http.PostForm(c.addr+reverseFuncMap["GetName"], 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 *types.NameRegEntry `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) GetStorage(address []byte, key []byte) (*ctypes.ResponseGetStorage, error) {
|
func (c *ClientHTTP) GetStorage(address []byte, key []byte) (*ctypes.ResponseGetStorage, error) {
|
||||||
values, err := argsToURLValues([]string{"address", "key"}, address, key)
|
values, err := argsToURLValues([]string{"address", "key"}, address, key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -394,6 +425,36 @@ func (c *ClientHTTP) ListAccounts() (*ctypes.ResponseListAccounts, error) {
|
||||||
return response.Result, nil
|
return response.Result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *ClientHTTP) ListNames() (*ctypes.ResponseListNames, error) {
|
||||||
|
values, err := argsToURLValues(nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err := http.PostForm(c.addr+reverseFuncMap["ListNames"], 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.ResponseListNames `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) ListUnconfirmedTxs() (*ctypes.ResponseListUnconfirmedTxs, error) {
|
func (c *ClientHTTP) ListUnconfirmedTxs() (*ctypes.ResponseListUnconfirmedTxs, error) {
|
||||||
values, err := argsToURLValues(nil)
|
values, err := argsToURLValues(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -454,36 +515,6 @@ func (c *ClientHTTP) ListValidators() (*ctypes.ResponseListValidators, error) {
|
||||||
return response.Result, nil
|
return response.Result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientHTTP) NameRegEntry(name string) (*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) {
|
func (c *ClientHTTP) NetInfo() (*ctypes.ResponseNetInfo, error) {
|
||||||
values, err := argsToURLValues(nil)
|
values, err := argsToURLValues(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -844,6 +875,33 @@ func (c *ClientJSON) GetBlock(height uint) (*ctypes.ResponseGetBlock, error) {
|
||||||
return response.Result, nil
|
return response.Result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *ClientJSON) GetName(name string) (*types.NameRegEntry, error) {
|
||||||
|
request := rpctypes.RPCRequest{
|
||||||
|
JSONRPC: "2.0",
|
||||||
|
Method: reverseFuncMap["GetName"],
|
||||||
|
Params: []interface{}{name},
|
||||||
|
Id: 0,
|
||||||
|
}
|
||||||
|
body, err := c.RequestResponse(request)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var response struct {
|
||||||
|
Result *types.NameRegEntry `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) GetStorage(address []byte, key []byte) (*ctypes.ResponseGetStorage, error) {
|
func (c *ClientJSON) GetStorage(address []byte, key []byte) (*ctypes.ResponseGetStorage, error) {
|
||||||
request := rpctypes.RPCRequest{
|
request := rpctypes.RPCRequest{
|
||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
|
@ -898,6 +956,33 @@ func (c *ClientJSON) ListAccounts() (*ctypes.ResponseListAccounts, error) {
|
||||||
return response.Result, nil
|
return response.Result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *ClientJSON) ListNames() (*ctypes.ResponseListNames, error) {
|
||||||
|
request := rpctypes.RPCRequest{
|
||||||
|
JSONRPC: "2.0",
|
||||||
|
Method: reverseFuncMap["ListNames"],
|
||||||
|
Params: []interface{}{},
|
||||||
|
Id: 0,
|
||||||
|
}
|
||||||
|
body, err := c.RequestResponse(request)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var response struct {
|
||||||
|
Result *ctypes.ResponseListNames `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) ListUnconfirmedTxs() (*ctypes.ResponseListUnconfirmedTxs, error) {
|
func (c *ClientJSON) ListUnconfirmedTxs() (*ctypes.ResponseListUnconfirmedTxs, error) {
|
||||||
request := rpctypes.RPCRequest{
|
request := rpctypes.RPCRequest{
|
||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
|
@ -952,33 +1037,6 @@ func (c *ClientJSON) ListValidators() (*ctypes.ResponseListValidators, error) {
|
||||||
return response.Result, nil
|
return response.Result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientJSON) NameRegEntry(name string) (*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) {
|
func (c *ClientJSON) NetInfo() (*ctypes.ResponseNetInfo, error) {
|
||||||
request := rpctypes.RPCRequest{
|
request := rpctypes.RPCRequest{
|
||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
|
|
|
@ -212,11 +212,11 @@ func callContract(t *testing.T, client cclient.Client, address, data, expected [
|
||||||
// get the namereg entry
|
// get the namereg entry
|
||||||
func getNameRegEntry(t *testing.T, typ string, name string) *types.NameRegEntry {
|
func getNameRegEntry(t *testing.T, typ string, name string) *types.NameRegEntry {
|
||||||
client := clients[typ]
|
client := clients[typ]
|
||||||
r, err := client.NameRegEntry(name)
|
entry, err := client.GetName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
return r.Entry
|
return entry
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue