2020-10-21 16:14:29 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
2020-10-21 16:14:29 +00:00
|
|
|
)
|
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// Epoch receives number of current FrostFS epoch
|
2022-01-31 11:58:55 +00:00
|
|
|
// 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 {
|
2024-12-04 08:17:13 +00:00
|
|
|
return 0, fmt.Errorf("test invoke (%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
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// LastEpochBlock receives block number of current FrostFS epoch
|
2022-01-31 11:58:55 +00:00
|
|
|
// 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 {
|
2024-12-04 08:17:13 +00:00
|
|
|
return 0, fmt.Errorf("test invoke (%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
|
|
|
}
|