Marina Biryukova
d219943542
All checks were successful
/ Vulncheck (pull_request) Successful in 1m32s
/ Lint (pull_request) Successful in 2m28s
/ Tests (1.20) (pull_request) Successful in 1m52s
/ Tests (1.21) (pull_request) Successful in 1m21s
/ DCO (pull_request) Successful in 3m25s
/ Builds (1.20) (pull_request) Successful in 5m38s
/ Builds (1.21) (pull_request) Successful in 1m23s
Signed-off-by: Marina Biryukova <m.biryukova@yadro.com>
43 lines
1,022 B
Go
43 lines
1,022 B
Go
package utils
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/pool"
|
|
"github.com/valyala/fasthttp"
|
|
)
|
|
|
|
type EpochDurations struct {
|
|
CurrentEpoch uint64
|
|
MsPerBlock int64
|
|
BlockPerEpoch uint64
|
|
}
|
|
|
|
func GetEpochDurations(ctx context.Context, p *pool.Pool) (*EpochDurations, error) {
|
|
networkInfo, err := p.NetworkInfo(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
res := &EpochDurations{
|
|
CurrentEpoch: networkInfo.CurrentEpoch(),
|
|
MsPerBlock: networkInfo.MsPerBlock(),
|
|
BlockPerEpoch: networkInfo.EpochDuration(),
|
|
}
|
|
|
|
if res.BlockPerEpoch == 0 {
|
|
return nil, fmt.Errorf("EpochDuration is empty")
|
|
}
|
|
return res, nil
|
|
}
|
|
|
|
// SetContextToRequest adds new context to fasthttp request.
|
|
func SetContextToRequest(ctx context.Context, c *fasthttp.RequestCtx) {
|
|
c.SetUserValue("context", ctx)
|
|
}
|
|
|
|
// GetContextFromRequest returns main context from fasthttp request context.
|
|
func GetContextFromRequest(c *fasthttp.RequestCtx) context.Context {
|
|
return c.UserValue("context").(context.Context)
|
|
}
|