From bf1c9a869c5f67e0cdc0ea703b08ec5fab43bfa1 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Wed, 3 Jun 2015 19:26:31 -0400 Subject: [PATCH] use gendoc struct for genesis rpc response --- rpc/core/net.go | 22 +++++++++++++++------- rpc/core_client/client_methods.go | 23 ++++++++++++----------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/rpc/core/net.go b/rpc/core/net.go index f74510e78..caa6b922d 100644 --- a/rpc/core/net.go +++ b/rpc/core/net.go @@ -3,6 +3,7 @@ package core import ( "io/ioutil" + "github.com/tendermint/tendermint/binary" dbm "github.com/tendermint/tendermint/db" ctypes "github.com/tendermint/tendermint/rpc/core/types" sm "github.com/tendermint/tendermint/state" @@ -62,12 +63,19 @@ func NetInfo() (*ctypes.ResponseNetInfo, error) { //----------------------------------------------------------------------------- -// returns pointer because the rpc-gen code returns nil (TODO!) -func Genesis() (*string, error) { - b, err := ioutil.ReadFile(config.GetString("genesis_file")) - if err != nil { - return nil, err +// cache the genesis structure +var genDoc *sm.GenesisDoc + +func Genesis() (*sm.GenesisDoc, error) { + if genDoc == nil { + b, err := ioutil.ReadFile(config.GetString("genesis_file")) + if err != nil { + return nil, err + } + binary.ReadJSON(&genDoc, b, &err) + if err != nil { + return nil, err + } } - ret := string(b) - return &ret, nil + return genDoc, nil } diff --git a/rpc/core_client/client_methods.go b/rpc/core_client/client_methods.go index 9ac669842..a880c29ea 100644 --- a/rpc/core_client/client_methods.go +++ b/rpc/core_client/client_methods.go @@ -9,6 +9,7 @@ import ( "github.com/tendermint/tendermint/binary" ctypes "github.com/tendermint/tendermint/rpc/core/types" rpctypes "github.com/tendermint/tendermint/rpc/types" + sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" "io/ioutil" "net/http" @@ -22,7 +23,7 @@ type Client interface { DumpConsensusState() (*ctypes.ResponseDumpConsensusState, error) DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, error) GenPrivAccount() (*acm.PrivAccount, error) - Genesis() (*string, error) + Genesis() (*sm.GenesisDoc, error) GetAccount(address []byte) (*acm.Account, error) GetBlock(height uint) (*ctypes.ResponseGetBlock, error) GetName(name string) (*types.NameRegEntry, error) @@ -246,7 +247,7 @@ func (c *ClientHTTP) GenPrivAccount() (*acm.PrivAccount, error) { return response.Result, nil } -func (c *ClientHTTP) Genesis() (*string, error) { +func (c *ClientHTTP) Genesis() (*sm.GenesisDoc, error) { values, err := argsToURLValues(nil) if err != nil { return nil, err @@ -261,10 +262,10 @@ func (c *ClientHTTP) Genesis() (*string, error) { return nil, err } var response struct { - Result *string `json:"result"` - Error string `json:"error"` - Id string `json:"id"` - JSONRPC string `json:"jsonrpc"` + Result *sm.GenesisDoc `json:"result"` + Error string `json:"error"` + Id string `json:"id"` + JSONRPC string `json:"jsonrpc"` } binary.ReadJSON(&response, body, &err) if err != nil { @@ -795,7 +796,7 @@ func (c *ClientJSON) GenPrivAccount() (*acm.PrivAccount, error) { return response.Result, nil } -func (c *ClientJSON) Genesis() (*string, error) { +func (c *ClientJSON) Genesis() (*sm.GenesisDoc, error) { request := rpctypes.RPCRequest{ JSONRPC: "2.0", Method: reverseFuncMap["Genesis"], @@ -807,10 +808,10 @@ func (c *ClientJSON) Genesis() (*string, error) { return nil, err } var response struct { - Result *string `json:"result"` - Error string `json:"error"` - Id string `json:"id"` - JSONRPC string `json:"jsonrpc"` + Result *sm.GenesisDoc `json:"result"` + Error string `json:"error"` + Id string `json:"id"` + JSONRPC string `json:"jsonrpc"` } binary.ReadJSON(&response, body, &err) if err != nil {