github.com/cosmos/cosmos-sdk@v0.50.10/client/grpc/cmtservice/block.go (about) 1 package cmtservice 2 3 import ( 4 "context" 5 6 cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" 7 coretypes "github.com/cometbft/cometbft/rpc/core/types" 8 9 "github.com/cosmos/cosmos-sdk/client" 10 ) 11 12 func getBlockHeight(ctx context.Context, clientCtx client.Context) (int64, error) { 13 status, err := GetNodeStatus(ctx, clientCtx) 14 if err != nil { 15 return 0, err 16 } 17 height := status.SyncInfo.LatestBlockHeight 18 return height, nil 19 } 20 21 func getBlock(ctx context.Context, clientCtx client.Context, height *int64) (*coretypes.ResultBlock, error) { 22 // get the node 23 node, err := clientCtx.GetNode() 24 if err != nil { 25 return nil, err 26 } 27 28 return node.Block(ctx, height) 29 } 30 31 func GetProtoBlock(ctx context.Context, clientCtx client.Context, height *int64) (cmtproto.BlockID, *cmtproto.Block, error) { 32 block, err := getBlock(ctx, clientCtx, height) 33 if err != nil { 34 return cmtproto.BlockID{}, nil, err 35 } 36 protoBlock, err := block.Block.ToProto() 37 if err != nil { 38 return cmtproto.BlockID{}, nil, err 39 } 40 protoBlockID := block.BlockID.ToProto() 41 42 return protoBlockID, protoBlock, nil 43 }