-
Notifications
You must be signed in to change notification settings - Fork 0
/
grpc_query_pubkeys_proposal.go
60 lines (49 loc) · 1.92 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
package keeper
import (
"context"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/furynet/furynetwork/consts"
"github.com/furynet/furynetwork/x/dvm/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
// PublicKeysChangeProposal returns a specific proposal by its id and status
func (k Keeper) PublicKeysChangeProposal(c context.Context, req *types.QueryPublicKeysChangeProposalRequest) (*types.QueryPublicKeysChangeProposalResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, consts.ErrTextInvalidRequest)
}
ctx := sdk.UnwrapSDKContext(c)
val, found := k.GetPubkeysChangeProposal(
ctx,
req.Status,
req.Id,
)
if !found {
return nil, status.Error(codes.NotFound, "not found")
}
return &types.QueryPublicKeysChangeProposalResponse{Proposal: val}, nil
}
// PublicKeysChangeProposals returns list of the pubkeys change proposal
func (k Keeper) PublicKeysChangeProposals(goCtx context.Context, req *types.QueryPublicKeysChangeProposalsRequest) (*types.QueryPublicKeysChangeProposalsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, consts.ErrTextInvalidRequest)
}
var proposals []types.PublicKeysChangeProposal
ctx := sdk.UnwrapSDKContext(goCtx)
marketStore := k.getPubKeysChangeProposalStore(ctx)
proposalStore := prefix.NewStore(marketStore, types.PubkeysChangeProposalPrefix(req.Status))
pageRes, err := query.Paginate(proposalStore, 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.QueryPublicKeysChangeProposalsResponse{Proposals: proposals, Pagination: pageRes}, nil
}