mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-23 13:38:35 +00:00
rpc/server: implement getstateheight RPC
This commit is contained in:
parent
4de22247d5
commit
6b42e9306a
3 changed files with 34 additions and 0 deletions
7
pkg/rpc/response/result/mpt.go
Normal file
7
pkg/rpc/response/result/mpt.go
Normal 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"`
|
||||
}
|
|
@ -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 {
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue