[#833] morph/client: Implement MsPerBlock method

Add `Client.MsPerBlock` method which reads MillisecondsPerBlock network
parameter.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-09-20 19:01:11 +03:00 committed by Alex Vanin
parent 3929f6b396
commit cb22e2bf29

View file

@ -457,3 +457,20 @@ func (c *Client) BlockCount() (res uint32, err error) {
return c.client.GetBlockCount()
}
// MsPerBlock returns MillisecondsPerBlock network parameter.
func (c *Client) MsPerBlock() (res int64, err error) {
if c.multiClient != nil {
return res, c.multiClient.iterateClients(func(c *Client) error {
res, err = c.MsPerBlock()
return err
})
}
v, err := c.client.GetVersion()
if err != nil {
return 0, fmt.Errorf("getVersion: %w", err)
}
return int64(v.Protocol.MillisecondsPerBlock), nil
}