Skip to content

Commit

Permalink
chore: transfer authz nits (backport #3586) (#3589)
Browse files Browse the repository at this point in the history
* chore: optimise transfer authz to consume less gas for unbounded spend limits (#3586)

(cherry picked from commit f6e8f03)

# Conflicts:
#	modules/apps/transfer/types/transfer_authorization.go

* resolve conflicts

---------

Co-authored-by: Damian Nolan <damiannolan@gmail.com>
  • Loading branch information
mergify[bot] and damiannolan authored May 16, 2023
1 parent 1a99cb7 commit 80e9f6a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion modules/apps/transfer/types/transfer_authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (a TransferAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.Accep

// If the spend limit is set to the MaxUint256 sentinel value, do not subtract the amount from the spend limit.
if allocation.SpendLimit.AmountOf(msgTransfer.Token.Denom).Equal(UnboundedSpendLimit()) {
return authz.AcceptResponse{Accept: true, Delete: false, Updated: &a}, nil
return authz.AcceptResponse{Accept: true, Delete: false, Updated: nil}, nil
}

limitLeft, isNegative := allocation.SpendLimit.SafeSub(msgTransfer.Token)
Expand Down
8 changes: 3 additions & 5 deletions modules/apps/transfer/types/transfer_authorization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,9 @@ func (suite *TypesTestSuite) TestTransferAuthorizationAccept() {
func(res authz.AcceptResponse, err error) {
suite.Require().NoError(err)

updatedTransferAuthz, ok := res.Updated.(*types.TransferAuthorization)
suite.Require().True(ok)

remainder := updatedTransferAuthz.Allocations[0].SpendLimit.AmountOf(sdk.DefaultBondDenom)
suite.Require().True(types.UnboundedSpendLimit().Equal(remainder))
suite.Require().True(res.Accept)
suite.Require().False(res.Delete)
suite.Require().Nil(res.Updated)
},
},
{
Expand Down

0 comments on commit 80e9f6a

Please sign in to comment.