2024-07-04 05:23:26 +00:00
|
|
|
package keeper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2024-07-29 10:28:30 +00:00
|
|
|
errorsmod "cosmossdk.io/errors"
|
2024-07-04 05:23:26 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2024-07-29 10:28:30 +00:00
|
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
2024-07-04 05:23:26 +00:00
|
|
|
|
|
|
|
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.
|
2024-07-11 05:16:31 +00:00
|
|
|
func (qs queryServer) Participants(
|
|
|
|
c context.Context,
|
|
|
|
_ *onboardingtypes.QueryParticipantsRequest,
|
|
|
|
) (*onboardingtypes.QueryParticipantsResponse, error) {
|
2024-07-04 05:23:26 +00:00
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
|
|
|
|
resp, err := qs.k.ListParticipants(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &onboardingtypes.QueryParticipantsResponse{Participants: resp}, nil
|
|
|
|
}
|
2024-07-29 10:28:30 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|