frostfs-node/pkg/morph/client/netmap/epoch.go
Evgenii Stratonikov e3487d5af5
All checks were successful
Tests and linters / Run gofumpt (push) Successful in 2m10s
Tests and linters / Staticcheck (push) Successful in 2m52s
Vulncheck / Vulncheck (push) Successful in 2m50s
Build / Build Components (push) Successful in 3m23s
Pre-commit hooks / Pre-commit (push) Successful in 3m33s
Tests and linters / gopls check (push) Successful in 4m8s
Tests and linters / Lint (push) Successful in 4m16s
Tests and linters / Tests (push) Successful in 4m19s
Tests and linters / Tests with -race (push) Successful in 5m1s
[#1535] morph: Unify test invoke error messages
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2024-12-04 09:50:20 +00:00

56 lines
1.4 KiB
Go

package netmap
import (
"fmt"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
)
// Epoch receives number of current FrostFS epoch
// through the Netmap contract call.
func (c *Client) Epoch() (uint64, error) {
prm := client.TestInvokePrm{}
prm.SetMethod(epochMethod)
items, err := c.client.TestInvoke(prm)
if err != nil {
return 0, fmt.Errorf("test invoke (%s): %w",
epochMethod, err)
}
if ln := len(items); ln != 1 {
return 0, fmt.Errorf("unexpected stack item count (%s): %d",
epochMethod, ln)
}
num, err := client.IntFromStackItem(items[0])
if err != nil {
return 0, fmt.Errorf("could not get number from stack item (%s): %w", epochMethod, err)
}
return uint64(num), nil
}
// LastEpochBlock receives block number of current FrostFS epoch
// through the Netmap contract call.
func (c *Client) LastEpochBlock() (uint32, error) {
prm := client.TestInvokePrm{}
prm.SetMethod(lastEpochBlockMethod)
items, err := c.client.TestInvoke(prm)
if err != nil {
return 0, fmt.Errorf("test invoke (%s): %w",
lastEpochBlockMethod, err)
}
if ln := len(items); ln != 1 {
return 0, fmt.Errorf("unexpected stack item count (%s): %d",
lastEpochBlockMethod, ln)
}
block, err := client.IntFromStackItem(items[0])
if err != nil {
return 0, fmt.Errorf("could not get number from stack item (%s): %w",
lastEpochBlockMethod, err)
}
return uint32(block), nil
}