mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-05 03:58:23 +00:00
rpc/server: implement getstateheight RPC
This commit is contained in:
parent
53dc7f27b6
commit
fe8038e8b7
3 changed files with 31 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"`
|
||||||
|
}
|
|
@ -95,6 +95,7 @@ var rpcHandlers = map[string]func(*Server, request.Params) (interface{}, *respon
|
||||||
"getpeers": (*Server).getPeers,
|
"getpeers": (*Server).getPeers,
|
||||||
"getrawmempool": (*Server).getRawMempool,
|
"getrawmempool": (*Server).getRawMempool,
|
||||||
"getrawtransaction": (*Server).getrawtransaction,
|
"getrawtransaction": (*Server).getrawtransaction,
|
||||||
|
"getstateheight": (*Server).getStateHeight,
|
||||||
"getstateroot": (*Server).getStateRoot,
|
"getstateroot": (*Server).getStateRoot,
|
||||||
"getstorage": (*Server).getStorage,
|
"getstorage": (*Server).getStorage,
|
||||||
"gettransactionheight": (*Server).getTransactionHeight,
|
"gettransactionheight": (*Server).getTransactionHeight,
|
||||||
|
@ -688,6 +689,14 @@ func (s *Server) getDecimals(h util.Uint160, cache map[util.Uint160]int64) (int6
|
||||||
return d, nil
|
return d, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) getStateHeight(_ request.Params) (interface{}, *response.Error) {
|
||||||
|
height := s.chain.BlockHeight()
|
||||||
|
return &result.StateHeight{
|
||||||
|
BlockHeight: height,
|
||||||
|
StateHeight: height,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) getStateRoot(ps request.Params) (interface{}, *response.Error) {
|
func (s *Server) getStateRoot(ps request.Params) (interface{}, *response.Error) {
|
||||||
p := ps.Value(0)
|
p := ps.Value(0)
|
||||||
if p == nil {
|
if p == nil {
|
||||||
|
|
|
@ -214,6 +214,21 @@ var rpcTestCases = map[string][]rpcTestCase{
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"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)
|
||||||
|
|
||||||
|
h := e.chain.BlockHeight()
|
||||||
|
require.Equal(t, h, sh.BlockHeight)
|
||||||
|
require.Equal(t, h, sh.StateHeight)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
"getstateroot": {
|
"getstateroot": {
|
||||||
{
|
{
|
||||||
name: "no params",
|
name: "no params",
|
||||||
|
|
Loading…
Reference in a new issue