forked from cerc-io/laconicd
Prathamesh Musale
7a88c82816
Part of [laconicd testnet validator enrollment](https://www.notion.so/laconicd-testnet-validator-enrollment-6fc1d3cafcc64fef8c5ed3affa27c675) Co-authored-by: IshaVenikar <ishavenikar7@gmail.com> Reviewed-on: cerc-io/laconicd#44 Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com> Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
76 lines
2.1 KiB
Go
76 lines
2.1 KiB
Go
package keeper
|
|
|
|
import (
|
|
"context"
|
|
|
|
errorsmod "cosmossdk.io/errors"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
|
|
onboardingtypes "git.vdb.to/cerc-io/laconicd/x/onboarding"
|
|
)
|
|
|
|
var _ onboardingtypes.QueryServer = queryServer{}
|
|
|
|
type queryServer struct {
|
|
k *Keeper
|
|
}
|
|
|
|
// NewQueryServerImpl returns an implementation of the module QueryServer.
|
|
func NewQueryServerImpl(k *Keeper) onboardingtypes.QueryServer {
|
|
return queryServer{k}
|
|
}
|
|
|
|
// Participants implements Participants.QueryServer.
|
|
func (qs queryServer) Participants(
|
|
c context.Context,
|
|
_ *onboardingtypes.QueryParticipantsRequest,
|
|
) (*onboardingtypes.QueryParticipantsResponse, error) {
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
resp, err := qs.k.ListParticipants(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &onboardingtypes.QueryParticipantsResponse{Participants: resp}, nil
|
|
}
|
|
|
|
// GetParticipantByAddress implements the GetParticipantByAddress query.
|
|
func (qs queryServer) GetParticipantByAddress(
|
|
c context.Context,
|
|
req *onboardingtypes.QueryGetParticipantByAddressRequest,
|
|
) (*onboardingtypes.QueryGetParticipantByAddressResponse, error) {
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
if req.Address == "" {
|
|
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "cosmos (laconic) address is required")
|
|
}
|
|
|
|
participant, err := qs.k.GetParticipantByAddress(ctx, req.Address)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &onboardingtypes.QueryGetParticipantByAddressResponse{Participant: &participant}, nil
|
|
}
|
|
|
|
// GetParticipantByNitroAddress implements the GetParticipantByNitroAddress query.
|
|
func (qs queryServer) GetParticipantByNitroAddress(
|
|
c context.Context,
|
|
req *onboardingtypes.QueryGetParticipantByNitroAddressRequest,
|
|
) (*onboardingtypes.QueryGetParticipantByNitroAddressResponse, error) {
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
if req.NitroAddress == "" {
|
|
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "nitro address is required")
|
|
}
|
|
|
|
participant, err := qs.k.GetParticipantByNitroAddress(ctx, req.NitroAddress)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &onboardingtypes.QueryGetParticipantByNitroAddressResponse{Participant: &participant}, nil
|
|
}
|