diff --git a/erisdb/methods.go b/erisdb/methods.go index 77c19bee9232abe6e08b93b68c9a169f519ba381..13fd826f193c37920b51889bf583d13e5f7735a2 100644 --- a/erisdb/methods.go +++ b/erisdb/methods.go @@ -15,42 +15,37 @@ const ( ID = "socketrpc" SERVICE_NAME = "erisdb" - // Accounts - GET_ACCOUNTS = SERVICE_NAME + ".getAccounts" + GET_ACCOUNTS = SERVICE_NAME + ".getAccounts" // Accounts GET_ACCOUNT = SERVICE_NAME + ".getAccount" GET_STORAGE = SERVICE_NAME + ".getStorage" GET_STORAGE_AT = SERVICE_NAME + ".getStorageAt" GEN_PRIV_ACCOUNT = SERVICE_NAME + ".genPrivAccount" GEN_PRIV_ACCOUNT_FROM_KEY = SERVICE_NAME + ".genPrivAccountFromKey" - // Blockchain - GET_BLOCKCHAIN_INFO = SERVICE_NAME + ".getBlockchainInfo" - GET_GENESIS_HASH = SERVICE_NAME + ".getGenesisHash" - GET_LATEST_BLOCK_HEIGHT = SERVICE_NAME + ".getLatestBlockHeight" - GET_LATEST_BLOCK = SERVICE_NAME + ".getLatestBlock" - GET_BLOCKS = SERVICE_NAME + ".getBlocks" - GET_BLOCK = SERVICE_NAME + ".getBlock" - // Consensus - GET_CONSENSUS_STATE = SERVICE_NAME + ".getConsensusState" - GET_VALIDATORS = SERVICE_NAME + ".getValidators" - // Net - GET_NETWORK_INFO = SERVICE_NAME + ".getNetworkInfo" - GET_MONIKER = SERVICE_NAME + ".getMoniker" - GET_CHAIN_ID = SERVICE_NAME + ".getChainId" - IS_LISTENING = SERVICE_NAME + ".isListening" - GET_LISTENERS = SERVICE_NAME + ".getListeners" - GET_PEERS = SERVICE_NAME + ".getPeers" - GET_PEER = SERVICE_NAME + ".getPeer" - // Tx - CALL = SERVICE_NAME + ".call" - CALL_CODE = SERVICE_NAME + ".callCode" - BROADCAST_TX = SERVICE_NAME + ".broadcastTx" - GET_UNCONFIRMED_TXS = SERVICE_NAME + ".getUnconfirmedTxs" - SIGN_TX = SERVICE_NAME + ".signTx" - TRANSACT = SERVICE_NAME + ".transact" - // Events - EVENT_SUBSCRIBE = SERVICE_NAME + ".eventSubscribe" - EVENT_UNSUBSCRIBE = SERVICE_NAME + ".eventUnsubscribe" - EVENT_POLL = SERVICE_NAME + ".eventPoll" + GET_BLOCKCHAIN_INFO = SERVICE_NAME + ".getBlockchainInfo" // Blockchain + GET_GENESIS_HASH = SERVICE_NAME + ".getGenesisHash" + GET_LATEST_BLOCK_HEIGHT = SERVICE_NAME + ".getLatestBlockHeight" + GET_LATEST_BLOCK = SERVICE_NAME + ".getLatestBlock" + GET_BLOCKS = SERVICE_NAME + ".getBlocks" + GET_BLOCK = SERVICE_NAME + ".getBlock" + GET_CONSENSUS_STATE = SERVICE_NAME + ".getConsensusState" // Consensus + GET_VALIDATORS = SERVICE_NAME + ".getValidators" + GET_NETWORK_INFO = SERVICE_NAME + ".getNetworkInfo" // Net + GET_CLIENT_VERSION = SERVICE_NAME + ".getClientVersion" + GET_MONIKER = SERVICE_NAME + ".getMoniker" + GET_CHAIN_ID = SERVICE_NAME + ".getChainId" + IS_LISTENING = SERVICE_NAME + ".isListening" + GET_LISTENERS = SERVICE_NAME + ".getListeners" + GET_PEERS = SERVICE_NAME + ".getPeers" + GET_PEER = SERVICE_NAME + ".getPeer" + CALL = SERVICE_NAME + ".call" // Tx + CALL_CODE = SERVICE_NAME + ".callCode" + BROADCAST_TX = SERVICE_NAME + ".broadcastTx" + GET_UNCONFIRMED_TXS = SERVICE_NAME + ".getUnconfirmedTxs" + SIGN_TX = SERVICE_NAME + ".signTx" + TRANSACT = SERVICE_NAME + ".transact" + EVENT_SUBSCRIBE = SERVICE_NAME + ".eventSubscribe" // Events + EVENT_UNSUBSCRIBE = SERVICE_NAME + ".eventUnsubscribe" + EVENT_POLL = SERVICE_NAME + ".eventPoll" ) // The rpc method handlers. @@ -84,6 +79,7 @@ func (this *ErisDbMethods) getMethods() map[string]RequestHandlerFunc { dhMap[GET_VALIDATORS] = this.Validators // Network dhMap[GET_NETWORK_INFO] = this.NetworkInfo + dhMap[GET_CLIENT_VERSION] = this.ClientVersion dhMap[GET_MONIKER] = this.Moniker dhMap[GET_CHAIN_ID] = this.ChainId dhMap[IS_LISTENING] = this.Listening @@ -287,6 +283,14 @@ func (this *ErisDbMethods) NetworkInfo(request *rpc.RPCRequest, requester interf return info, 0, nil } +func (this *ErisDbMethods) ClientVersion(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { + version, errC := this.pipe.Net().ClientVersion() + if errC != nil { + return nil, rpc.INTERNAL_ERROR, errC + } + return &ep.ClientVersion{version}, 0, nil +} + func (this *ErisDbMethods) Moniker(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { moniker, errC := this.pipe.Net().Moniker() if errC != nil { diff --git a/erisdb/pipe/net.go b/erisdb/pipe/net.go index d088ab69c99f66d0b3d3eb2152ecdd413f8c9174..fe7b6e6f3c0445483b7aaad8f35c193980ef5c01 100644 --- a/erisdb/pipe/net.go +++ b/erisdb/pipe/net.go @@ -17,9 +17,9 @@ func newNetwork(p2pSwitch *p2p.Switch) *network { // Get the complete net info. func (this *network) Info() (*NetworkInfo, error) { - listening := this.p2pSwitch.IsListening() - + version := config.GetString("version") moniker := config.GetString("moniker") + listening := this.p2pSwitch.IsListening() listeners := []string{} for _, listener := range this.p2pSwitch.Listeners() { listeners = append(listeners, listener.String()) @@ -30,6 +30,7 @@ func (this *network) Info() (*NetworkInfo, error) { peers = append(peers, p) } return &NetworkInfo{ + version, moniker, listening, listeners, @@ -37,6 +38,11 @@ func (this *network) Info() (*NetworkInfo, error) { }, nil } +// Get the client version +func (this *network) ClientVersion() (string, error) { + return config.GetString("version"), nil +} + // Get the moniker func (this *network) Moniker() (string, error) { return config.GetString("moniker"), nil diff --git a/erisdb/pipe/pipe.go b/erisdb/pipe/pipe.go index 6ea5ac58a65baa0efe244bd5a35828930eac51fc..156607199b638dbedd5d868cfdf96ba1d249b0ba 100644 --- a/erisdb/pipe/pipe.go +++ b/erisdb/pipe/pipe.go @@ -50,6 +50,7 @@ type ( Net interface { Info() (*NetworkInfo, error) + ClientVersion() (string, error) Moniker() (string, error) Listening() (bool, error) Listeners() ([]string, error) diff --git a/erisdb/pipe/types.go b/erisdb/pipe/types.go index c23b0bfe1dff50b85c797c6eff483b3a6bffbc12..2901ec7107a702bb766d582b5c8413f5b31b67bb 100644 --- a/erisdb/pipe/types.go +++ b/erisdb/pipe/types.go @@ -101,10 +101,15 @@ type ( // NetworkInfo NetworkInfo struct { - Moniker string `json:"moniker"` - Listening bool `json:"listening"` - Listeners []string `json:"listeners"` - Peers []*Peer `json:"peers"` + ClientVersion string `json:"client_version"` + Moniker string `json:"moniker"` + Listening bool `json:"listening"` + Listeners []string `json:"listeners"` + Peers []*Peer `json:"peers"` + } + + ClientVersion struct { + ClientVersion string `json:"client_version"` } Moniker struct { diff --git a/erisdb/restServer.go b/erisdb/restServer.go index c0c74591bf3a2b1a11f86e4e41958a082d6e1d96..08819b27c6c5c8ffc8de7584fb8441694bd115b0 100644 --- a/erisdb/restServer.go +++ b/erisdb/restServer.go @@ -52,6 +52,7 @@ func (this *RestServer) Start(config *server.ServerConfig, router *gin.Engine) { router.DELETE("/event_subs/:id", this.handleEventUnsubscribe) // Network router.GET("/network", this.handleNetworkInfo) + router.GET("/network/client_version", this.handleClientVersion) router.GET("/network/moniker", this.handleMoniker) router.GET("/network/listening", this.handleListening) router.GET("/network/listeners", this.handleListeners) @@ -283,6 +284,15 @@ func (this *RestServer) handleNetworkInfo(c *gin.Context) { this.codec.Encode(nInfo, c.Writer) } +func (this *RestServer) handleClientVersion(c *gin.Context) { + version, err := this.pipe.Net().ClientVersion() + if err != nil { + c.AbortWithError(500, err) + } + c.Writer.WriteHeader(200) + this.codec.Encode(&ep.ClientVersion{version}, c.Writer) +} + func (this *RestServer) handleMoniker(c *gin.Context) { moniker, err := this.pipe.Net().Moniker() if err != nil { diff --git a/erisdb/serve.go b/erisdb/serve.go index a4aed65e8460d09b4ec628f05932f1cc8480fe29..855c6a08fdca986d48a0c9bbe8e084d0820a8724 100644 --- a/erisdb/serve.go +++ b/erisdb/serve.go @@ -1,7 +1,6 @@ package erisdb import ( - "fmt" ep "github.com/eris-ltd/erisdb/erisdb/pipe" "github.com/eris-ltd/erisdb/server" "github.com/tendermint/log15" @@ -13,16 +12,11 @@ import ( "path" ) +const VERSION = "0.9.0" + var log = log15.New("module", "eris/erisdb_server") var tmConfig cfg.Config -func init() { - cfg.OnConfig(func(newConfig cfg.Config) { - fmt.Println("NEWCONFIG") - tmConfig = newConfig - }) -} - // This function returns a properly configured ErisDb server process with a running // tendermint node attached to it. To start listening for incoming requests, call // 'Start()' on the process. Make sure to register any start event listeners before @@ -51,8 +45,9 @@ func ServeErisDB(workDir string) (*server.ServeProcess, error) { // Get tendermint configuration tmConfig = tmcfg.GetConfig(workDir) + tmConfig.Set("version", VERSION) cfg.ApplyConfig(tmConfig) // Notify modules of new config - + // Set the node up. nodeRd := make(chan struct{}) nd := node.NewNode() diff --git a/test/mock/mock_web_api_test.go b/test/mock/mock_web_api_test.go index a9dd13c3f6a61de95ef8ced841e5431ef0c758f2..00cfd3c8584c2fd93676acac40930ec6d67c1073 100644 --- a/test/mock/mock_web_api_test.go +++ b/test/mock/mock_web_api_test.go @@ -93,7 +93,15 @@ func (this *WebApiSuite) Test_B0_NetworkInfo() { this.Equal(ret, this.testData.Output.NetworkInfo) } -func (this *WebApiSuite) Test_B1_Moniker() { +func (this *WebApiSuite) Test_B1_ClientVersion() { + resp := this.get("/network/client_version") + ret := &ep.ClientVersion{} + errD := this.codec.Decode(ret, resp.Body) + this.NoError(errD) + this.Equal(ret, this.testData.Output.ClientVersion) +} + +func (this *WebApiSuite) Test_B2_Moniker() { resp := this.get("/network/moniker") ret := &ep.Moniker{} errD := this.codec.Decode(ret, resp.Body) @@ -101,7 +109,7 @@ func (this *WebApiSuite) Test_B1_Moniker() { this.Equal(ret, this.testData.Output.Moniker) } -func (this *WebApiSuite) Test_B2_Listening() { +func (this *WebApiSuite) Test_B3_Listening() { resp := this.get("/network/listening") ret := &ep.Listening{} errD := this.codec.Decode(ret, resp.Body) @@ -109,7 +117,7 @@ func (this *WebApiSuite) Test_B2_Listening() { this.Equal(ret, this.testData.Output.Listening) } -func (this *WebApiSuite) Test_B3_Listeners() { +func (this *WebApiSuite) Test_B4_Listeners() { resp := this.get("/network/listeners") ret := &ep.Listeners{} errD := this.codec.Decode(ret, resp.Body) @@ -117,7 +125,7 @@ func (this *WebApiSuite) Test_B3_Listeners() { this.Equal(ret, this.testData.Output.Listeners) } -func (this *WebApiSuite) Test_B4_Peers() { +func (this *WebApiSuite) Test_B5_Peers() { resp := this.get("/network/peers") ret := []*ep.Peer{} errD := this.codec.Decode(ret, resp.Body) diff --git a/test/mock/pipe.go b/test/mock/pipe.go index 00134082afb0466f098c799dc12b5210fe08f547..20628373105871e3b799239b34da8dbbd1187ceb 100644 --- a/test/mock/pipe.go +++ b/test/mock/pipe.go @@ -166,6 +166,10 @@ func (this *net) Info() (*ep.NetworkInfo, error) { return this.testOutput.NetworkInfo, nil } +func (this *net) ClientVersion() (string, error) { + return this.testOutput.ClientVersion.ClientVersion, nil +} + func (this *net) Moniker() (string, error) { return this.testOutput.Moniker.Moniker, nil } diff --git a/test/testdata/testdata/testdata.go b/test/testdata/testdata/testdata.go index 1df8a4603c95c45521c3c2e4511b9db9a519e2c5..011df4acff12e2491408f4e0cca1a9eb98570325 100644 --- a/test/testdata/testdata/testdata.go +++ b/test/testdata/testdata/testdata.go @@ -121,11 +121,15 @@ var testDataJson = `{ "unbonding_validators": [] }, "network_info": { + "client_version": "0.9.0", "moniker": "anothertester", "listening": false, "listeners": [], "peers": [] }, + "client_version": { + "client_version": "0.9.0" + }, "moniker": { "moniker": "anothertester" }, @@ -238,6 +242,7 @@ var testDataJson = `{ }, "storage_at": {}, "blockchain_info": { + "client_version": "", "chain_id": "my_tests", "genesis_hash": "DA4F4DC4A54620F1E0AA1213631C4DC2957B7415E3F8C066C30009BC57C4E5FC", "latest_block_height": 0, @@ -295,6 +300,7 @@ type ( ConsensusState *ep.ConsensusState `json:"consensus_state"` Validators *ep.ValidatorList `json:"validators"` NetworkInfo *ep.NetworkInfo `json:"network_info"` + ClientVersion *ep.ClientVersion `json:"client_version"` Moniker *ep.Moniker `json:"moniker"` Listening *ep.Listening `json:"listening"` Listeners *ep.Listeners `json:"listeners"` diff --git a/test/web_api/web_api_test.go b/test/web_api/web_api_test.go index ebfc6c75046a29c6a7aa21e32a90390944c03b45..20e71937fc6b2b8dc7858811f9b827ee56513d4b 100644 --- a/test/web_api/web_api_test.go +++ b/test/web_api/web_api_test.go @@ -84,7 +84,15 @@ func (this *WebApiSuite) Test_B0_NetworkInfo() { this.Equal(ret, this.testData.Output.NetworkInfo) } -func (this *WebApiSuite) Test_B1_Moniker() { +func (this *WebApiSuite) Test_B1_ClientVersion() { + resp := this.get("/network/client_version") + ret := &ep.ClientVersion{} + errD := this.codec.Decode(ret, resp.Body) + this.NoError(errD) + this.Equal(ret, this.testData.Output.ClientVersion) +} + +func (this *WebApiSuite) Test_B2_Moniker() { resp := this.get("/network/moniker") ret := &ep.Moniker{} errD := this.codec.Decode(ret, resp.Body) @@ -92,7 +100,7 @@ func (this *WebApiSuite) Test_B1_Moniker() { this.Equal(ret, this.testData.Output.Moniker) } -func (this *WebApiSuite) Test_B2_Listening() { +func (this *WebApiSuite) Test_B3_Listening() { resp := this.get("/network/listening") ret := &ep.Listening{} errD := this.codec.Decode(ret, resp.Body) @@ -100,7 +108,7 @@ func (this *WebApiSuite) Test_B2_Listening() { this.Equal(ret, this.testData.Output.Listening) } -func (this *WebApiSuite) Test_B3_Listeners() { +func (this *WebApiSuite) Test_B4_Listeners() { resp := this.get("/network/listeners") ret := &ep.Listeners{} errD := this.codec.Decode(ret, resp.Body) @@ -108,7 +116,7 @@ func (this *WebApiSuite) Test_B3_Listeners() { this.Equal(ret, this.testData.Output.Listeners) } -func (this *WebApiSuite) Test_B4_Peers() { +func (this *WebApiSuite) Test_B5_Peers() { resp := this.get("/network/peers") ret := []*ep.Peer{} errD := this.codec.Decode(ret, resp.Body)