diff --git a/pkg/rpc/response/result/mpt.go b/pkg/rpc/response/result/mpt.go new file mode 100644 index 000000000..65224e726 --- /dev/null +++ b/pkg/rpc/response/result/mpt.go @@ -0,0 +1,7 @@ +package result + +// StateHeight is a result of getstateheight RPC. +type StateHeight struct { + BlockHeight uint32 `json:"blockHeight"` + StateHeight uint32 `json:"stateHeight"` +} diff --git a/pkg/rpc/server/server.go b/pkg/rpc/server/server.go index 2cfb62451..3d3362262 100644 --- a/pkg/rpc/server/server.go +++ b/pkg/rpc/server/server.go @@ -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 { diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index 1ca90dd57..d521d1ebc 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -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",