forked from TrueCloudLab/frostfs-node
[#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 <alexey@nspcc.ru>
This commit is contained in:
parent
f42c5e64fc
commit
2f6adb0465
2 changed files with 28 additions and 0 deletions
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue