rpc/client: support getstateheight RPC

This commit is contained in:
Evgenii Stratonikov 2020-06-25 15:35:32 +03:00
parent b4b0ae0f51
commit d8dddabc86
2 changed files with 26 additions and 0 deletions

View file

@ -620,6 +620,21 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
},
},
},
"getstateheight": {
{
name: "positive",
invoke: func(c *Client) (interface{}, error) {
return c.GetStateHeight()
},
serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"blockHeight":208,"stateHeight":200}}`,
result: func(c *Client) interface{} {
return &result.StateHeight{
BlockHeight: 208,
StateHeight: 200,
}
},
},
},
"getstateroot": {
{
name: "positive",

View file

@ -3,6 +3,7 @@ package client
import (
"github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
"github.com/nspcc-dev/neo-go/pkg/util"
)
@ -24,3 +25,13 @@ func (c *Client) getStateRoot(p request.RawParams) (*state.MPTRootState, error)
}
return &resp, nil
}
// GetStateHeight returns current block and state height.
func (c *Client) GetStateHeight() (*result.StateHeight, error) {
resp := new(result.StateHeight)
err := c.performRequest("getstateheight", request.NewRawParams(), resp)
if err != nil {
return nil, err
}
return resp, nil
}