rpc: add Magic to Version

This commit is contained in:
Anna Shaleva 2020-10-14 16:52:49 +03:00
parent c50f3db6ad
commit 474d2dfb65
3 changed files with 10 additions and 5 deletions

View file

@ -631,9 +631,10 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
invoke: func(c *Client) (interface{}, error) { invoke: func(c *Client) (interface{}, error) {
return c.GetVersion() return c.GetVersion()
}, },
serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"tcpport":20332,"wsport":20342,"nonce":2153672787,"useragent":"/NEO-GO:0.73.1-pre-273-ge381358/"}}`, serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"magic":42,"tcpport":20332,"wsport":20342,"nonce":2153672787,"useragent":"/NEO-GO:0.73.1-pre-273-ge381358/"}}`,
result: func(c *Client) interface{} { result: func(c *Client) interface{} {
return &result.Version{ return &result.Version{
Magic: netmode.UnitTestNet,
TCPPort: uint16(20332), TCPPort: uint16(20332),
WSPort: uint16(20342), WSPort: uint16(20342),
Nonce: 2153672787, Nonce: 2153672787,

View file

@ -1,9 +1,12 @@
package result package result
import "github.com/nspcc-dev/neo-go/pkg/config/netmode"
type ( type (
// Version model used for reporting server version // Version model used for reporting server version
// info. // info.
Version struct { Version struct {
Magic netmode.Magic `json:"magic"`
TCPPort uint16 `json:"tcpport"` TCPPort uint16 `json:"tcpport"`
WSPort uint16 `json:"wsport,omitempty"` WSPort uint16 `json:"wsport,omitempty"`
Nonce uint32 `json:"nonce"` Nonce uint32 `json:"nonce"`

View file

@ -466,6 +466,7 @@ func (s *Server) getVersion(_ request.Params) (interface{}, *response.Error) {
return nil, response.NewInternalServerError("Cannot fetch tcp port", err) return nil, response.NewInternalServerError("Cannot fetch tcp port", err)
} }
return result.Version{ return result.Version{
Magic: s.network,
TCPPort: port, TCPPort: port,
Nonce: s.coreServer.ID(), Nonce: s.coreServer.ID(),
UserAgent: s.coreServer.UserAgent, UserAgent: s.coreServer.UserAgent,