2020-10-21 16:14:29 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2020-10-21 16:14:29 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
|
|
|
)
|
|
|
|
|
|
|
|
// EpochArgs groups the arguments
|
|
|
|
// of get epoch number test invoke call.
|
2021-11-10 10:44:19 +00:00
|
|
|
type EpochArgs struct{}
|
2020-10-21 16:14:29 +00:00
|
|
|
|
|
|
|
// EpochValues groups the stack parameters
|
|
|
|
// returned by get epoch number test invoke.
|
|
|
|
type EpochValues struct {
|
|
|
|
num int64
|
|
|
|
}
|
|
|
|
|
|
|
|
// Number return the number of NeoFS epoch.
|
|
|
|
func (e EpochValues) Number() int64 {
|
|
|
|
return e.num
|
|
|
|
}
|
|
|
|
|
|
|
|
// Epoch performs the test invoke of get epoch number
|
|
|
|
// method of NeoFS Netmap contract.
|
|
|
|
func (c *Client) Epoch(_ EpochArgs) (*EpochValues, error) {
|
2021-11-09 20:52:29 +00:00
|
|
|
prm := client.TestInvokePrm{}
|
2022-01-29 13:06:36 +00:00
|
|
|
prm.SetMethod(epochMethod)
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
items, err := c.client.TestInvoke(prm)
|
2020-10-21 16:14:29 +00:00
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not perform test invocation (%s): %w",
|
2022-01-29 13:06:36 +00:00
|
|
|
epochMethod, err)
|
2020-10-21 16:14:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ln := len(items); ln != 1 {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("unexpected stack item count (%s): %d",
|
2022-01-29 13:06:36 +00:00
|
|
|
epochMethod, ln)
|
2020-10-21 16:14:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
num, err := client.IntFromStackItem(items[0])
|
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return nil, fmt.Errorf("could not get number from stack item (%s): %w", epochMethod, err)
|
2020-10-21 16:14:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &EpochValues{
|
|
|
|
num: num,
|
|
|
|
}, nil
|
|
|
|
}
|
2021-07-21 12:55:05 +00:00
|
|
|
|
2021-11-10 10:44:19 +00:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2021-07-21 12:55:05 +00:00
|
|
|
// LastEpochBlock performs the test invoke of get epoch block number
|
|
|
|
// method of NeoFS Netmap contract.
|
|
|
|
func (c *Client) LastEpochBlock(_ EpochBlockArgs) (*EpochBlockValues, error) {
|
2021-11-09 20:52:29 +00:00
|
|
|
prm := client.TestInvokePrm{}
|
2022-01-29 13:06:36 +00:00
|
|
|
prm.SetMethod(lastEpochBlockMethod)
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
items, err := c.client.TestInvoke(prm)
|
2021-07-21 12:55:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("could not perform test invocation (%s): %w",
|
2022-01-29 13:06:36 +00:00
|
|
|
lastEpochBlockMethod, err)
|
2021-07-21 12:55:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ln := len(items); ln != 1 {
|
|
|
|
return nil, fmt.Errorf("unexpected stack item count (%s): %d",
|
2022-01-29 13:06:36 +00:00
|
|
|
lastEpochBlockMethod, ln)
|
2021-07-21 12:55:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
block, err := client.IntFromStackItem(items[0])
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("could not get number from stack item (%s): %w",
|
2022-01-29 13:06:36 +00:00
|
|
|
lastEpochBlockMethod, err)
|
2021-07-21 12:55:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &EpochBlockValues{
|
|
|
|
block: block,
|
|
|
|
}, nil
|
|
|
|
}
|