rpc/server: implement getstateheight RPC

This commit is contained in:
Evgenii Stratonikov 2020-06-04 11:09:07 +03:00
parent 4de22247d5
commit 6b42e9306a
3 changed files with 34 additions and 0 deletions

View file

@ -0,0 +1,7 @@
package result
// StateHeight is a result of getstateheight RPC.
type StateHeight struct {
BlockHeight uint32 `json:"blockHeight"`
StateHeight uint32 `json:"stateHeight"`
}

View file

@ -100,6 +100,7 @@ var rpcHandlers = map[string]func(*Server, request.Params) (interface{}, *respon
"getpeers": (*Server).getPeers,
"getrawmempool": (*Server).getRawMempool,
"getrawtransaction": (*Server).getrawtransaction,
"getstateheight": (*Server).getStateHeight,
"getstateroot": (*Server).getStateRoot,
"getstorage": (*Server).getStorage,
"gettransactionheight": (*Server).getTransactionHeight,
@ -774,6 +775,18 @@ func (s *Server) contractScriptHashFromParam(param *request.Param) (util.Uint160
return result, nil
}
func (s *Server) getStateHeight(_ request.Params) (interface{}, *response.Error) {
var height = s.chain.BlockHeight()
var stateHeight uint32
if s.chain.GetConfig().StateRootInHeader {
stateHeight = height - 1
}
return &result.StateHeight{
BlockHeight: height,
StateHeight: stateHeight,
}, nil
}
func (s *Server) getStateRoot(ps request.Params) (interface{}, *response.Error) {
p := ps.Value(0)
if p == nil {

View file

@ -285,6 +285,20 @@ var rpcTestCases = map[string][]rpcTestCase{
check: checkNep5Transfers,
},
},
"getstateheight": {
{
name: "positive",
params: `[]`,
result: func(_ *executor) interface{} { return new(result.StateHeight) },
check: func(t *testing.T, e *executor, res interface{}) {
sh, ok := res.(*result.StateHeight)
require.True(t, ok)
require.Equal(t, e.chain.BlockHeight(), sh.BlockHeight)
require.Equal(t, uint32(0), sh.StateHeight)
},
},
},
"getstateroot": {
{
name: "no params",