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"
|
|
|
|
)
|
|
|
|
|
2022-01-31 11:58:55 +00:00
|
|
|
// Epoch receives number of current NeoFS epoch
|
|
|
|
// through the Netmap contract call.
|
|
|
|
func (c *Client) Epoch() (uint64, 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 {
|
2022-01-31 11:58:55 +00:00
|
|
|
return 0, 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 {
|
2022-01-31 11:58:55 +00:00
|
|
|
return 0, 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-31 11:58:55 +00:00
|
|
|
return 0, fmt.Errorf("could not get number from stack item (%s): %w", epochMethod, err)
|
2020-10-21 16:14:29 +00:00
|
|
|
}
|
2022-01-31 11:58:55 +00:00
|
|
|
return uint64(num), nil
|
2020-10-21 16:14:29 +00:00
|
|
|
}
|
2021-07-21 12:55:05 +00:00
|
|
|
|
2022-01-31 11:58:55 +00:00
|
|
|
// LastEpochBlock receives block number of current NeoFS epoch
|
|
|
|
// through the Netmap contract call.
|
|
|
|
func (c *Client) LastEpochBlock() (uint32, 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 {
|
2022-01-31 11:58:55 +00:00
|
|
|
return 0, 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 {
|
2022-01-31 11:58:55 +00:00
|
|
|
return 0, 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 {
|
2022-01-31 11:58:55 +00:00
|
|
|
return 0, 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
|
|
|
}
|
2022-01-31 11:58:55 +00:00
|
|
|
return uint32(block), nil
|
2021-07-21 12:55:05 +00:00
|
|
|
}
|