Skip to content

Commit

Permalink
Enhance validation for auxiliary request
Browse files Browse the repository at this point in the history
The updated code includes enhanced validation processes in the auxiliary request function, now using custom error checking. It ensures the validity of the owner and asset IDs and checks that the value is greater than zero. It also offers improved error messages by replacing govalidator, removing unnecessary 'valid' struct tags and therefore making the overall testing more concise and clear.
  • Loading branch information
deepanshutr committed Apr 12, 2024
1 parent adac516 commit 5fdd1dd
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions x/splits/auxiliaries/burn/auxiliary_keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package burn

import (
"context"
errorConstants "github.com/AssetMantle/schema/go/errors/constants"
"reflect"

"github.com/AssetMantle/modules/helpers"
"github.com/AssetMantle/modules/x/splits/utilities"
Expand All @@ -17,10 +19,17 @@ type auxiliaryKeeper struct {
var _ helpers.AuxiliaryKeeper = (*auxiliaryKeeper)(nil)

func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) {
auxiliaryRequest := auxiliaryRequestFromInterface(request)
if err := request.Validate(); err != nil {
return nil, err
}

auxiliaryRequest, ok := request.(auxiliaryRequest)
if !ok {
return nil, errorConstants.InvalidRequest.Wrapf("invalid request type: %s", reflect.TypeOf(request).String())
}

if _, err := utilities.SubtractSplits(auxiliaryKeeper.mapper.NewCollection(context), auxiliaryRequest.OwnerID, auxiliaryRequest.AssetID, auxiliaryRequest.Value); err != nil {
return newAuxiliaryResponse(), err
return nil, err
}

return newAuxiliaryResponse(), nil
Expand Down

0 comments on commit 5fdd1dd

Please sign in to comment.