cosmos-sdk/client/grpc/tmservice/block.go
2022-08-20 02:33:07 +02:00

34 lines
855 B
Go

package tmservice
import (
"context"
"github.com/cosmos/cosmos-sdk/client"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
coretypes "github.com/tendermint/tendermint/rpc/core/types"
)
func getBlock(ctx context.Context, clientCtx client.Context, height *int64) (*coretypes.ResultBlock, error) {
// get the node
node, err := clientCtx.GetNode()
if err != nil {
return nil, err
}
return node.Block(ctx, height)
}
func GetProtoBlock(ctx context.Context, clientCtx client.Context, height *int64) (tmproto.BlockID, *tmproto.Block, error) {
block, err := getBlock(ctx, clientCtx, height)
if err != nil {
return tmproto.BlockID{}, nil, err
}
protoBlock, err := block.Block.ToProto()
if err != nil {
return tmproto.BlockID{}, nil, err
}
protoBlockID := block.BlockID.ToProto()
return protoBlockID, protoBlock, nil
}