forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
block.go
43 lines (35 loc) · 1.07 KB
/
block.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package cmtservice
import (
"context"
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
coretypes "github.com/cometbft/cometbft/rpc/core/types"
"github.com/T-ragon/cosmos-sdk/v3/client"
)
func getBlockHeight(ctx context.Context, clientCtx client.Context) (int64, error) {
status, err := GetNodeStatus(ctx, clientCtx)
if err != nil {
return 0, err
}
height := status.SyncInfo.LatestBlockHeight
return height, nil
}
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) (cmtproto.BlockID, *cmtproto.Block, error) {
block, err := getBlock(ctx, clientCtx, height)
if err != nil {
return cmtproto.BlockID{}, nil, err
}
protoBlock, err := block.Block.ToProto()
if err != nil {
return cmtproto.BlockID{}, nil, err
}
protoBlockID := block.BlockID.ToProto()
return protoBlockID, protoBlock, nil
}