@@ -211,52 +211,51 @@ func (k *keeper) AuthorizeDeposits(sctx sdk.Context, msg sdk.Msg) ([]etypes.Depo
211211 msgTypeUrl := (& ev1.DepositAuthorization {}).MsgTypeURL ()
212212
213213 k .authzKeeper .GetGranteeGrantsByMsgType (sctx , owner , msgTypeUrl , func (ctx context.Context , granter sdk.AccAddress , authorization authz.Authorization , expiration * time.Time ) bool {
214- deplAuthz , valid := authorization .(* ev1.DepositAuthorization )
214+ depositAuthz , valid := authorization .(ev1.Authorization )
215215 if ! valid {
216216 return false
217217 }
218218
219- authorizedSpend := sdk.Coin {
220- Denom : denom ,
221- Amount : sdkmath .NewInt (deplAuthz .SpendLimit .Amount .Int64 ()),
222- }
219+ spendableAmount := depositAuthz .GetSpendLimit ()
220+ requestedSpend := sdk .NewCoin (denom , remainder )
223221
224222 // bc authz.Accepts take sdk.Msg as an argument, the deposit amount from incoming message
225223 // has to be modified in place to correctly calculate what deposits to take from grants
226224 switch mt := msg .(type ) {
227225 case * ev1.MsgAccountDeposit :
228- mt .Deposit .Amount = sdk . NewCoin ( denom , sdkmath . NewIntFromBigInt ( remainder . BigInt ()))
226+ mt .Deposit .Amount = requestedSpend
229227 case * dv1beta.MsgCreateDeployment :
230- mt .Deposit .Amount = sdk . NewCoin ( denom , sdkmath . NewIntFromBigInt ( remainder . BigInt ()))
228+ mt .Deposit .Amount = requestedSpend
231229 case * mv1beta.MsgCreateBid :
232- mt .Deposit .Amount = sdk . NewCoin ( denom , sdkmath . NewIntFromBigInt ( remainder . BigInt ()))
230+ mt .Deposit .Amount = requestedSpend
233231 }
234232
235- resp , err := authorization . Accept (ctx , msg )
233+ resp , err := depositAuthz . TryAccept (ctx , msg , true )
236234 if err != nil {
237235 return false
238236 }
239237
240- if resp .Delete {
241- err = k .authzKeeper .DeleteGrant (ctx , owner , granter , msgTypeUrl )
242- } else if resp .Updated != nil {
243- err = k .authzKeeper .SaveGrant (ctx , owner , granter , resp .Updated , expiration )
238+ if ! resp .Accept {
239+ return false
244240 }
245241
246- if ! resp .Accept {
242+ // Delete is ignored here as not all fund may be used during deployment lifetime.
243+ // also, there can be another deployment using same authorization and may return funds before deposit is fully used
244+ err = k .authzKeeper .SaveGrant (ctx , owner , granter , resp .Updated , expiration )
245+ if err != nil {
247246 return false
248247 }
249248
250- deplAuthz = resp .Updated .(* ev1.DepositAuthorization )
249+ depositAuthz = resp .Updated .(ev1.Authorization )
251250
252- authorizedSpend = authorizedSpend .Sub (deplAuthz . SpendLimit )
251+ spendableAmount = spendableAmount .Sub (depositAuthz . GetSpendLimit () )
253252
254253 depositors = append (depositors , etypes.Depositor {
255254 Owner : granter .String (),
256255 Height : sctx .BlockHeight (),
257- Balance : sdk .NewDecCoinFromCoin (authorizedSpend ),
256+ Balance : sdk .NewDecCoinFromCoin (spendableAmount ),
258257 })
259- remainder = remainder .Sub (authorizedSpend .Amount )
258+ remainder = remainder .Sub (spendableAmount .Amount )
260259
261260 return remainder .IsZero ()
262261 })
0 commit comments