diff --git a/pkg/morph/client/client.go b/pkg/morph/client/client.go index 9cf6139ca..29a374fdd 100644 --- a/pkg/morph/client/client.go +++ b/pkg/morph/client/client.go @@ -37,6 +37,8 @@ type Client struct { neo util.Uint160 // native neo script-hash + designate util.Uint160 // native designate script-hash + waitInterval time.Duration notary *notary @@ -51,6 +53,7 @@ const HaltState = "HALT" const ( committeeList = "getCommittee" + designateList = "getDesignatedByRole" ) var errEmptyInvocationScript = errors.New("got empty invocation script from neo node") @@ -214,6 +217,25 @@ func (c *Client) Committee() (keys.PublicKeys, error) { return roleKeys, nil } +func (c *Client) roleList(r native.Role) (keys.PublicKeys, error) { + height, err := c.client.GetBlockCount() + if err != nil { + return nil, errors.Wrap(err, "can't get chain height") + } + + items, err := c.TestInvoke(c.designate, designateList, r, int64(height)) + if err != nil { + return nil, err + } + + roleKeys, err := keysFromStack(items) + if err != nil { + return nil, errors.Wrap(err, "can't get role keys") + } + + return roleKeys, nil +} + func toStackParameter(value interface{}) (sc.Parameter, error) { var result = sc.Parameter{ Value: value, diff --git a/pkg/morph/client/constructor.go b/pkg/morph/client/constructor.go index e3a8bd77f..573d81a96 100644 --- a/pkg/morph/client/constructor.go +++ b/pkg/morph/client/constructor.go @@ -105,12 +105,18 @@ func New(key *ecdsa.PrivateKey, endpoint string, opts ...Option) (*Client, error return nil, err } + designate, err := cli.GetNativeContractHash(nativenames.Designation) + if err != nil { + return nil, err + } + return &Client{ logger: cfg.logger, client: cli, acc: account, gas: gas, neo: neo, + designate: designate, waitInterval: cfg.waitInterval, }, nil }