rpc: add getblockheadercount call

See neo-project/neo-modules#504.
This commit is contained in:
Roman Khimov 2021-02-07 22:01:22 +03:00
parent 66471de9d2
commit e0c7a3b77c
5 changed files with 38 additions and 2 deletions

View file

@ -40,6 +40,7 @@ which would yield the response:
| `getblockcount` | | `getblockcount` |
| `getblockhash` | | `getblockhash` |
| `getblockheader` | | `getblockheader` |
| `getblockheadercount` |
| `getblocksysfee` | | `getblocksysfee` |
| `getconnectioncount` | | `getconnectioncount` |
| `getcontractstate` | | `getcontractstate` |

View file

@ -155,6 +155,15 @@ func (c *Client) GetBlockHeader(hash util.Uint256) (*block.Header, error) {
return h, nil return h, nil
} }
// GetBlockHeaderCount returns the number of headers in the main chain.
func (c *Client) GetBlockHeaderCount() (uint32, error) {
var resp uint32
if err := c.performRequest("getblockheadercount", request.NewRawParams(), &resp); err != nil {
return resp, err
}
return resp, nil
}
// GetBlockHeaderVerbose returns the corresponding block header information from Json format string // GetBlockHeaderVerbose returns the corresponding block header information from Json format string
// according to the specified script hash. // according to the specified script hash.
func (c *Client) GetBlockHeaderVerbose(hash util.Uint256) (*result.Header, error) { func (c *Client) GetBlockHeaderVerbose(hash util.Uint256) (*result.Header, error) {

View file

@ -280,6 +280,18 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
}, },
}, },
}, },
"getblockheadercount": {
{
name: "positive",
invoke: func(c *Client) (interface{}, error) {
return c.GetBlockHeaderCount()
},
serverResponse: `{"jsonrpc":"2.0","id":1,"result":2021}`,
result: func(c *Client) interface{} {
return uint32(2021)
},
},
},
"getblocksysfee": { "getblocksysfee": {
{ {
name: "positive", name: "positive",

View file

@ -29,12 +29,12 @@ import (
"github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/network" "github.com/nspcc-dev/neo-go/pkg/network"
"github.com/nspcc-dev/neo-go/pkg/services/oracle"
"github.com/nspcc-dev/neo-go/pkg/services/oracle/broadcaster"
"github.com/nspcc-dev/neo-go/pkg/rpc" "github.com/nspcc-dev/neo-go/pkg/rpc"
"github.com/nspcc-dev/neo-go/pkg/rpc/request" "github.com/nspcc-dev/neo-go/pkg/rpc/request"
"github.com/nspcc-dev/neo-go/pkg/rpc/response" "github.com/nspcc-dev/neo-go/pkg/rpc/response"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result" "github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
"github.com/nspcc-dev/neo-go/pkg/services/oracle"
"github.com/nspcc-dev/neo-go/pkg/services/oracle/broadcaster"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
@ -99,6 +99,7 @@ var rpcHandlers = map[string]func(*Server, request.Params) (interface{}, *respon
"getblockcount": (*Server).getBlockCount, "getblockcount": (*Server).getBlockCount,
"getblockhash": (*Server).getBlockHash, "getblockhash": (*Server).getBlockHash,
"getblockheader": (*Server).getBlockHeader, "getblockheader": (*Server).getBlockHeader,
"getblockheadercount": (*Server).getBlockHeaderCount,
"getblocksysfee": (*Server).getBlockSysFee, "getblocksysfee": (*Server).getBlockSysFee,
"getcommittee": (*Server).getCommittee, "getcommittee": (*Server).getCommittee,
"getconnectioncount": (*Server).getConnectionCount, "getconnectioncount": (*Server).getConnectionCount,
@ -433,6 +434,10 @@ func (s *Server) getBlockCount(_ request.Params) (interface{}, *response.Error)
return s.chain.BlockHeight() + 1, nil return s.chain.BlockHeight() + 1, nil
} }
func (s *Server) getBlockHeaderCount(_ request.Params) (interface{}, *response.Error) {
return s.chain.HeaderHeight() + 1, nil
}
func (s *Server) getConnectionCount(_ request.Params) (interface{}, *response.Error) { func (s *Server) getConnectionCount(_ request.Params) (interface{}, *response.Error) {
return s.coreServer.PeerCount(), nil return s.coreServer.PeerCount(), nil
} }

View file

@ -494,6 +494,15 @@ var rpcTestCases = map[string][]rpcTestCase{
fail: true, fail: true,
}, },
}, },
"getblockheadercount": {
{
params: "[]",
result: func(e *executor) interface{} {
v := int(e.chain.HeaderHeight() + 1)
return &v
},
},
},
"getblocksysfee": { "getblocksysfee": {
{ {
name: "positive", name: "positive",