rpc/server: allow specifying number for getblockheader
As it should be allowed.
This commit is contained in:
parent
dfb26f9ab2
commit
2ef9ec0756
2 changed files with 25 additions and 12 deletions
|
@ -382,31 +382,39 @@ func (s *Server) getConnectionCount(_ request.Params) (interface{}, *response.Er
|
|||
return s.coreServer.PeerCount(), nil
|
||||
}
|
||||
|
||||
func (s *Server) getBlock(reqParams request.Params) (interface{}, *response.Error) {
|
||||
func (s *Server) blockHashFromParam(param *request.Param) (util.Uint256, *response.Error) {
|
||||
var hash util.Uint256
|
||||
|
||||
param, ok := reqParams.Value(0)
|
||||
if !ok {
|
||||
return nil, response.ErrInvalidParams
|
||||
}
|
||||
|
||||
switch param.Type {
|
||||
case request.StringT:
|
||||
var err error
|
||||
hash, err = param.GetUint256()
|
||||
if err != nil {
|
||||
return nil, response.ErrInvalidParams
|
||||
return hash, response.ErrInvalidParams
|
||||
}
|
||||
case request.NumberT:
|
||||
num, err := s.blockHeightFromParam(param)
|
||||
if err != nil {
|
||||
return nil, response.ErrInvalidParams
|
||||
return hash, response.ErrInvalidParams
|
||||
}
|
||||
hash = s.chain.GetHeaderHash(num)
|
||||
default:
|
||||
return hash, response.ErrInvalidParams
|
||||
}
|
||||
return hash, nil
|
||||
}
|
||||
|
||||
func (s *Server) getBlock(reqParams request.Params) (interface{}, *response.Error) {
|
||||
param, ok := reqParams.Value(0)
|
||||
if !ok {
|
||||
return nil, response.ErrInvalidParams
|
||||
}
|
||||
|
||||
hash, respErr := s.blockHashFromParam(param)
|
||||
if respErr != nil {
|
||||
return nil, respErr
|
||||
}
|
||||
|
||||
block, err := s.chain.GetBlock(hash)
|
||||
if err != nil {
|
||||
return nil, response.NewInternalServerError(fmt.Sprintf("Problem locating block with hash: %s", hash), err)
|
||||
|
@ -771,13 +779,14 @@ func (s *Server) getBlockSysFee(reqParams request.Params) (interface{}, *respons
|
|||
func (s *Server) getBlockHeader(reqParams request.Params) (interface{}, *response.Error) {
|
||||
var verbose bool
|
||||
|
||||
param, ok := reqParams.ValueWithType(0, request.StringT)
|
||||
param, ok := reqParams.Value(0)
|
||||
if !ok {
|
||||
return nil, response.ErrInvalidParams
|
||||
}
|
||||
hash, err := param.GetUint256()
|
||||
if err != nil {
|
||||
return nil, response.ErrInvalidParams
|
||||
|
||||
hash, respErr := s.blockHashFromParam(param)
|
||||
if respErr != nil {
|
||||
return nil, respErr
|
||||
}
|
||||
|
||||
param, ok = reqParams.ValueWithType(1, request.NumberT)
|
||||
|
|
|
@ -910,6 +910,10 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) []
|
|||
t.Run("verbose=0", func(t *testing.T) {
|
||||
runCase(t, fmt.Sprintf(rpc, `["`+testHeaderHash+`", 0]`), &encoded, new(string))
|
||||
})
|
||||
|
||||
t.Run("by number", func(t *testing.T) {
|
||||
runCase(t, fmt.Sprintf(rpc, `[1]`), &encoded, new(string))
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("verbose != 0", func(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue