laconicd/x/onboarding/keeper/query_server.go
Prathamesh Musale 620c5224f7
All checks were successful
Build / build (pull_request) Successful in 1m53s
Protobuf / lint (pull_request) Successful in 10s
E2E Tests / test-e2e (pull_request) Successful in 2m46s
Integration Tests / test-integration (pull_request) Successful in 1m47s
SDK Tests / sdk_tests_nameservice_expiry (pull_request) Successful in 6m45s
Unit Tests / test-unit (pull_request) Successful in 2m18s
SDK Tests / sdk_tests_auctions (pull_request) Successful in 12m20s
SDK Tests / sdk_tests (pull_request) Successful in 9m1s
Implement query to get participant by Nitro address
2024-07-29 15:05:04 +05:30

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, "cosmos (laconic) address is required")
}
participant, err := qs.k.GetParticipantByNitroAddress(ctx, req.NitroAddress)
if err != nil {
return nil, err
}
return &onboardingtypes.QueryGetParticipantByNitroAddressResponse{Participant: &participant}, nil
}