rpc: move getblockhash RPC to a separate func

This commit is contained in:
Evgenii Stratonikov 2020-03-13 10:06:52 +03:00
parent 90fdde4018
commit e442ebdb69

View file

@ -210,18 +210,7 @@ Methods:
results = s.chain.BlockHeight() + 1
case "getblockhash":
param, ok := reqParams.ValueWithType(0, request.NumberT)
if !ok {
resultsErr = response.ErrInvalidParams
break Methods
}
num, err := s.blockHeightFromParam(param)
if err != nil {
resultsErr = response.ErrInvalidParams
break Methods
}
results = s.chain.GetHeaderHash(num)
results, resultsErr = s.getBlockHash(reqParams)
case "getblockheader":
results, resultsErr = s.getBlockHeader(reqParams)
@ -309,6 +298,19 @@ Methods:
s.WriteResponse(req, w, results)
}
func (s *Server) getBlockHash(reqParams request.Params) (interface{}, error) {
param, ok := reqParams.ValueWithType(0, request.NumberT)
if !ok {
return nil, response.ErrInvalidParams
}
num, err := s.blockHeightFromParam(param)
if err != nil {
return nil, response.ErrInvalidParams
}
return s.chain.GetHeaderHash(num), nil
}
func (s *Server) getVersion(_ request.Params) (interface{}, error) {
return result.Version{
Port: s.coreServer.Port,