@@ -115,23 +115,24 @@ func (a GenericExchangeAuthorization) MsgTypeURL() string {
115115}
116116
117117// Accept implements Authorization.Accept.
118- func (a GenericExchangeAuthorization ) Accept (ctx context.Context , msg sdk.Msg ) (authz.AcceptResponse , error ) {
119- // SpendLimit is optional, so we only check it if it is set
120- if a .SpendLimit != nil {
121- hold , ok := getHold (ctx )
122- if ! ok {
118+ func (a GenericExchangeAuthorization ) Accept (ctx context.Context , _ sdk.Msg ) (authz.AcceptResponse , error ) {
119+ hold , _ := getHold (ctx )
120+
121+ if a .SpendLimit .IsZero () && ! hold .IsZero () { // on an exhausted grant only allow zero hold messages (like cancellations) (BB-225)
122+ return authz.AcceptResponse {Accept : false }, nil
123+ }
124+
125+ limit := a .SpendLimit
126+ for _ , coin := range hold {
127+ allowance := limit .AmountOf (coin .Denom )
128+ if allowance .LT (coin .Amount ) {
123129 return authz.AcceptResponse {Accept : false }, nil
124130 }
125131
126- for _ , coin := range hold {
127- allowed := a .SpendLimit .AmountOf (coin .Denom )
128- if allowed .LT (coin .Amount ) {
129- return authz.AcceptResponse {Accept : false }, nil
130- }
131- a .SpendLimit = a .SpendLimit .Sub (sdk .NewCoin (coin .Denom , coin .Amount ))
132- }
132+ limit = limit .Sub (sdk .NewCoin (coin .Denom , coin .Amount ))
133133 }
134- return authz.AcceptResponse {Accept : true , Updated : & a }, nil
134+
135+ return authz.AcceptResponse {Accept : true , Updated : NewGenericExchangeAuthorization (a .Msg , limit )}, nil
135136}
136137
137138// getHold returns the hold from the context. Hold is the amount of coins that
0 commit comments