From cb22e2bf29187ee04e06fa13d9e711496870ab1d Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 20 Sep 2021 19:01:11 +0300 Subject: [PATCH] [#833] morph/client: Implement MsPerBlock method Add `Client.MsPerBlock` method which reads MillisecondsPerBlock network parameter. Signed-off-by: Leonard Lyubich --- pkg/morph/client/client.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkg/morph/client/client.go b/pkg/morph/client/client.go index d9978b54..41742d7a 100644 --- a/pkg/morph/client/client.go +++ b/pkg/morph/client/client.go @@ -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 +}