mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 14:52:17 +00:00
rpc: remove unecessary response wrappers
This commit is contained in:
parent
293aa31f64
commit
ec282d3e3d
@ -7,11 +7,11 @@ import (
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
)
|
||||
|
||||
func GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error) {
|
||||
return &ctypes.ResponseGenPrivAccount{acm.GenPrivAccount()}, nil
|
||||
func GenPrivAccount() (*acm.PrivAccount, error) {
|
||||
return acm.GenPrivAccount(), nil
|
||||
}
|
||||
|
||||
func GetAccount(address []byte) (*ctypes.ResponseGetAccount, error) {
|
||||
func GetAccount(address []byte) (*acm.Account, error) {
|
||||
cache := mempoolReactor.Mempool.GetCache()
|
||||
account := cache.GetAccount(address)
|
||||
if account == nil {
|
||||
@ -24,7 +24,7 @@ func GetAccount(address []byte) (*ctypes.ResponseGetAccount, error) {
|
||||
StorageRoot: nil,
|
||||
}
|
||||
}
|
||||
return &ctypes.ResponseGetAccount{account}, nil
|
||||
return account, nil
|
||||
}
|
||||
|
||||
func GetStorage(address, key []byte) (*ctypes.ResponseGetStorage, error) {
|
||||
|
@ -9,9 +9,8 @@ import (
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// pass pointer?
|
||||
// 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)
|
||||
if err != nil {
|
||||
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))
|
||||
}
|
||||
}
|
||||
return &ctypes.ResponseBroadcastTx{ctypes.Receipt{txHash, createsContract, contractAddr}}, nil
|
||||
return &ctypes.Receipt{txHash, createsContract, contractAddr}, nil
|
||||
}
|
||||
|
||||
func ListUnconfirmedTxs() (*ctypes.ResponseListUnconfirmedTxs, error) {
|
||||
txs := mempoolReactor.Mempool.GetProposalTxs()
|
||||
return &ctypes.ResponseListUnconfirmedTxs{txs}, nil
|
||||
func ListUnconfirmedTxs() ([]types.Tx, error) {
|
||||
return mempoolReactor.Mempool.GetProposalTxs(), nil
|
||||
}
|
||||
|
@ -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?
|
||||
|
||||
for i, privAccount := range privAccounts {
|
||||
@ -113,5 +113,5 @@ func SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*ctypes.ResponseS
|
||||
rebondTx := tx.(*types.RebondTx)
|
||||
rebondTx.Signature = privAccounts[0].Sign(config.GetString("chain_id"), rebondTx).(account.SignatureEd25519)
|
||||
}
|
||||
return &ctypes.ResponseSignTx{tx}, nil
|
||||
return tx, nil
|
||||
}
|
||||
|
@ -6,14 +6,6 @@ import (
|
||||
"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 {
|
||||
Key []byte `json:"key"`
|
||||
Value []byte `json:"value"`
|
||||
@ -50,14 +42,6 @@ type ResponseGetBlock struct {
|
||||
Block *types.Block `json:"block"`
|
||||
}
|
||||
|
||||
type ResponseBroadcastTx struct {
|
||||
Receipt Receipt `json:"receipt"`
|
||||
}
|
||||
|
||||
type ResponseListUnconfirmedTxs struct {
|
||||
Txs []types.Tx `json:"txs"`
|
||||
}
|
||||
|
||||
type Receipt struct {
|
||||
TxHash []byte `json:"tx_hash"`
|
||||
CreatesContract uint8 `json:"creates_contract"`
|
||||
@ -86,10 +70,6 @@ type Peer struct {
|
||||
IsOutbound bool `json:"is_outbound"`
|
||||
}
|
||||
|
||||
type ResponseSignTx struct {
|
||||
Tx types.Tx `json:"tx"`
|
||||
}
|
||||
|
||||
type ResponseListValidators struct {
|
||||
BlockHeight uint `json:"block_height"`
|
||||
BondedValidators []*sm.Validator `json:"bonded_validators"`
|
||||
|
@ -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,23 +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.ResponseGenPrivAccount, error)
|
||||
GenPrivAccount() (*acm.PrivAccount, error)
|
||||
Genesis() (*string, error)
|
||||
GetAccount(address []byte) (*ctypes.ResponseGetAccount, 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)
|
||||
ListNames() (*ctypes.ResponseListNames, error)
|
||||
ListUnconfirmedTxs() (*ctypes.ResponseListUnconfirmedTxs, error)
|
||||
ListUnconfirmedTxs() ([]types.Tx, error)
|
||||
ListValidators() (*ctypes.ResponseListValidators, 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)
|
||||
}
|
||||
|
||||
@ -65,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
|
||||
@ -80,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 {
|
||||
@ -215,7 +216,7 @@ func (c *ClientHTTP) DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, e
|
||||
return response.Result, nil
|
||||
}
|
||||
|
||||
func (c *ClientHTTP) GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error) {
|
||||
func (c *ClientHTTP) GenPrivAccount() (*acm.PrivAccount, error) {
|
||||
values, err := argsToURLValues(nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -230,10 +231,10 @@ func (c *ClientHTTP) GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error) {
|
||||
return nil, err
|
||||
}
|
||||
var response struct {
|
||||
Result *ctypes.ResponseGenPrivAccount `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 {
|
||||
@ -275,7 +276,7 @@ func (c *ClientHTTP) Genesis() (*string, error) {
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -290,10 +291,10 @@ func (c *ClientHTTP) GetAccount(address []byte) (*ctypes.ResponseGetAccount, err
|
||||
return nil, err
|
||||
}
|
||||
var response struct {
|
||||
Result *ctypes.ResponseGetAccount `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 {
|
||||
@ -455,7 +456,7 @@ func (c *ClientHTTP) ListNames() (*ctypes.ResponseListNames, error) {
|
||||
return response.Result, nil
|
||||
}
|
||||
|
||||
func (c *ClientHTTP) ListUnconfirmedTxs() (*ctypes.ResponseListUnconfirmedTxs, error) {
|
||||
func (c *ClientHTTP) ListUnconfirmedTxs() ([]types.Tx, error) {
|
||||
values, err := argsToURLValues(nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -470,10 +471,10 @@ func (c *ClientHTTP) ListUnconfirmedTxs() (*ctypes.ResponseListUnconfirmedTxs, e
|
||||
return nil, err
|
||||
}
|
||||
var response struct {
|
||||
Result *ctypes.ResponseListUnconfirmedTxs `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 {
|
||||
@ -545,7 +546,7 @@ func (c *ClientHTTP) NetInfo() (*ctypes.ResponseNetInfo, error) {
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -560,10 +561,10 @@ func (c *ClientHTTP) SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*
|
||||
return nil, err
|
||||
}
|
||||
var response struct {
|
||||
Result *ctypes.ResponseSignTx `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 {
|
||||
@ -632,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"],
|
||||
@ -644,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 {
|
||||
@ -767,7 +768,7 @@ func (c *ClientJSON) DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, e
|
||||
return response.Result, nil
|
||||
}
|
||||
|
||||
func (c *ClientJSON) GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error) {
|
||||
func (c *ClientJSON) GenPrivAccount() (*acm.PrivAccount, error) {
|
||||
request := rpctypes.RPCRequest{
|
||||
JSONRPC: "2.0",
|
||||
Method: reverseFuncMap["GenPrivAccount"],
|
||||
@ -779,10 +780,10 @@ func (c *ClientJSON) GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error) {
|
||||
return nil, err
|
||||
}
|
||||
var response struct {
|
||||
Result *ctypes.ResponseGenPrivAccount `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 {
|
||||
@ -821,7 +822,7 @@ func (c *ClientJSON) Genesis() (*string, error) {
|
||||
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{
|
||||
JSONRPC: "2.0",
|
||||
Method: reverseFuncMap["GetAccount"],
|
||||
@ -833,10 +834,10 @@ func (c *ClientJSON) GetAccount(address []byte) (*ctypes.ResponseGetAccount, err
|
||||
return nil, err
|
||||
}
|
||||
var response struct {
|
||||
Result *ctypes.ResponseGetAccount `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 {
|
||||
@ -983,7 +984,7 @@ func (c *ClientJSON) ListNames() (*ctypes.ResponseListNames, error) {
|
||||
return response.Result, nil
|
||||
}
|
||||
|
||||
func (c *ClientJSON) ListUnconfirmedTxs() (*ctypes.ResponseListUnconfirmedTxs, error) {
|
||||
func (c *ClientJSON) ListUnconfirmedTxs() ([]types.Tx, error) {
|
||||
request := rpctypes.RPCRequest{
|
||||
JSONRPC: "2.0",
|
||||
Method: reverseFuncMap["ListUnconfirmedTxs"],
|
||||
@ -995,10 +996,10 @@ func (c *ClientJSON) ListUnconfirmedTxs() (*ctypes.ResponseListUnconfirmedTxs, e
|
||||
return nil, err
|
||||
}
|
||||
var response struct {
|
||||
Result *ctypes.ResponseListUnconfirmedTxs `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 {
|
||||
@ -1064,7 +1065,7 @@ func (c *ClientJSON) NetInfo() (*ctypes.ResponseNetInfo, error) {
|
||||
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{
|
||||
JSONRPC: "2.0",
|
||||
Method: reverseFuncMap["SignTx"],
|
||||
@ -1076,10 +1077,10 @@ func (c *ClientJSON) SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*
|
||||
return nil, err
|
||||
}
|
||||
var response struct {
|
||||
Result *ctypes.ResponseSignTx `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 {
|
||||
|
@ -129,10 +129,10 @@ func getNonce(t *testing.T, typ string, addr []byte) uint {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if ac.Account == nil {
|
||||
if ac == nil {
|
||||
return 0
|
||||
}
|
||||
return ac.Account.Sequence
|
||||
return ac.Sequence
|
||||
}
|
||||
|
||||
// get the account
|
||||
@ -142,28 +142,28 @@ func getAccount(t *testing.T, typ string, addr []byte) *account.Account {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return ac.Account
|
||||
return ac
|
||||
}
|
||||
|
||||
// sign transaction
|
||||
func signTx(t *testing.T, typ string, tx types.Tx, privAcc *account.PrivAccount) types.Tx {
|
||||
client := clients[typ]
|
||||
resp, err := client.SignTx(tx, []*account.PrivAccount{privAcc})
|
||||
signedTx, err := client.SignTx(tx, []*account.PrivAccount{privAcc})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return resp.Tx
|
||||
return signedTx
|
||||
}
|
||||
|
||||
// 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]
|
||||
resp, err := client.BroadcastTx(tx)
|
||||
rec, err := client.BroadcastTx(tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mempoolCount += 1
|
||||
return resp.Receipt
|
||||
return rec
|
||||
}
|
||||
|
||||
// dump all storage for an account. currently unused
|
||||
|
@ -25,11 +25,11 @@ func testStatus(t *testing.T, typ string) {
|
||||
|
||||
func testGenPriv(t *testing.T, typ string) {
|
||||
client := clients[typ]
|
||||
resp, err := client.GenPrivAccount()
|
||||
privAcc, err := client.GenPrivAccount()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(resp.PrivAccount.Address) == 0 {
|
||||
if len(privAcc.Address) == 0 {
|
||||
t.Fatal("Failed to generate an address")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user