Skip to content

Commit

Permalink
Short-circuit RegisterAffiliate state read when address is invalid (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyding authored Sep 6, 2024
1 parent 0ce92b3 commit 98d00b4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions protocol/x/affiliates/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ func (k Keeper) RegisterAffiliate(
referee string,
affiliateAddr string,
) error {
if _, found := k.GetReferredBy(ctx, referee); found {
return errorsmod.Wrapf(types.ErrAffiliateAlreadyExistsForReferee, "referee: %s, affiliate: %s",
referee, affiliateAddr)
}
if _, err := sdk.AccAddressFromBech32(referee); err != nil {
return errorsmod.Wrapf(types.ErrInvalidAddress, "referee: %s", referee)
}
if _, err := sdk.AccAddressFromBech32(affiliateAddr); err != nil {
return errorsmod.Wrapf(types.ErrInvalidAddress, "affiliate: %s", affiliateAddr)
}
if _, found := k.GetReferredBy(ctx, referee); found {
return errorsmod.Wrapf(types.ErrAffiliateAlreadyExistsForReferee, "referee: %s, affiliate: %s",
referee, affiliateAddr)
}
prefix.NewStore(ctx.KVStore(k.storeKey), []byte(types.ReferredByKeyPrefix)).Set([]byte(referee), []byte(affiliateAddr))
// TODO(OTE-696): Emit indexer event.
return nil
Expand Down

0 comments on commit 98d00b4

Please sign in to comment.