2023-12-13 17:17:37 +00:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
|
|
|
|
"google.golang.org/grpc/metadata"
|
|
|
|
|
2024-04-24 07:10:22 +00:00
|
|
|
"github.com/0glabs/0g-chain/app"
|
|
|
|
"github.com/0glabs/0g-chain/app/params"
|
|
|
|
query "github.com/0glabs/0g-chain/client/grpc/query"
|
2023-12-13 17:17:37 +00:00
|
|
|
)
|
|
|
|
|
2024-04-24 11:41:25 +00:00
|
|
|
// Util contains utility functions for the 0gChain gRPC client
|
2023-12-13 17:17:37 +00:00
|
|
|
type Util struct {
|
|
|
|
query *query.QueryClient
|
|
|
|
encodingConfig params.EncodingConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewUtil creates a new Util instance
|
|
|
|
func NewUtil(query *query.QueryClient) *Util {
|
|
|
|
return &Util{
|
|
|
|
query: query,
|
|
|
|
encodingConfig: app.MakeEncodingConfig(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u *Util) CtxAtHeight(height int64) context.Context {
|
|
|
|
heightStr := strconv.FormatInt(height, 10)
|
|
|
|
return metadata.AppendToOutgoingContext(context.Background(), grpctypes.GRPCBlockHeightHeader, heightStr)
|
|
|
|
}
|