@ -5,6 +5,7 @@ package core_client
import (
"fmt"
"github.com/tendermint/tendermint/account"
acm "github.com/tendermint/tendermint/account"
"github.com/tendermint/tendermint/binary"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpctypes "github.com/tendermint/tendermint/rpc/types"
@ -15,21 +16,23 @@ import (
type Client interface {
BlockchainInfo ( minHeight uint , maxHeight uint ) ( * ctypes . ResponseBlockchainInfo , error )
BroadcastTx ( tx types . Tx ) ( * ctypes . ResponseBroadcastTx , error )
BroadcastTx ( tx types . Tx ) ( * ctypes . Receipt , error )
Call ( address [ ] byte , data [ ] byte ) ( * ctypes . ResponseCall , error )
CallCode ( code [ ] byte , data [ ] byte ) ( * ctypes . ResponseCall , error )
DumpConsensusState ( ) ( * ctypes . ResponseDumpConsensusState , error )
DumpStorage ( address [ ] byte ) ( * ctypes . ResponseDumpStorage , error )
GenPrivAccount ( ) ( * ctypes . ResponseGen PrivAccount, error )
GenPrivAccount ( ) ( * acm . PrivAccount , error )
Genesis ( ) ( * string , error )
GetAccount ( address [ ] byte ) ( * ctypes . ResponseGet Account, error )
GetAccount ( address [ ] byte ) ( * acm . Account , error )
GetBlock ( height uint ) ( * ctypes . ResponseGetBlock , error )
GetName ( name string ) ( * types . NameRegEntry , error )
GetStorage ( address [ ] byte , key [ ] byte ) ( * ctypes . ResponseGetStorage , error )
ListAccounts ( ) ( * ctypes . ResponseListAccounts , error )
ListUnconfirmedTxs ( ) ( * ctypes . ResponseListUnconfirmedTxs , error )
ListNames ( ) ( * ctypes . ResponseListNames , error )
ListUnconfirmedTxs ( ) ( [ ] types . Tx , error )
ListValidators ( ) ( * ctypes . ResponseListValidators , error )
NetInfo ( ) ( * ctypes . ResponseNetInfo , error )
SignTx ( tx types . Tx , privAccounts [ ] * account . PrivAccount ) ( * c types. ResponseSign Tx, error )
SignTx ( tx types . Tx , privAccounts [ ] * account . PrivAccount ) ( types . Tx , error )
Status ( ) ( * ctypes . ResponseStatus , error )
}
@ -63,7 +66,7 @@ func (c *ClientHTTP) BlockchainInfo(minHeight uint, maxHeight uint) (*ctypes.Res
return response . Result , nil
}
func ( c * ClientHTTP ) BroadcastTx ( tx types . Tx ) ( * ctypes . ResponseBroadcastTx , error ) {
func ( c * ClientHTTP ) BroadcastTx ( tx types . Tx ) ( * ctypes . Receipt , error ) {
values , err := argsToURLValues ( [ ] string { "tx" } , tx )
if err != nil {
return nil , err
@ -78,10 +81,10 @@ func (c *ClientHTTP) BroadcastTx(tx types.Tx) (*ctypes.ResponseBroadcastTx, erro
return nil , err
}
var response struct {
Result * ctypes . ResponseBroadcastTx ` json:"result" `
Error string ` json:"error" `
Id string ` json:"id" `
JSONRPC string ` json:"jsonrpc" `
Result * ctypes . Receipt ` json:"result" `
Error string ` json:"error" `
Id string ` json:"id" `
JSONRPC string ` json:"jsonrpc" `
}
binary . ReadJSON ( & response , body , & err )
if err != nil {
@ -213,7 +216,7 @@ func (c *ClientHTTP) DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, e
return response . Result , nil
}
func ( c * ClientHTTP ) GenPrivAccount ( ) ( * ctypes . ResponseGen PrivAccount, error ) {
func ( c * ClientHTTP ) GenPrivAccount ( ) ( * acm . PrivAccount , error ) {
values , err := argsToURLValues ( nil )
if err != nil {
return nil , err
@ -228,10 +231,10 @@ func (c *ClientHTTP) GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error) {
return nil , err
}
var response struct {
Result * ctypes . ResponseGen PrivAccount ` json:"result" `
Error string ` json:"error" `
Id string ` json:"id" `
JSONRPC string ` json:"jsonrpc" `
Result * acm . PrivAccount ` json:"result" `
Error string ` json:"error" `
Id string ` json:"id" `
JSONRPC string ` json:"jsonrpc" `
}
binary . ReadJSON ( & response , body , & err )
if err != nil {
@ -273,7 +276,7 @@ func (c *ClientHTTP) Genesis() (*string, error) {
return response . Result , nil
}
func ( c * ClientHTTP ) GetAccount ( address [ ] byte ) ( * ctypes . ResponseGet Account, error ) {
func ( c * ClientHTTP ) GetAccount ( address [ ] byte ) ( * acm . Account , error ) {
values , err := argsToURLValues ( [ ] string { "address" } , address )
if err != nil {
return nil , err
@ -288,10 +291,10 @@ func (c *ClientHTTP) GetAccount(address []byte) (*ctypes.ResponseGetAccount, err
return nil , err
}
var response struct {
Result * ctypes . ResponseGet Account ` json:"result" `
Error string ` json:"error" `
Id string ` json:"id" `
JSONRPC string ` json:"jsonrpc" `
Result * acm . Account ` json:"result" `
Error string ` json:"error" `
Id string ` json:"id" `
JSONRPC string ` json:"jsonrpc" `
}
binary . ReadJSON ( & response , body , & err )
if err != nil {
@ -333,6 +336,36 @@ func (c *ClientHTTP) GetBlock(height uint) (*ctypes.ResponseGetBlock, error) {
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 ) {
values , err := argsToURLValues ( [ ] string { "address" , "key" } , address , key )
if err != nil {
@ -393,7 +426,37 @@ func (c *ClientHTTP) ListAccounts() (*ctypes.ResponseListAccounts, error) {
return response . Result , nil
}
func ( c * ClientHTTP ) ListUnconfirmedTxs ( ) ( * ctypes . ResponseListUnconfirmedTxs , error ) {
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 ( ) ( [ ] types . Tx , error ) {
values , err := argsToURLValues ( nil )
if err != nil {
return nil , err
@ -408,10 +471,10 @@ func (c *ClientHTTP) ListUnconfirmedTxs() (*ctypes.ResponseListUnconfirmedTxs, e
return nil , err
}
var response struct {
Result * c types. ResponseListUnconfirmed Txs ` json:"result" `
Error string ` json:"error" `
Id string ` json:"id" `
JSONRPC string ` json:"jsonrpc" `
Result [ ] types . Tx ` json:"result" `
Error string ` json:"error" `
Id string ` json:"id" `
JSONRPC string ` json:"jsonrpc" `
}
binary . ReadJSON ( & response , body , & err )
if err != nil {
@ -483,7 +546,7 @@ func (c *ClientHTTP) NetInfo() (*ctypes.ResponseNetInfo, error) {
return response . Result , nil
}
func ( c * ClientHTTP ) SignTx ( tx types . Tx , privAccounts [ ] * account . PrivAccount ) ( * c types. ResponseSign Tx, error ) {
func ( c * ClientHTTP ) SignTx ( tx types . Tx , privAccounts [ ] * account . PrivAccount ) ( types . Tx , error ) {
values , err := argsToURLValues ( [ ] string { "tx" , "privAccounts" } , tx , privAccounts )
if err != nil {
return nil , err
@ -498,10 +561,10 @@ func (c *ClientHTTP) SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*
return nil , err
}
var response struct {
Result * c types. ResponseSign Tx ` json:"result" `
Error string ` json:"error" `
Id string ` json:"id" `
JSONRPC string ` json:"jsonrpc" `
Result types . Tx ` json:"result" `
Error string ` json:"error" `
Id string ` json:"id" `
JSONRPC string ` json:"jsonrpc" `
}
binary . ReadJSON ( & response , body , & err )
if err != nil {
@ -570,7 +633,7 @@ func (c *ClientJSON) BlockchainInfo(minHeight uint, maxHeight uint) (*ctypes.Res
return response . Result , nil
}
func ( c * ClientJSON ) BroadcastTx ( tx types . Tx ) ( * ctypes . ResponseBroadcastTx , error ) {
func ( c * ClientJSON ) BroadcastTx ( tx types . Tx ) ( * ctypes . Receipt , error ) {
request := rpctypes . RPCRequest {
JSONRPC : "2.0" ,
Method : reverseFuncMap [ "BroadcastTx" ] ,
@ -582,10 +645,10 @@ func (c *ClientJSON) BroadcastTx(tx types.Tx) (*ctypes.ResponseBroadcastTx, erro
return nil , err
}
var response struct {
Result * ctypes . ResponseBroadcastTx ` json:"result" `
Error string ` json:"error" `
Id string ` json:"id" `
JSONRPC string ` json:"jsonrpc" `
Result * ctypes . Receipt ` json:"result" `
Error string ` json:"error" `
Id string ` json:"id" `
JSONRPC string ` json:"jsonrpc" `
}
binary . ReadJSON ( & response , body , & err )
if err != nil {
@ -705,7 +768,7 @@ func (c *ClientJSON) DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, e
return response . Result , nil
}
func ( c * ClientJSON ) GenPrivAccount ( ) ( * ctypes . ResponseGen PrivAccount, error ) {
func ( c * ClientJSON ) GenPrivAccount ( ) ( * acm . PrivAccount , error ) {
request := rpctypes . RPCRequest {
JSONRPC : "2.0" ,
Method : reverseFuncMap [ "GenPrivAccount" ] ,
@ -717,10 +780,10 @@ func (c *ClientJSON) GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error) {
return nil , err
}
var response struct {
Result * ctypes . ResponseGen PrivAccount ` json:"result" `
Error string ` json:"error" `
Id string ` json:"id" `
JSONRPC string ` json:"jsonrpc" `
Result * acm . PrivAccount ` json:"result" `
Error string ` json:"error" `
Id string ` json:"id" `
JSONRPC string ` json:"jsonrpc" `
}
binary . ReadJSON ( & response , body , & err )
if err != nil {
@ -759,7 +822,7 @@ func (c *ClientJSON) Genesis() (*string, error) {
return response . Result , nil
}
func ( c * ClientJSON ) GetAccount ( address [ ] byte ) ( * ctypes . ResponseGet Account, error ) {
func ( c * ClientJSON ) GetAccount ( address [ ] byte ) ( * acm . Account , error ) {
request := rpctypes . RPCRequest {
JSONRPC : "2.0" ,
Method : reverseFuncMap [ "GetAccount" ] ,
@ -771,10 +834,10 @@ func (c *ClientJSON) GetAccount(address []byte) (*ctypes.ResponseGetAccount, err
return nil , err
}
var response struct {
Result * ctypes . ResponseGet Account ` json:"result" `
Error string ` json:"error" `
Id string ` json:"id" `
JSONRPC string ` json:"jsonrpc" `
Result * acm . Account ` json:"result" `
Error string ` json:"error" `
Id string ` json:"id" `
JSONRPC string ` json:"jsonrpc" `
}
binary . ReadJSON ( & response , body , & err )
if err != nil {
@ -813,6 +876,33 @@ func (c *ClientJSON) GetBlock(height uint) (*ctypes.ResponseGetBlock, error) {
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 ) {
request := rpctypes . RPCRequest {
JSONRPC : "2.0" ,
@ -867,7 +957,34 @@ func (c *ClientJSON) ListAccounts() (*ctypes.ResponseListAccounts, error) {
return response . Result , nil
}
func ( c * ClientJSON ) ListUnconfirmedTxs ( ) ( * ctypes . ResponseListUnconfirmedTxs , error ) {
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 ( ) ( [ ] types . Tx , error ) {
request := rpctypes . RPCRequest {
JSONRPC : "2.0" ,
Method : reverseFuncMap [ "ListUnconfirmedTxs" ] ,
@ -879,10 +996,10 @@ func (c *ClientJSON) ListUnconfirmedTxs() (*ctypes.ResponseListUnconfirmedTxs, e
return nil , err
}
var response struct {
Result * c types. ResponseListUnconfirmed Txs ` json:"result" `
Error string ` json:"error" `
Id string ` json:"id" `
JSONRPC string ` json:"jsonrpc" `
Result [ ] types . Tx ` json:"result" `
Error string ` json:"error" `
Id string ` json:"id" `
JSONRPC string ` json:"jsonrpc" `
}
binary . ReadJSON ( & response , body , & err )
if err != nil {
@ -948,7 +1065,7 @@ func (c *ClientJSON) NetInfo() (*ctypes.ResponseNetInfo, error) {
return response . Result , nil
}
func ( c * ClientJSON ) SignTx ( tx types . Tx , privAccounts [ ] * account . PrivAccount ) ( * c types. ResponseSign Tx, error ) {
func ( c * ClientJSON ) SignTx ( tx types . Tx , privAccounts [ ] * account . PrivAccount ) ( types . Tx , error ) {
request := rpctypes . RPCRequest {
JSONRPC : "2.0" ,
Method : reverseFuncMap [ "SignTx" ] ,
@ -960,10 +1077,10 @@ func (c *ClientJSON) SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*
return nil , err
}
var response struct {
Result * c types. ResponseSign Tx ` json:"result" `
Error string ` json:"error" `
Id string ` json:"id" `
JSONRPC string ` json:"jsonrpc" `
Result types . Tx ` json:"result" `
Error string ` json:"error" `
Id string ` json:"id" `
JSONRPC string ` json:"jsonrpc" `
}
binary . ReadJSON ( & response , body , & err )
if err != nil {