2015-04-07 11:44:25 -07:00
|
|
|
package core_client
|
2015-04-01 04:12:34 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-04-01 17:30:16 -07:00
|
|
|
"github.com/tendermint/tendermint/account"
|
|
|
|
"github.com/tendermint/tendermint/binary"
|
2015-04-07 11:44:25 -07:00
|
|
|
"github.com/tendermint/tendermint/rpc"
|
|
|
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
2015-04-01 17:30:16 -07:00
|
|
|
"github.com/tendermint/tendermint/types"
|
2015-04-01 04:12:34 -07:00
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Client interface {
|
2015-04-07 11:44:25 -07:00
|
|
|
BlockchainInfo(minHeight uint) (*ctypes.ResponseBlockchainInfo, error)
|
|
|
|
BroadcastTx(tx types.Tx) (*ctypes.ResponseBroadcastTx, error)
|
|
|
|
Call(address []byte) (*ctypes.ResponseCall, error)
|
|
|
|
DumpStorage(addr []byte) (*ctypes.ResponseDumpStorage, error)
|
|
|
|
GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error)
|
|
|
|
GetAccount(address []byte) (*ctypes.ResponseGetAccount, error)
|
|
|
|
GetBlock(height uint) (*ctypes.ResponseGetBlock, error)
|
|
|
|
GetStorage(address []byte) (*ctypes.ResponseGetStorage, error)
|
|
|
|
ListAccounts() (*ctypes.ResponseListAccounts, error)
|
|
|
|
ListValidators() (*ctypes.ResponseListValidators, error)
|
|
|
|
NetInfo() (*ctypes.ResponseNetInfo, error)
|
|
|
|
SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*ctypes.ResponseSignTx, error)
|
|
|
|
Status() (*ctypes.ResponseStatus, error)
|
2015-04-01 04:12:34 -07:00
|
|
|
}
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func (c *ClientHTTP) BlockchainInfo(minHeight uint) (*ctypes.ResponseBlockchainInfo, error) {
|
2015-04-01 13:23:20 -07:00
|
|
|
values, err := argsToURLValues([]string{"minHeight"}, minHeight)
|
2015-04-01 04:12:34 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-04-01 13:23:20 -07:00
|
|
|
resp, err := http.PostForm(c.addr+"blockchain_info", values)
|
2015-04-01 04:12:34 -07:00
|
|
|
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 {
|
2015-04-07 11:44:25 -07:00
|
|
|
Result *ctypes.ResponseBlockchainInfo `json:"result"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
2015-04-01 04:12:34 -07:00
|
|
|
}
|
|
|
|
binary.ReadJSON(&response, body, &err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if response.Error != "" {
|
|
|
|
return nil, fmt.Errorf(response.Error)
|
|
|
|
}
|
|
|
|
return response.Result, nil
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func (c *ClientHTTP) BroadcastTx(tx types.Tx) (*ctypes.ResponseBroadcastTx, error) {
|
2015-04-01 13:23:20 -07:00
|
|
|
values, err := argsToURLValues([]string{"tx"}, tx)
|
2015-04-01 04:12:34 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-04-01 13:23:20 -07:00
|
|
|
resp, err := http.PostForm(c.addr+"broadcast_tx", values)
|
2015-04-01 04:12:34 -07:00
|
|
|
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 {
|
2015-04-07 11:44:25 -07:00
|
|
|
Result *ctypes.ResponseBroadcastTx `json:"result"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
2015-04-01 04:12:34 -07:00
|
|
|
}
|
|
|
|
binary.ReadJSON(&response, body, &err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if response.Error != "" {
|
|
|
|
return nil, fmt.Errorf(response.Error)
|
|
|
|
}
|
|
|
|
return response.Result, nil
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func (c *ClientHTTP) Call(address []byte) (*ctypes.ResponseCall, error) {
|
2015-04-01 13:23:20 -07:00
|
|
|
values, err := argsToURLValues([]string{"address"}, address)
|
2015-04-01 04:12:34 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-04-01 13:23:20 -07:00
|
|
|
resp, err := http.PostForm(c.addr+"call", values)
|
2015-04-01 04:12:34 -07:00
|
|
|
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 {
|
2015-04-07 11:44:25 -07:00
|
|
|
Result *ctypes.ResponseCall `json:"result"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
2015-04-01 04:12:34 -07:00
|
|
|
}
|
|
|
|
binary.ReadJSON(&response, body, &err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if response.Error != "" {
|
|
|
|
return nil, fmt.Errorf(response.Error)
|
|
|
|
}
|
|
|
|
return response.Result, nil
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func (c *ClientHTTP) DumpStorage(addr []byte) (*ctypes.ResponseDumpStorage, error) {
|
2015-04-01 13:23:20 -07:00
|
|
|
values, err := argsToURLValues([]string{"addr"}, addr)
|
2015-04-01 04:12:34 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-04-01 13:23:20 -07:00
|
|
|
resp, err := http.PostForm(c.addr+"dump_storage", values)
|
2015-04-01 04:12:34 -07:00
|
|
|
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 {
|
2015-04-07 11:44:25 -07:00
|
|
|
Result *ctypes.ResponseDumpStorage `json:"result"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
2015-04-01 04:12:34 -07:00
|
|
|
}
|
|
|
|
binary.ReadJSON(&response, body, &err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if response.Error != "" {
|
|
|
|
return nil, fmt.Errorf(response.Error)
|
|
|
|
}
|
|
|
|
return response.Result, nil
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func (c *ClientHTTP) GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error) {
|
2015-04-01 13:23:20 -07:00
|
|
|
values, err := argsToURLValues(nil, nil)
|
2015-04-01 04:12:34 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-04-01 13:23:20 -07:00
|
|
|
resp, err := http.PostForm(c.addr+"gen_priv_account", values)
|
2015-04-01 04:12:34 -07:00
|
|
|
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 {
|
2015-04-07 11:44:25 -07:00
|
|
|
Result *ctypes.ResponseGenPrivAccount `json:"result"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
2015-04-01 04:12:34 -07:00
|
|
|
}
|
|
|
|
binary.ReadJSON(&response, body, &err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if response.Error != "" {
|
|
|
|
return nil, fmt.Errorf(response.Error)
|
|
|
|
}
|
|
|
|
return response.Result, nil
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func (c *ClientHTTP) GetAccount(address []byte) (*ctypes.ResponseGetAccount, error) {
|
2015-04-01 13:23:20 -07:00
|
|
|
values, err := argsToURLValues([]string{"address"}, address)
|
2015-04-01 04:12:34 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-04-01 13:23:20 -07:00
|
|
|
resp, err := http.PostForm(c.addr+"get_account", values)
|
2015-04-01 04:12:34 -07:00
|
|
|
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 {
|
2015-04-07 11:44:25 -07:00
|
|
|
Result *ctypes.ResponseGetAccount `json:"result"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
2015-04-01 04:12:34 -07:00
|
|
|
}
|
|
|
|
binary.ReadJSON(&response, body, &err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if response.Error != "" {
|
|
|
|
return nil, fmt.Errorf(response.Error)
|
|
|
|
}
|
|
|
|
return response.Result, nil
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func (c *ClientHTTP) GetBlock(height uint) (*ctypes.ResponseGetBlock, error) {
|
2015-04-01 13:23:20 -07:00
|
|
|
values, err := argsToURLValues([]string{"height"}, height)
|
2015-04-01 04:12:34 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-04-01 13:23:20 -07:00
|
|
|
resp, err := http.PostForm(c.addr+"get_block", values)
|
2015-04-01 04:12:34 -07:00
|
|
|
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 {
|
2015-04-07 11:44:25 -07:00
|
|
|
Result *ctypes.ResponseGetBlock `json:"result"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
2015-04-01 04:12:34 -07:00
|
|
|
}
|
|
|
|
binary.ReadJSON(&response, body, &err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if response.Error != "" {
|
|
|
|
return nil, fmt.Errorf(response.Error)
|
|
|
|
}
|
|
|
|
return response.Result, nil
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func (c *ClientHTTP) GetStorage(address []byte) (*ctypes.ResponseGetStorage, error) {
|
2015-04-01 04:12:34 -07:00
|
|
|
values, err := argsToURLValues([]string{"address"}, address)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-04-01 13:23:20 -07:00
|
|
|
resp, err := http.PostForm(c.addr+"get_storage", values)
|
2015-04-01 04:12:34 -07:00
|
|
|
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 {
|
2015-04-07 11:44:25 -07:00
|
|
|
Result *ctypes.ResponseGetStorage `json:"result"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
2015-04-01 04:12:34 -07:00
|
|
|
}
|
|
|
|
binary.ReadJSON(&response, body, &err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if response.Error != "" {
|
|
|
|
return nil, fmt.Errorf(response.Error)
|
|
|
|
}
|
|
|
|
return response.Result, nil
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func (c *ClientHTTP) ListAccounts() (*ctypes.ResponseListAccounts, error) {
|
2015-04-01 13:23:20 -07:00
|
|
|
values, err := argsToURLValues(nil, nil)
|
2015-04-01 04:12:34 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-04-01 13:23:20 -07:00
|
|
|
resp, err := http.PostForm(c.addr+"list_accounts", values)
|
2015-04-01 04:12:34 -07:00
|
|
|
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 {
|
2015-04-07 11:44:25 -07:00
|
|
|
Result *ctypes.ResponseListAccounts `json:"result"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
2015-04-01 04:12:34 -07:00
|
|
|
}
|
|
|
|
binary.ReadJSON(&response, body, &err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if response.Error != "" {
|
|
|
|
return nil, fmt.Errorf(response.Error)
|
|
|
|
}
|
|
|
|
return response.Result, nil
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func (c *ClientHTTP) ListValidators() (*ctypes.ResponseListValidators, error) {
|
2015-04-01 04:12:34 -07:00
|
|
|
values, err := argsToURLValues(nil, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
resp, err := http.PostForm(c.addr+"list_validators", 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 {
|
2015-04-07 11:44:25 -07:00
|
|
|
Result *ctypes.ResponseListValidators `json:"result"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
2015-04-01 04:12:34 -07:00
|
|
|
}
|
|
|
|
binary.ReadJSON(&response, body, &err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if response.Error != "" {
|
|
|
|
return nil, fmt.Errorf(response.Error)
|
|
|
|
}
|
|
|
|
return response.Result, nil
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func (c *ClientHTTP) NetInfo() (*ctypes.ResponseNetInfo, error) {
|
2015-04-01 04:12:34 -07:00
|
|
|
values, err := argsToURLValues(nil, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-04-01 13:23:20 -07:00
|
|
|
resp, err := http.PostForm(c.addr+"net_info", values)
|
2015-04-01 04:12:34 -07:00
|
|
|
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 {
|
2015-04-07 11:44:25 -07:00
|
|
|
Result *ctypes.ResponseNetInfo `json:"result"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
2015-04-01 04:12:34 -07:00
|
|
|
}
|
|
|
|
binary.ReadJSON(&response, body, &err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if response.Error != "" {
|
|
|
|
return nil, fmt.Errorf(response.Error)
|
|
|
|
}
|
|
|
|
return response.Result, nil
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func (c *ClientHTTP) SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*ctypes.ResponseSignTx, error) {
|
2015-04-01 13:23:20 -07:00
|
|
|
values, err := argsToURLValues([]string{"tx", "privAccounts"}, tx, privAccounts)
|
2015-04-01 04:12:34 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-04-01 13:23:20 -07:00
|
|
|
resp, err := http.PostForm(c.addr+"sign_tx", values)
|
2015-04-01 04:12:34 -07:00
|
|
|
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 {
|
2015-04-07 11:44:25 -07:00
|
|
|
Result *ctypes.ResponseSignTx `json:"result"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
2015-04-01 04:12:34 -07:00
|
|
|
}
|
|
|
|
binary.ReadJSON(&response, body, &err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if response.Error != "" {
|
|
|
|
return nil, fmt.Errorf(response.Error)
|
|
|
|
}
|
|
|
|
return response.Result, nil
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func (c *ClientHTTP) Status() (*ctypes.ResponseStatus, error) {
|
2015-04-01 13:23:20 -07:00
|
|
|
values, err := argsToURLValues(nil, nil)
|
2015-04-01 04:12:34 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-04-01 13:23:20 -07:00
|
|
|
resp, err := http.PostForm(c.addr+"status", values)
|
2015-04-01 04:12:34 -07:00
|
|
|
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 {
|
2015-04-07 11:44:25 -07:00
|
|
|
Result *ctypes.ResponseStatus `json:"result"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
2015-04-01 04:12:34 -07:00
|
|
|
}
|
|
|
|
binary.ReadJSON(&response, body, &err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if response.Error != "" {
|
|
|
|
return nil, fmt.Errorf(response.Error)
|
|
|
|
}
|
|
|
|
return response.Result, nil
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func (c *ClientJSON) BlockchainInfo(minHeight uint) (*ctypes.ResponseBlockchainInfo, error) {
|
|
|
|
request := rpc.RPCRequest{
|
2015-04-01 04:12:34 -07:00
|
|
|
JSONRPC: "2.0",
|
2015-04-01 13:23:20 -07:00
|
|
|
Method: "blockchain_info",
|
|
|
|
Params: []interface{}{minHeight},
|
2015-04-01 04:12:34 -07:00
|
|
|
Id: 0,
|
|
|
|
}
|
2015-04-01 13:23:20 -07:00
|
|
|
body, err := c.RequestResponse(request)
|
2015-04-01 04:12:34 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var response struct {
|
2015-04-07 11:44:25 -07:00
|
|
|
Result *ctypes.ResponseBlockchainInfo `json:"result"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
2015-04-01 04:12:34 -07:00
|
|
|
}
|
|
|
|
binary.ReadJSON(&response, body, &err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if response.Error != "" {
|
|
|
|
return nil, fmt.Errorf(response.Error)
|
|
|
|
}
|
|
|
|
return response.Result, nil
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func (c *ClientJSON) BroadcastTx(tx types.Tx) (*ctypes.ResponseBroadcastTx, error) {
|
|
|
|
request := rpc.RPCRequest{
|
2015-04-01 04:12:34 -07:00
|
|
|
JSONRPC: "2.0",
|
2015-04-01 13:23:20 -07:00
|
|
|
Method: "broadcast_tx",
|
|
|
|
Params: []interface{}{tx},
|
2015-04-01 04:12:34 -07:00
|
|
|
Id: 0,
|
|
|
|
}
|
2015-04-01 13:23:20 -07:00
|
|
|
body, err := c.RequestResponse(request)
|
2015-04-01 04:12:34 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var response struct {
|
2015-04-07 11:44:25 -07:00
|
|
|
Result *ctypes.ResponseBroadcastTx `json:"result"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
2015-04-01 04:12:34 -07:00
|
|
|
}
|
|
|
|
binary.ReadJSON(&response, body, &err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if response.Error != "" {
|
|
|
|
return nil, fmt.Errorf(response.Error)
|
|
|
|
}
|
|
|
|
return response.Result, nil
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func (c *ClientJSON) Call(address []byte) (*ctypes.ResponseCall, error) {
|
|
|
|
request := rpc.RPCRequest{
|
2015-04-01 04:12:34 -07:00
|
|
|
JSONRPC: "2.0",
|
2015-04-01 13:23:20 -07:00
|
|
|
Method: "call",
|
|
|
|
Params: []interface{}{address},
|
2015-04-01 04:12:34 -07:00
|
|
|
Id: 0,
|
|
|
|
}
|
2015-04-01 13:23:20 -07:00
|
|
|
body, err := c.RequestResponse(request)
|
2015-04-01 04:12:34 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var response struct {
|
2015-04-07 11:44:25 -07:00
|
|
|
Result *ctypes.ResponseCall `json:"result"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
2015-04-01 04:12:34 -07:00
|
|
|
}
|
|
|
|
binary.ReadJSON(&response, body, &err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if response.Error != "" {
|
|
|
|
return nil, fmt.Errorf(response.Error)
|
|
|
|
}
|
|
|
|
return response.Result, nil
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func (c *ClientJSON) DumpStorage(addr []byte) (*ctypes.ResponseDumpStorage, error) {
|
|
|
|
request := rpc.RPCRequest{
|
2015-04-01 04:12:34 -07:00
|
|
|
JSONRPC: "2.0",
|
2015-04-01 13:23:20 -07:00
|
|
|
Method: "dump_storage",
|
|
|
|
Params: []interface{}{addr},
|
2015-04-01 04:12:34 -07:00
|
|
|
Id: 0,
|
|
|
|
}
|
2015-04-01 13:23:20 -07:00
|
|
|
body, err := c.RequestResponse(request)
|
2015-04-01 04:12:34 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var response struct {
|
2015-04-07 11:44:25 -07:00
|
|
|
Result *ctypes.ResponseDumpStorage `json:"result"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
2015-04-01 04:12:34 -07:00
|
|
|
}
|
|
|
|
binary.ReadJSON(&response, body, &err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if response.Error != "" {
|
|
|
|
return nil, fmt.Errorf(response.Error)
|
|
|
|
}
|
|
|
|
return response.Result, nil
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func (c *ClientJSON) GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error) {
|
|
|
|
request := rpc.RPCRequest{
|
2015-04-01 04:12:34 -07:00
|
|
|
JSONRPC: "2.0",
|
2015-04-01 13:23:20 -07:00
|
|
|
Method: "gen_priv_account",
|
|
|
|
Params: []interface{}{nil},
|
2015-04-01 04:12:34 -07:00
|
|
|
Id: 0,
|
|
|
|
}
|
2015-04-01 13:23:20 -07:00
|
|
|
body, err := c.RequestResponse(request)
|
2015-04-01 04:12:34 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var response struct {
|
2015-04-07 11:44:25 -07:00
|
|
|
Result *ctypes.ResponseGenPrivAccount `json:"result"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
2015-04-01 04:12:34 -07:00
|
|
|
}
|
|
|
|
binary.ReadJSON(&response, body, &err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if response.Error != "" {
|
|
|
|
return nil, fmt.Errorf(response.Error)
|
|
|
|
}
|
|
|
|
return response.Result, nil
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func (c *ClientJSON) GetAccount(address []byte) (*ctypes.ResponseGetAccount, error) {
|
|
|
|
request := rpc.RPCRequest{
|
2015-04-01 04:12:34 -07:00
|
|
|
JSONRPC: "2.0",
|
2015-04-01 13:23:20 -07:00
|
|
|
Method: "get_account",
|
|
|
|
Params: []interface{}{address},
|
2015-04-01 04:12:34 -07:00
|
|
|
Id: 0,
|
|
|
|
}
|
2015-04-01 13:23:20 -07:00
|
|
|
body, err := c.RequestResponse(request)
|
2015-04-01 04:12:34 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var response struct {
|
2015-04-07 11:44:25 -07:00
|
|
|
Result *ctypes.ResponseGetAccount `json:"result"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
2015-04-01 04:12:34 -07:00
|
|
|
}
|
|
|
|
binary.ReadJSON(&response, body, &err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if response.Error != "" {
|
|
|
|
return nil, fmt.Errorf(response.Error)
|
|
|
|
}
|
|
|
|
return response.Result, nil
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func (c *ClientJSON) GetBlock(height uint) (*ctypes.ResponseGetBlock, error) {
|
|
|
|
request := rpc.RPCRequest{
|
2015-04-01 04:12:34 -07:00
|
|
|
JSONRPC: "2.0",
|
2015-04-01 13:23:20 -07:00
|
|
|
Method: "get_block",
|
|
|
|
Params: []interface{}{height},
|
2015-04-01 04:12:34 -07:00
|
|
|
Id: 0,
|
|
|
|
}
|
2015-04-01 13:23:20 -07:00
|
|
|
body, err := c.RequestResponse(request)
|
2015-04-01 04:12:34 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var response struct {
|
2015-04-07 11:44:25 -07:00
|
|
|
Result *ctypes.ResponseGetBlock `json:"result"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
2015-04-01 04:12:34 -07:00
|
|
|
}
|
|
|
|
binary.ReadJSON(&response, body, &err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if response.Error != "" {
|
|
|
|
return nil, fmt.Errorf(response.Error)
|
|
|
|
}
|
|
|
|
return response.Result, nil
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func (c *ClientJSON) GetStorage(address []byte) (*ctypes.ResponseGetStorage, error) {
|
|
|
|
request := rpc.RPCRequest{
|
2015-04-01 04:12:34 -07:00
|
|
|
JSONRPC: "2.0",
|
2015-04-01 13:23:20 -07:00
|
|
|
Method: "get_storage",
|
|
|
|
Params: []interface{}{address},
|
2015-04-01 04:12:34 -07:00
|
|
|
Id: 0,
|
|
|
|
}
|
2015-04-01 13:23:20 -07:00
|
|
|
body, err := c.RequestResponse(request)
|
2015-04-01 04:12:34 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var response struct {
|
2015-04-07 11:44:25 -07:00
|
|
|
Result *ctypes.ResponseGetStorage `json:"result"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
2015-04-01 04:12:34 -07:00
|
|
|
}
|
|
|
|
binary.ReadJSON(&response, body, &err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if response.Error != "" {
|
|
|
|
return nil, fmt.Errorf(response.Error)
|
|
|
|
}
|
|
|
|
return response.Result, nil
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func (c *ClientJSON) ListAccounts() (*ctypes.ResponseListAccounts, error) {
|
|
|
|
request := rpc.RPCRequest{
|
2015-04-01 04:12:34 -07:00
|
|
|
JSONRPC: "2.0",
|
2015-04-01 13:23:20 -07:00
|
|
|
Method: "list_accounts",
|
|
|
|
Params: []interface{}{nil},
|
2015-04-01 04:12:34 -07:00
|
|
|
Id: 0,
|
|
|
|
}
|
2015-04-01 13:23:20 -07:00
|
|
|
body, err := c.RequestResponse(request)
|
2015-04-01 04:12:34 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var response struct {
|
2015-04-07 11:44:25 -07:00
|
|
|
Result *ctypes.ResponseListAccounts `json:"result"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
2015-04-01 04:12:34 -07:00
|
|
|
}
|
|
|
|
binary.ReadJSON(&response, body, &err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if response.Error != "" {
|
|
|
|
return nil, fmt.Errorf(response.Error)
|
|
|
|
}
|
|
|
|
return response.Result, nil
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func (c *ClientJSON) ListValidators() (*ctypes.ResponseListValidators, error) {
|
|
|
|
request := rpc.RPCRequest{
|
2015-04-01 04:12:34 -07:00
|
|
|
JSONRPC: "2.0",
|
|
|
|
Method: "list_validators",
|
2015-04-01 13:23:20 -07:00
|
|
|
Params: []interface{}{nil},
|
2015-04-01 04:12:34 -07:00
|
|
|
Id: 0,
|
|
|
|
}
|
2015-04-01 13:23:20 -07:00
|
|
|
body, err := c.RequestResponse(request)
|
2015-04-01 04:12:34 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var response struct {
|
2015-04-07 11:44:25 -07:00
|
|
|
Result *ctypes.ResponseListValidators `json:"result"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
2015-04-01 04:12:34 -07:00
|
|
|
}
|
|
|
|
binary.ReadJSON(&response, body, &err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if response.Error != "" {
|
|
|
|
return nil, fmt.Errorf(response.Error)
|
|
|
|
}
|
|
|
|
return response.Result, nil
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func (c *ClientJSON) NetInfo() (*ctypes.ResponseNetInfo, error) {
|
|
|
|
request := rpc.RPCRequest{
|
2015-04-01 04:12:34 -07:00
|
|
|
JSONRPC: "2.0",
|
2015-04-01 13:23:20 -07:00
|
|
|
Method: "net_info",
|
|
|
|
Params: []interface{}{nil},
|
2015-04-01 04:12:34 -07:00
|
|
|
Id: 0,
|
|
|
|
}
|
2015-04-01 13:23:20 -07:00
|
|
|
body, err := c.RequestResponse(request)
|
2015-04-01 04:12:34 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var response struct {
|
2015-04-07 11:44:25 -07:00
|
|
|
Result *ctypes.ResponseNetInfo `json:"result"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
2015-04-01 04:12:34 -07:00
|
|
|
}
|
|
|
|
binary.ReadJSON(&response, body, &err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if response.Error != "" {
|
|
|
|
return nil, fmt.Errorf(response.Error)
|
|
|
|
}
|
|
|
|
return response.Result, nil
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func (c *ClientJSON) SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*ctypes.ResponseSignTx, error) {
|
|
|
|
request := rpc.RPCRequest{
|
2015-04-01 04:12:34 -07:00
|
|
|
JSONRPC: "2.0",
|
2015-04-01 13:23:20 -07:00
|
|
|
Method: "sign_tx",
|
|
|
|
Params: []interface{}{tx, privAccounts},
|
2015-04-01 04:12:34 -07:00
|
|
|
Id: 0,
|
|
|
|
}
|
2015-04-01 13:23:20 -07:00
|
|
|
body, err := c.RequestResponse(request)
|
2015-04-01 04:12:34 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var response struct {
|
2015-04-07 11:44:25 -07:00
|
|
|
Result *ctypes.ResponseSignTx `json:"result"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
2015-04-01 04:12:34 -07:00
|
|
|
}
|
|
|
|
binary.ReadJSON(&response, body, &err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if response.Error != "" {
|
|
|
|
return nil, fmt.Errorf(response.Error)
|
|
|
|
}
|
|
|
|
return response.Result, nil
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:44:25 -07:00
|
|
|
func (c *ClientJSON) Status() (*ctypes.ResponseStatus, error) {
|
|
|
|
request := rpc.RPCRequest{
|
2015-04-01 04:12:34 -07:00
|
|
|
JSONRPC: "2.0",
|
2015-04-01 13:23:20 -07:00
|
|
|
Method: "status",
|
|
|
|
Params: []interface{}{nil},
|
2015-04-01 04:12:34 -07:00
|
|
|
Id: 0,
|
|
|
|
}
|
2015-04-01 13:23:20 -07:00
|
|
|
body, err := c.RequestResponse(request)
|
2015-04-01 04:12:34 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var response struct {
|
2015-04-07 11:44:25 -07:00
|
|
|
Result *ctypes.ResponseStatus `json:"result"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
2015-04-01 04:12:34 -07:00
|
|
|
}
|
|
|
|
binary.ReadJSON(&response, body, &err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if response.Error != "" {
|
|
|
|
return nil, fmt.Errorf(response.Error)
|
|
|
|
}
|
|
|
|
return response.Result, nil
|
|
|
|
}
|