[#708] morph/client: Add epoch block getter from netmap

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-07-21 15:55:05 +03:00 committed by Alex Vanin
parent 7e43af3de3
commit 7146afcd28
3 changed files with 57 additions and 0 deletions

View file

@ -22,6 +22,22 @@ func (e EpochValues) Number() int64 {
return e.num
}
// EpochBlockArgs groups the arguments of
// get epoch block number test invoke call.
type EpochBlockArgs struct {
}
// EpochBlockValues groups the stack parameters
// returned by get epoch block number test invoke.
type EpochBlockValues struct {
block int64
}
// Block return the block number of NeoFS epoch.
func (e EpochBlockValues) Block() int64 {
return e.block
}
// Epoch performs the test invoke of get epoch number
// method of NeoFS Netmap contract.
func (c *Client) Epoch(_ EpochArgs) (*EpochValues, error) {
@ -47,3 +63,28 @@ func (c *Client) Epoch(_ EpochArgs) (*EpochValues, error) {
num: num,
}, nil
}
// LastEpochBlock performs the test invoke of get epoch block number
// method of NeoFS Netmap contract.
func (c *Client) LastEpochBlock(_ EpochBlockArgs) (*EpochBlockValues, error) {
items, err := c.client.TestInvoke(c.epochBlockMethod)
if err != nil {
return nil, fmt.Errorf("could not perform test invocation (%s): %w",
c.epochBlockMethod, err)
}
if ln := len(items); ln != 1 {
return nil, fmt.Errorf("unexpected stack item count (%s): %d",
c.epochBlockMethod, ln)
}
block, err := client.IntFromStackItem(items[0])
if err != nil {
return nil, fmt.Errorf("could not get number from stack item (%s): %w",
c.epochBlockMethod, err)
}
return &EpochBlockValues{
block: block,
}, nil
}