-
Notifications
You must be signed in to change notification settings - Fork 29
/
block.go
55 lines (44 loc) · 1.37 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
44
45
46
47
48
49
50
51
52
53
54
55
package tmservice
import (
"context"
ocproto "github.com/Finschia/ostracon/proto/ostracon/types"
ctypes "github.com/Finschia/ostracon/rpc/core/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/Finschia/finschia-sdk/client"
)
func getBlock(ctx context.Context, clientCtx client.Context, height *int64) (*ctypes.ResultBlock, error) {
// get the node
node, err := clientCtx.GetNode()
if err != nil {
return nil, err
}
return node.Block(ctx, height)
}
func getBlockByHash(clientCtx client.Context, hash []byte) (*ctypes.ResultBlock, error) {
// get the node
node, err := clientCtx.GetNode()
if err != nil {
return nil, err
}
return node.BlockByHash(context.Background(), hash)
}
func getBlockResultsByHeight(clientCtx client.Context, height *int64) (*ctypes.ResultBlockResults, error) {
// get the node
node, err := clientCtx.GetNode()
if err != nil {
return nil, err
}
return node.BlockResults(context.Background(), height)
}
func GetProtoBlock(ctx context.Context, clientCtx client.Context, height *int64) (tmproto.BlockID, *ocproto.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
}