github.com/Finschia/finschia-sdk@v0.48.1/client/grpc/tmservice/block.go (about)

     1  package tmservice
     2  
     3  import (
     4  	"context"
     5  
     6  	ocproto "github.com/Finschia/ostracon/proto/ostracon/types"
     7  	ctypes "github.com/Finschia/ostracon/rpc/core/types"
     8  	tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
     9  
    10  	"github.com/Finschia/finschia-sdk/client"
    11  )
    12  
    13  func GetBlock(ctx context.Context, clientCtx client.Context, height *int64) (*ctypes.ResultBlock, error) {
    14  	// get the node
    15  	node, err := clientCtx.GetNode()
    16  	if err != nil {
    17  		return nil, err
    18  	}
    19  
    20  	return node.Block(ctx, height)
    21  }
    22  
    23  func GetBlockByHash(clientCtx client.Context, hash []byte) (*ctypes.ResultBlock, error) {
    24  	// get the node
    25  	node, err := clientCtx.GetNode()
    26  	if err != nil {
    27  		return nil, err
    28  	}
    29  
    30  	return node.BlockByHash(context.Background(), hash)
    31  }
    32  
    33  func GetBlockResultsByHeight(clientCtx client.Context, height *int64) (*ctypes.ResultBlockResults, error) {
    34  	// get the node
    35  	node, err := clientCtx.GetNode()
    36  	if err != nil {
    37  		return nil, err
    38  	}
    39  
    40  	return node.BlockResults(context.Background(), height)
    41  }
    42  
    43  func GetProtoBlock(ctx context.Context, clientCtx client.Context, height *int64) (tmproto.BlockID, *ocproto.Block, error) {
    44  	block, err := GetBlock(ctx, clientCtx, height)
    45  	if err != nil {
    46  		return tmproto.BlockID{}, nil, err
    47  	}
    48  	protoBlock, err := block.Block.ToProto()
    49  	if err != nil {
    50  		return tmproto.BlockID{}, nil, err
    51  	}
    52  	protoBlockID := block.BlockID.ToProto()
    53  
    54  	return protoBlockID, protoBlock, nil
    55  }