onboarding keeper: return nil for party not found
This commit is contained in:
parent
eb94500f70
commit
8f8e462397
@ -142,32 +142,38 @@ func (k Keeper) ListParticipants(ctx context.Context) ([]*onboarding.Participant
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetParticipantByAddress - get participant by cosmos (laconic) address.
|
// GetParticipantByAddress - get participant by cosmos (laconic) address.
|
||||||
func (k Keeper) GetParticipantByAddress(ctx context.Context, address string) (onboarding.Participant, error) {
|
// Returns nil if participant is not found.
|
||||||
|
func (k Keeper) GetParticipantByAddress(ctx context.Context, address string) (*onboarding.Participant, error) {
|
||||||
participant, err := k.Participants.Get(ctx, address)
|
participant, err := k.Participants.Get(ctx, address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, collections.ErrNotFound) {
|
if errors.Is(err, collections.ErrNotFound) {
|
||||||
return onboarding.Participant{}, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "participant with given address not found.")
|
return nil, nil
|
||||||
}
|
}
|
||||||
return onboarding.Participant{}, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return participant, nil
|
return &participant, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetParticipantByNitroAddress - get participant by nitro address.
|
// GetParticipantByNitroAddress - get participant by nitro address.
|
||||||
func (k Keeper) GetParticipantByNitroAddress(ctx context.Context, nitroAddress string) (onboarding.Participant, error) {
|
// Returns nil if participant is not found.
|
||||||
var participant onboarding.Participant
|
func (k Keeper) GetParticipantByNitroAddress(ctx context.Context, nitroAddress string) (*onboarding.Participant, error) {
|
||||||
|
var participant *onboarding.Participant
|
||||||
|
|
||||||
err := k.Participants.Walk(ctx, nil, func(key string, value onboarding.Participant) (bool, error) {
|
err := k.Participants.Walk(ctx, nil, func(key string, value onboarding.Participant) (bool, error) {
|
||||||
if value.NitroAddress == nitroAddress {
|
ethAddr, err := utils.EthAddressFromPubKey(value.PublicKey)
|
||||||
participant = value
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
if ethAddr.String() == nitroAddress {
|
||||||
|
participant = &value
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return false, nil
|
return false, nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return onboarding.Participant{}, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return participant, nil
|
return participant, nil
|
||||||
|
@ -46,8 +46,10 @@ func (qs queryServer) GetParticipantByAddress(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if participant == nil {
|
||||||
return &onboardingtypes.QueryGetParticipantByAddressResponse{Participant: &participant}, nil
|
return nil, errorsmod.Wrap(sdkerrors.ErrNotFound, "participant with given address not found")
|
||||||
|
}
|
||||||
|
return &onboardingtypes.QueryGetParticipantByAddressResponse{Participant: participant}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetParticipantByNitroAddress implements the GetParticipantByNitroAddress query.
|
// GetParticipantByNitroAddress implements the GetParticipantByNitroAddress query.
|
||||||
@ -63,6 +65,8 @@ func (qs queryServer) GetParticipantByNitroAddress(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if participant == nil {
|
||||||
return &onboardingtypes.QueryGetParticipantByNitroAddressResponse{Participant: &participant}, nil
|
return nil, errorsmod.Wrap(sdkerrors.ErrNotFound, "participant with given Nitro address not found")
|
||||||
|
}
|
||||||
|
return &onboardingtypes.QueryGetParticipantByNitroAddressResponse{Participant: participant}, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user