From 2f6adb04653592f1ff9ec7222d374cbcd24f252c Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 23 Mar 2021 13:02:24 +0300 Subject: [PATCH] [#421] morph/client: Add role getter from designate contract RoleManagement native contract (ex designate contract) stores list of keys per role. Main net uses NeoFSAlphabet role to store keys of alphabet nodes of inner ring. Side chain uses the same role to store keys of all inner ring nodes, including alphabet. Signed-off-by: Alex Vanin --- pkg/morph/client/client.go | 22 ++++++++++++++++++++++ pkg/morph/client/constructor.go | 6 ++++++ 2 files changed, 28 insertions(+) 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 }