2020-06-25 12:29:43 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
|
2020-06-25 12:35:32 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
|
2020-06-25 12:29:43 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetStateRootByHeight returns state root for the given height.
|
|
|
|
func (c *Client) GetStateRootByHeight(h uint32) (*state.MPTRootState, error) {
|
|
|
|
return c.getStateRoot(request.NewRawParams(h))
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetStateRootByHash returns state root for the given block hash.
|
|
|
|
func (c *Client) GetStateRootByHash(h util.Uint256) (*state.MPTRootState, error) {
|
|
|
|
return c.getStateRoot(request.NewRawParams(h))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) getStateRoot(p request.RawParams) (*state.MPTRootState, error) {
|
|
|
|
var resp state.MPTRootState
|
|
|
|
err := c.performRequest("getstateroot", p, &resp)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &resp, nil
|
|
|
|
}
|
2020-06-25 12:35:32 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|