forked from TrueCloudLab/neoneo-go
Merge pull request #1039 from nspcc-dev/neo3/rpc/getversion
rpc: update `getversion` RPC-call
This commit is contained in:
commit
4264a758ac
4 changed files with 29 additions and 14 deletions
|
@ -345,16 +345,9 @@ func (s *Server) HandshakedPeersCount() int {
|
|||
|
||||
// getVersionMsg returns current version message.
|
||||
func (s *Server) getVersionMsg() (*Message, error) {
|
||||
var port uint16
|
||||
_, portStr, err := net.SplitHostPort(s.transport.Address())
|
||||
port, err := s.Port()
|
||||
if err != nil {
|
||||
port = s.Port
|
||||
} else {
|
||||
p, err := strconv.ParseUint(portStr, 10, 16)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
port = uint16(p)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
capabilities := []capability.Capability{
|
||||
|
@ -942,3 +935,19 @@ func (s *Server) broadcastTxLoop() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Port returns actual server port. It may differs from that of server.Config.
|
||||
func (s *Server) Port() (uint16, error) {
|
||||
var port uint16
|
||||
_, portStr, err := net.SplitHostPort(s.transport.Address())
|
||||
if err != nil {
|
||||
port = s.ServerConfig.Port
|
||||
} else {
|
||||
p, err := strconv.ParseUint(portStr, 10, 16)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
port = uint16(p)
|
||||
}
|
||||
return port, nil
|
||||
}
|
||||
|
|
|
@ -541,10 +541,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
|||
invoke: func(c *Client) (interface{}, error) {
|
||||
return c.GetVersion()
|
||||
},
|
||||
serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"tcp_port":20332,"nonce":2153672787,"useragent":"/NEO-GO:0.73.1-pre-273-ge381358/"}}`,
|
||||
serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"tcp_port":20332,"ws_port":20342,"nonce":2153672787,"user_agent":"/NEO-GO:0.73.1-pre-273-ge381358/"}}`,
|
||||
result: func(c *Client) interface{} {
|
||||
return &result.Version{
|
||||
Port: uint16(20332),
|
||||
TCPPort: uint16(20332),
|
||||
WSPort: uint16(20342),
|
||||
Nonce: 2153672787,
|
||||
UserAgent: "/NEO-GO:0.73.1-pre-273-ge381358/",
|
||||
}
|
||||
|
|
|
@ -4,8 +4,9 @@ type (
|
|||
// Version model used for reporting server version
|
||||
// info.
|
||||
Version struct {
|
||||
Port uint16 `json:"tcp_port"`
|
||||
TCPPort uint16 `json:"tcp_port"`
|
||||
WSPort uint16 `json:"ws_port,omitempty"`
|
||||
Nonce uint32 `json:"nonce"`
|
||||
UserAgent string `json:"useragent"`
|
||||
UserAgent string `json:"user_agent"`
|
||||
}
|
||||
)
|
||||
|
|
|
@ -442,8 +442,12 @@ func (s *Server) getBlockHash(reqParams request.Params) (interface{}, *response.
|
|||
}
|
||||
|
||||
func (s *Server) getVersion(_ request.Params) (interface{}, *response.Error) {
|
||||
port, err := s.coreServer.Port()
|
||||
if err != nil {
|
||||
return nil, response.NewInternalServerError("Cannot fetch tcp port", err)
|
||||
}
|
||||
return result.Version{
|
||||
Port: s.coreServer.Port,
|
||||
TCPPort: port,
|
||||
Nonce: s.coreServer.ID(),
|
||||
UserAgent: s.coreServer.UserAgent,
|
||||
}, nil
|
||||
|
|
Loading…
Reference in a new issue