-
Notifications
You must be signed in to change notification settings - Fork 42
/
query.go
63 lines (47 loc) · 1.89 KB
/
query.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
56
57
58
59
60
61
62
63
package keeper
import (
"context"
"github.com/omni-network/omni/halo/attest/types"
"github.com/omni-network/omni/lib/xchain"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
var _ types.QueryServer = (*Keeper)(nil)
const approvedFromLimit = 100
func (k *Keeper) AttestationsFrom(ctx context.Context, req *types.AttestationsFromRequest) (*types.AttestationsFromResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
atts, err := k.ListAttestationsFrom(ctx, req.ChainId, req.ConfLevel, req.FromOffset, approvedFromLimit)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
return &types.AttestationsFromResponse{Attestations: atts}, nil
}
func (k *Keeper) LatestAttestation(ctx context.Context, req *types.LatestAttestationRequest) (*types.LatestAttestationResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
chainVer := xchain.ChainVersion{ID: req.ChainId, ConfLevel: xchain.ConfLevel(req.ConfLevel)}
att, ok, err := k.latestAttestation(ctx, chainVer)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
} else if !ok {
return nil, status.Error(codes.NotFound, "no approved attestations for chain")
}
sigs, err := k.getSigs(ctx, att.GetId())
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
return &types.LatestAttestationResponse{Attestation: AttestationFromDB(att, sigs)}, nil
}
func (k *Keeper) WindowCompare(ctx context.Context, req *types.WindowCompareRequest) (*types.WindowCompareResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
cmp, err := k.windowCompare(ctx, req.XChainVersion(), req.GetBlockOffset())
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
return &types.WindowCompareResponse{Cmp: int32(cmp)}, nil
}