use gendoc struct for genesis rpc response
This commit is contained in:
parent
7a57f1069c
commit
bf1c9a869c
|
@ -3,6 +3,7 @@ package core
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
|
"github.com/tendermint/tendermint/binary"
|
||||||
dbm "github.com/tendermint/tendermint/db"
|
dbm "github.com/tendermint/tendermint/db"
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||||
sm "github.com/tendermint/tendermint/state"
|
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!)
|
// cache the genesis structure
|
||||||
func Genesis() (*string, error) {
|
var genDoc *sm.GenesisDoc
|
||||||
|
|
||||||
|
func Genesis() (*sm.GenesisDoc, error) {
|
||||||
|
if genDoc == nil {
|
||||||
b, err := ioutil.ReadFile(config.GetString("genesis_file"))
|
b, err := ioutil.ReadFile(config.GetString("genesis_file"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
ret := string(b)
|
binary.ReadJSON(&genDoc, b, &err)
|
||||||
return &ret, nil
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return genDoc, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"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"
|
||||||
|
sm "github.com/tendermint/tendermint/state"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -22,7 +23,7 @@ type Client interface {
|
||||||
DumpConsensusState() (*ctypes.ResponseDumpConsensusState, error)
|
DumpConsensusState() (*ctypes.ResponseDumpConsensusState, error)
|
||||||
DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, error)
|
DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, error)
|
||||||
GenPrivAccount() (*acm.PrivAccount, error)
|
GenPrivAccount() (*acm.PrivAccount, error)
|
||||||
Genesis() (*string, error)
|
Genesis() (*sm.GenesisDoc, error)
|
||||||
GetAccount(address []byte) (*acm.Account, 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)
|
||||||
|
@ -246,7 +247,7 @@ func (c *ClientHTTP) GenPrivAccount() (*acm.PrivAccount, error) {
|
||||||
return response.Result, nil
|
return response.Result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientHTTP) Genesis() (*string, error) {
|
func (c *ClientHTTP) Genesis() (*sm.GenesisDoc, error) {
|
||||||
values, err := argsToURLValues(nil)
|
values, err := argsToURLValues(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -261,7 +262,7 @@ func (c *ClientHTTP) Genesis() (*string, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response struct {
|
var response struct {
|
||||||
Result *string `json:"result"`
|
Result *sm.GenesisDoc `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"`
|
||||||
|
@ -795,7 +796,7 @@ func (c *ClientJSON) GenPrivAccount() (*acm.PrivAccount, error) {
|
||||||
return response.Result, nil
|
return response.Result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientJSON) Genesis() (*string, error) {
|
func (c *ClientJSON) Genesis() (*sm.GenesisDoc, error) {
|
||||||
request := rpctypes.RPCRequest{
|
request := rpctypes.RPCRequest{
|
||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
Method: reverseFuncMap["Genesis"],
|
Method: reverseFuncMap["Genesis"],
|
||||||
|
@ -807,7 +808,7 @@ func (c *ClientJSON) Genesis() (*string, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response struct {
|
var response struct {
|
||||||
Result *string `json:"result"`
|
Result *sm.GenesisDoc `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"`
|
||||||
|
|
Loading…
Reference in New Issue