-
Notifications
You must be signed in to change notification settings - Fork 206
/
chain_tracker_service.go
35 lines (30 loc) · 1.12 KB
/
chain_tracker_service.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
package chaintracker
import (
"context"
empty "github.com/golang/protobuf/ptypes/empty"
wrappers "github.com/golang/protobuf/ptypes/wrappers"
)
type ChainTrackerService struct {
UnimplementedChainTrackerServiceServer
ChainTracker *ChainTracker
}
func (cts *ChainTrackerService) GetLatestBlockNum(context.Context, *empty.Empty) (*wrappers.UInt64Value, error) {
latestBlockNum := cts.ChainTracker.GetLatestBlockNum()
if latestBlockNum <= 0 {
return nil, InvalidLatestBlockNumValue
}
return &wrappers.UInt64Value{Value: uint64(latestBlockNum)}, nil
}
func (cts *ChainTrackerService) GetLatestBlockData(ctx context.Context, latestBlockData *LatestBlockData) (*LatestBlockDataResponse, error) {
latestBlockNum, requestedHashes, err := cts.ChainTracker.GetLatestBlockData(latestBlockData.FromBlock, latestBlockData.ToBlock, latestBlockData.SpecificBlock)
if err != nil {
return nil, err
}
if latestBlockNum <= 0 {
return nil, InvalidLatestBlockNumValue
}
if len(requestedHashes) == 0 {
return nil, InvalidReturnedHashes
}
return &LatestBlockDataResponse{LatestBlock: latestBlockNum, RequestedHashes: requestedHashes}, nil
}