/
grpc_query_pubkeys_proposal.go
102 lines (82 loc) · 3.47 KB
/
grpc_query_pubkeys_proposal.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package keeper
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/merlin-network/fury/consts"
"github.com/merlin-network/fury/x/dvm/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
// ActivePublicKeysChangeProposal returns a specific active proposal by its UID
func (k Keeper) ActivePublicKeysChangeProposal(c context.Context, req *types.QueryActivePublicKeysChangeProposalRequest) (*types.QueryActivePublicKeysChangeProposalResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, consts.ErrTextInvalidRequest)
}
ctx := sdk.UnwrapSDKContext(c)
val, found := k.GetActivePubkeysChangeProposal(
ctx,
req.Id,
)
if !found {
return nil, status.Error(codes.NotFound, "not found")
}
return &types.QueryActivePublicKeysChangeProposalResponse{Proposal: val}, nil
}
// ActivePublicKeysChangeProposal returns list of the active pubkeys change proposal
func (k Keeper) ActivePublicKeysChangeProposals(goCtx context.Context, req *types.QueryActivePublicKeysChangeProposalsRequest) (*types.QueryActivePublicKeysChangeProposalsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, consts.ErrTextInvalidRequest)
}
var proposals []types.PublicKeysChangeProposal
ctx := sdk.UnwrapSDKContext(goCtx)
sportEventStore := k.getActivePubKeysChangeProposalStore(ctx)
pageRes, err := query.Paginate(sportEventStore, req.Pagination, func(key []byte, value []byte) error {
var proposal types.PublicKeysChangeProposal
if err := k.cdc.Unmarshal(value, &proposal); err != nil {
return err
}
proposals = append(proposals, proposal)
return nil
})
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
return &types.QueryActivePublicKeysChangeProposalsResponse{Proposals: proposals, Pagination: pageRes}, nil
}
// PublicKeysChangeProposal returns a specific finished proposal by its UID
func (k Keeper) FinishedPublicKeysChangeProposal(c context.Context, req *types.QueryFinishedPublicKeysChangeProposalRequest) (*types.QueryFinishedPublicKeysChangeProposalResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, consts.ErrTextInvalidRequest)
}
ctx := sdk.UnwrapSDKContext(c)
val, found := k.GetFinishedPubkeysChangeProposal(
ctx,
req.Id,
)
if !found {
return nil, status.Error(codes.NotFound, "not found")
}
return &types.QueryFinishedPublicKeysChangeProposalResponse{Proposal: val}, nil
}
// FinishedPublicKeysChangeProposal returns list of the finished pubkeys change proposal
func (k Keeper) FinishedPublicKeysChangeProposals(goCtx context.Context, req *types.QueryFinishedPublicKeysChangeProposalsRequest) (*types.QueryFinishedPublicKeysChangeProposalsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, consts.ErrTextInvalidRequest)
}
var proposals []types.PublicKeysChangeFinishedProposal
ctx := sdk.UnwrapSDKContext(goCtx)
sportEventStore := k.getActivePubKeysChangeProposalStore(ctx)
pageRes, err := query.Paginate(sportEventStore, req.Pagination, func(key []byte, value []byte) error {
var proposal types.PublicKeysChangeFinishedProposal
if err := k.cdc.Unmarshal(value, &proposal); err != nil {
return err
}
proposals = append(proposals, proposal)
return nil
})
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
return &types.QueryFinishedPublicKeysChangeProposalsResponse{Proposals: proposals, Pagination: pageRes}, nil
}