rpc: remove unecessary response wrappers

This commit is contained in:
Ethan Buchman 2015-06-01 13:51:03 -04:00
parent 293aa31f64
commit ec282d3e3d
7 changed files with 76 additions and 97 deletions

View File

@ -7,11 +7,11 @@ import (
ctypes "github.com/tendermint/tendermint/rpc/core/types" ctypes "github.com/tendermint/tendermint/rpc/core/types"
) )
func GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error) { func GenPrivAccount() (*acm.PrivAccount, error) {
return &ctypes.ResponseGenPrivAccount{acm.GenPrivAccount()}, nil return acm.GenPrivAccount(), nil
} }
func GetAccount(address []byte) (*ctypes.ResponseGetAccount, error) { func GetAccount(address []byte) (*acm.Account, error) {
cache := mempoolReactor.Mempool.GetCache() cache := mempoolReactor.Mempool.GetCache()
account := cache.GetAccount(address) account := cache.GetAccount(address)
if account == nil { if account == nil {
@ -24,7 +24,7 @@ func GetAccount(address []byte) (*ctypes.ResponseGetAccount, error) {
StorageRoot: nil, StorageRoot: nil,
} }
} }
return &ctypes.ResponseGetAccount{account}, nil return account, nil
} }
func GetStorage(address, key []byte) (*ctypes.ResponseGetStorage, error) { func GetStorage(address, key []byte) (*ctypes.ResponseGetStorage, error) {

View File

@ -9,9 +9,8 @@ import (
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// pass pointer?
// Note: tx must be signed // Note: tx must be signed
func BroadcastTx(tx types.Tx) (*ctypes.ResponseBroadcastTx, error) { func BroadcastTx(tx types.Tx) (*ctypes.Receipt, error) {
err := mempoolReactor.BroadcastTx(tx) err := mempoolReactor.BroadcastTx(tx)
if err != nil { if err != nil {
return nil, fmt.Errorf("Error broadcasting transaction: %v", err) return nil, fmt.Errorf("Error broadcasting transaction: %v", err)
@ -27,10 +26,9 @@ func BroadcastTx(tx types.Tx) (*ctypes.ResponseBroadcastTx, error) {
contractAddr = state.NewContractAddress(callTx.Input.Address, uint64(callTx.Input.Sequence)) contractAddr = state.NewContractAddress(callTx.Input.Address, uint64(callTx.Input.Sequence))
} }
} }
return &ctypes.ResponseBroadcastTx{ctypes.Receipt{txHash, createsContract, contractAddr}}, nil return &ctypes.Receipt{txHash, createsContract, contractAddr}, nil
} }
func ListUnconfirmedTxs() (*ctypes.ResponseListUnconfirmedTxs, error) { func ListUnconfirmedTxs() ([]types.Tx, error) {
txs := mempoolReactor.Mempool.GetProposalTxs() return mempoolReactor.Mempool.GetProposalTxs(), nil
return &ctypes.ResponseListUnconfirmedTxs{txs}, nil
} }

View File

@ -78,7 +78,7 @@ func CallCode(code, data []byte) (*ctypes.ResponseCall, error) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
func SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*ctypes.ResponseSignTx, error) { func SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (types.Tx, error) {
// more checks? // more checks?
for i, privAccount := range privAccounts { for i, privAccount := range privAccounts {
@ -113,5 +113,5 @@ func SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*ctypes.ResponseS
rebondTx := tx.(*types.RebondTx) rebondTx := tx.(*types.RebondTx)
rebondTx.Signature = privAccounts[0].Sign(config.GetString("chain_id"), rebondTx).(account.SignatureEd25519) rebondTx.Signature = privAccounts[0].Sign(config.GetString("chain_id"), rebondTx).(account.SignatureEd25519)
} }
return &ctypes.ResponseSignTx{tx}, nil return tx, nil
} }

View File

@ -6,14 +6,6 @@ import (
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
) )
type ResponseGenPrivAccount struct {
PrivAccount *account.PrivAccount `json:"priv_account"`
}
type ResponseGetAccount struct {
Account *account.Account `json:"account"`
}
type ResponseGetStorage struct { type ResponseGetStorage struct {
Key []byte `json:"key"` Key []byte `json:"key"`
Value []byte `json:"value"` Value []byte `json:"value"`
@ -50,14 +42,6 @@ type ResponseGetBlock struct {
Block *types.Block `json:"block"` Block *types.Block `json:"block"`
} }
type ResponseBroadcastTx struct {
Receipt Receipt `json:"receipt"`
}
type ResponseListUnconfirmedTxs struct {
Txs []types.Tx `json:"txs"`
}
type Receipt struct { type Receipt struct {
TxHash []byte `json:"tx_hash"` TxHash []byte `json:"tx_hash"`
CreatesContract uint8 `json:"creates_contract"` CreatesContract uint8 `json:"creates_contract"`
@ -86,10 +70,6 @@ type Peer struct {
IsOutbound bool `json:"is_outbound"` IsOutbound bool `json:"is_outbound"`
} }
type ResponseSignTx struct {
Tx types.Tx `json:"tx"`
}
type ResponseListValidators struct { type ResponseListValidators struct {
BlockHeight uint `json:"block_height"` BlockHeight uint `json:"block_height"`
BondedValidators []*sm.Validator `json:"bonded_validators"` BondedValidators []*sm.Validator `json:"bonded_validators"`

View File

@ -5,6 +5,7 @@ package core_client
import ( import (
"fmt" "fmt"
"github.com/tendermint/tendermint/account" "github.com/tendermint/tendermint/account"
acm "github.com/tendermint/tendermint/account"
"github.com/tendermint/tendermint/binary" "github.com/tendermint/tendermint/binary"
ctypes "github.com/tendermint/tendermint/rpc/core/types" ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpctypes "github.com/tendermint/tendermint/rpc/types" rpctypes "github.com/tendermint/tendermint/rpc/types"
@ -15,23 +16,23 @@ import (
type Client interface { type Client interface {
BlockchainInfo(minHeight uint, maxHeight uint) (*ctypes.ResponseBlockchainInfo, error) 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) Call(address []byte, data []byte) (*ctypes.ResponseCall, error)
CallCode(code []byte, data []byte) (*ctypes.ResponseCall, error) CallCode(code []byte, data []byte) (*ctypes.ResponseCall, error)
DumpConsensusState() (*ctypes.ResponseDumpConsensusState, error) DumpConsensusState() (*ctypes.ResponseDumpConsensusState, error)
DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, error) DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, error)
GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error) GenPrivAccount() (*acm.PrivAccount, error)
Genesis() (*string, error) Genesis() (*string, error)
GetAccount(address []byte) (*ctypes.ResponseGetAccount, error) GetAccount(address []byte) (*acm.Account, error)
GetBlock(height uint) (*ctypes.ResponseGetBlock, error) GetBlock(height uint) (*ctypes.ResponseGetBlock, error)
GetName(name string) (*types.NameRegEntry, 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) ListNames() (*ctypes.ResponseListNames, error)
ListUnconfirmedTxs() (*ctypes.ResponseListUnconfirmedTxs, error) ListUnconfirmedTxs() ([]types.Tx, error)
ListValidators() (*ctypes.ResponseListValidators, error) ListValidators() (*ctypes.ResponseListValidators, 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) (types.Tx, error)
Status() (*ctypes.ResponseStatus, error) Status() (*ctypes.ResponseStatus, error)
} }
@ -65,7 +66,7 @@ func (c *ClientHTTP) BlockchainInfo(minHeight uint, maxHeight uint) (*ctypes.Res
return response.Result, nil 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) values, err := argsToURLValues([]string{"tx"}, tx)
if err != nil { if err != nil {
return nil, err return nil, err
@ -80,7 +81,7 @@ func (c *ClientHTTP) BroadcastTx(tx types.Tx) (*ctypes.ResponseBroadcastTx, erro
return nil, err return nil, err
} }
var response struct { var response struct {
Result *ctypes.ResponseBroadcastTx `json:"result"` Result *ctypes.Receipt `json:"result"`
Error string `json:"error"` Error string `json:"error"`
Id string `json:"id"` Id string `json:"id"`
JSONRPC string `json:"jsonrpc"` JSONRPC string `json:"jsonrpc"`
@ -215,7 +216,7 @@ func (c *ClientHTTP) DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, e
return response.Result, nil return response.Result, nil
} }
func (c *ClientHTTP) GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error) { func (c *ClientHTTP) GenPrivAccount() (*acm.PrivAccount, error) {
values, err := argsToURLValues(nil) values, err := argsToURLValues(nil)
if err != nil { if err != nil {
return nil, err return nil, err
@ -230,7 +231,7 @@ func (c *ClientHTTP) GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error) {
return nil, err return nil, err
} }
var response struct { var response struct {
Result *ctypes.ResponseGenPrivAccount `json:"result"` Result *acm.PrivAccount `json:"result"`
Error string `json:"error"` Error string `json:"error"`
Id string `json:"id"` Id string `json:"id"`
JSONRPC string `json:"jsonrpc"` JSONRPC string `json:"jsonrpc"`
@ -275,7 +276,7 @@ func (c *ClientHTTP) Genesis() (*string, error) {
return response.Result, nil return response.Result, nil
} }
func (c *ClientHTTP) GetAccount(address []byte) (*ctypes.ResponseGetAccount, error) { func (c *ClientHTTP) GetAccount(address []byte) (*acm.Account, error) {
values, err := argsToURLValues([]string{"address"}, address) values, err := argsToURLValues([]string{"address"}, address)
if err != nil { if err != nil {
return nil, err return nil, err
@ -290,7 +291,7 @@ func (c *ClientHTTP) GetAccount(address []byte) (*ctypes.ResponseGetAccount, err
return nil, err return nil, err
} }
var response struct { var response struct {
Result *ctypes.ResponseGetAccount `json:"result"` Result *acm.Account `json:"result"`
Error string `json:"error"` Error string `json:"error"`
Id string `json:"id"` Id string `json:"id"`
JSONRPC string `json:"jsonrpc"` JSONRPC string `json:"jsonrpc"`
@ -455,7 +456,7 @@ func (c *ClientHTTP) ListNames() (*ctypes.ResponseListNames, error) {
return response.Result, nil return response.Result, nil
} }
func (c *ClientHTTP) ListUnconfirmedTxs() (*ctypes.ResponseListUnconfirmedTxs, error) { func (c *ClientHTTP) ListUnconfirmedTxs() ([]types.Tx, error) {
values, err := argsToURLValues(nil) values, err := argsToURLValues(nil)
if err != nil { if err != nil {
return nil, err return nil, err
@ -470,7 +471,7 @@ func (c *ClientHTTP) ListUnconfirmedTxs() (*ctypes.ResponseListUnconfirmedTxs, e
return nil, err return nil, err
} }
var response struct { var response struct {
Result *ctypes.ResponseListUnconfirmedTxs `json:"result"` Result []types.Tx `json:"result"`
Error string `json:"error"` Error string `json:"error"`
Id string `json:"id"` Id string `json:"id"`
JSONRPC string `json:"jsonrpc"` JSONRPC string `json:"jsonrpc"`
@ -545,7 +546,7 @@ func (c *ClientHTTP) NetInfo() (*ctypes.ResponseNetInfo, error) {
return response.Result, nil return response.Result, nil
} }
func (c *ClientHTTP) SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*ctypes.ResponseSignTx, error) { func (c *ClientHTTP) SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (types.Tx, error) {
values, err := argsToURLValues([]string{"tx", "privAccounts"}, tx, privAccounts) values, err := argsToURLValues([]string{"tx", "privAccounts"}, tx, privAccounts)
if err != nil { if err != nil {
return nil, err return nil, err
@ -560,7 +561,7 @@ func (c *ClientHTTP) SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*
return nil, err return nil, err
} }
var response struct { var response struct {
Result *ctypes.ResponseSignTx `json:"result"` Result types.Tx `json:"result"`
Error string `json:"error"` Error string `json:"error"`
Id string `json:"id"` Id string `json:"id"`
JSONRPC string `json:"jsonrpc"` JSONRPC string `json:"jsonrpc"`
@ -632,7 +633,7 @@ func (c *ClientJSON) BlockchainInfo(minHeight uint, maxHeight uint) (*ctypes.Res
return response.Result, nil 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{ request := rpctypes.RPCRequest{
JSONRPC: "2.0", JSONRPC: "2.0",
Method: reverseFuncMap["BroadcastTx"], Method: reverseFuncMap["BroadcastTx"],
@ -644,7 +645,7 @@ func (c *ClientJSON) BroadcastTx(tx types.Tx) (*ctypes.ResponseBroadcastTx, erro
return nil, err return nil, err
} }
var response struct { var response struct {
Result *ctypes.ResponseBroadcastTx `json:"result"` Result *ctypes.Receipt `json:"result"`
Error string `json:"error"` Error string `json:"error"`
Id string `json:"id"` Id string `json:"id"`
JSONRPC string `json:"jsonrpc"` JSONRPC string `json:"jsonrpc"`
@ -767,7 +768,7 @@ func (c *ClientJSON) DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, e
return response.Result, nil return response.Result, nil
} }
func (c *ClientJSON) GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error) { func (c *ClientJSON) GenPrivAccount() (*acm.PrivAccount, error) {
request := rpctypes.RPCRequest{ request := rpctypes.RPCRequest{
JSONRPC: "2.0", JSONRPC: "2.0",
Method: reverseFuncMap["GenPrivAccount"], Method: reverseFuncMap["GenPrivAccount"],
@ -779,7 +780,7 @@ func (c *ClientJSON) GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error) {
return nil, err return nil, err
} }
var response struct { var response struct {
Result *ctypes.ResponseGenPrivAccount `json:"result"` Result *acm.PrivAccount `json:"result"`
Error string `json:"error"` Error string `json:"error"`
Id string `json:"id"` Id string `json:"id"`
JSONRPC string `json:"jsonrpc"` JSONRPC string `json:"jsonrpc"`
@ -821,7 +822,7 @@ func (c *ClientJSON) Genesis() (*string, error) {
return response.Result, nil return response.Result, nil
} }
func (c *ClientJSON) GetAccount(address []byte) (*ctypes.ResponseGetAccount, error) { func (c *ClientJSON) GetAccount(address []byte) (*acm.Account, error) {
request := rpctypes.RPCRequest{ request := rpctypes.RPCRequest{
JSONRPC: "2.0", JSONRPC: "2.0",
Method: reverseFuncMap["GetAccount"], Method: reverseFuncMap["GetAccount"],
@ -833,7 +834,7 @@ func (c *ClientJSON) GetAccount(address []byte) (*ctypes.ResponseGetAccount, err
return nil, err return nil, err
} }
var response struct { var response struct {
Result *ctypes.ResponseGetAccount `json:"result"` Result *acm.Account `json:"result"`
Error string `json:"error"` Error string `json:"error"`
Id string `json:"id"` Id string `json:"id"`
JSONRPC string `json:"jsonrpc"` JSONRPC string `json:"jsonrpc"`
@ -983,7 +984,7 @@ func (c *ClientJSON) ListNames() (*ctypes.ResponseListNames, error) {
return response.Result, nil return response.Result, nil
} }
func (c *ClientJSON) ListUnconfirmedTxs() (*ctypes.ResponseListUnconfirmedTxs, error) { func (c *ClientJSON) ListUnconfirmedTxs() ([]types.Tx, error) {
request := rpctypes.RPCRequest{ request := rpctypes.RPCRequest{
JSONRPC: "2.0", JSONRPC: "2.0",
Method: reverseFuncMap["ListUnconfirmedTxs"], Method: reverseFuncMap["ListUnconfirmedTxs"],
@ -995,7 +996,7 @@ func (c *ClientJSON) ListUnconfirmedTxs() (*ctypes.ResponseListUnconfirmedTxs, e
return nil, err return nil, err
} }
var response struct { var response struct {
Result *ctypes.ResponseListUnconfirmedTxs `json:"result"` Result []types.Tx `json:"result"`
Error string `json:"error"` Error string `json:"error"`
Id string `json:"id"` Id string `json:"id"`
JSONRPC string `json:"jsonrpc"` JSONRPC string `json:"jsonrpc"`
@ -1064,7 +1065,7 @@ func (c *ClientJSON) NetInfo() (*ctypes.ResponseNetInfo, error) {
return response.Result, nil return response.Result, nil
} }
func (c *ClientJSON) SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*ctypes.ResponseSignTx, error) { func (c *ClientJSON) SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (types.Tx, error) {
request := rpctypes.RPCRequest{ request := rpctypes.RPCRequest{
JSONRPC: "2.0", JSONRPC: "2.0",
Method: reverseFuncMap["SignTx"], Method: reverseFuncMap["SignTx"],
@ -1076,7 +1077,7 @@ func (c *ClientJSON) SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*
return nil, err return nil, err
} }
var response struct { var response struct {
Result *ctypes.ResponseSignTx `json:"result"` Result types.Tx `json:"result"`
Error string `json:"error"` Error string `json:"error"`
Id string `json:"id"` Id string `json:"id"`
JSONRPC string `json:"jsonrpc"` JSONRPC string `json:"jsonrpc"`

View File

@ -129,10 +129,10 @@ func getNonce(t *testing.T, typ string, addr []byte) uint {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if ac.Account == nil { if ac == nil {
return 0 return 0
} }
return ac.Account.Sequence return ac.Sequence
} }
// get the account // get the account
@ -142,28 +142,28 @@ func getAccount(t *testing.T, typ string, addr []byte) *account.Account {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
return ac.Account return ac
} }
// sign transaction // sign transaction
func signTx(t *testing.T, typ string, tx types.Tx, privAcc *account.PrivAccount) types.Tx { func signTx(t *testing.T, typ string, tx types.Tx, privAcc *account.PrivAccount) types.Tx {
client := clients[typ] client := clients[typ]
resp, err := client.SignTx(tx, []*account.PrivAccount{privAcc}) signedTx, err := client.SignTx(tx, []*account.PrivAccount{privAcc})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
return resp.Tx return signedTx
} }
// broadcast transaction // broadcast transaction
func broadcastTx(t *testing.T, typ string, tx types.Tx) ctypes.Receipt { func broadcastTx(t *testing.T, typ string, tx types.Tx) *ctypes.Receipt {
client := clients[typ] client := clients[typ]
resp, err := client.BroadcastTx(tx) rec, err := client.BroadcastTx(tx)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
mempoolCount += 1 mempoolCount += 1
return resp.Receipt return rec
} }
// dump all storage for an account. currently unused // dump all storage for an account. currently unused

View File

@ -25,11 +25,11 @@ func testStatus(t *testing.T, typ string) {
func testGenPriv(t *testing.T, typ string) { func testGenPriv(t *testing.T, typ string) {
client := clients[typ] client := clients[typ]
resp, err := client.GenPrivAccount() privAcc, err := client.GenPrivAccount()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if len(resp.PrivAccount.Address) == 0 { if len(privAcc.Address) == 0 {
t.Fatal("Failed to generate an address") t.Fatal("Failed to generate an address")
} }
} }