address issues from audit (#793)

This commit is contained in:
Kevin Davis 2021-02-04 11:35:24 -07:00 committed by GitHub
parent be498c72f5
commit 3d6e730368
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 12 deletions

View File

@ -136,10 +136,8 @@ func (k Keeper) UnblockAddress(ctx sdk.Context, denom string, owner, addr sdk.Ac
} }
blocked, i := k.checkBlockedAddress(asset, addr) blocked, i := k.checkBlockedAddress(asset, addr)
if !blocked { if !blocked {
if blocked {
return sdkerrors.Wrapf(types.ErrAccountAlreadyUnblocked, "address: %s", addr) return sdkerrors.Wrapf(types.ErrAccountAlreadyUnblocked, "address: %s", addr)
} }
}
blockedAddrs := k.removeBlockedAddress(asset.BlockedAddresses, i) blockedAddrs := k.removeBlockedAddress(asset.BlockedAddresses, i)
asset.BlockedAddresses = blockedAddrs asset.BlockedAddresses = blockedAddrs

View File

@ -56,17 +56,22 @@ func (k Keeper) UpdateTimeBasedSupplyLimits(ctx sdk.Context) {
if !found { if !found {
supply = k.CreateNewAssetSupply(ctx, asset.Denom) supply = k.CreateNewAssetSupply(ctx, asset.Denom)
} }
if asset.RateLimit.Active { if !asset.RateLimit.Active {
if asset.RateLimit.TimePeriod <= supply.TimeElapsed+timeElapsed { // rate limiting is not active, reset supply
supply.TimeElapsed = time.Duration(0)
supply.CurrentSupply = sdk.NewCoin(asset.Denom, sdk.ZeroInt()) supply.CurrentSupply = sdk.NewCoin(asset.Denom, sdk.ZeroInt())
} else { supply.TimeElapsed = time.Duration(0)
k.SetAssetSupply(ctx, supply, asset.Denom)
continue
}
if asset.RateLimit.TimePeriod > supply.TimeElapsed+timeElapsed {
// rate limiting is active, the rate-limiting period has not expired
supply.TimeElapsed = supply.TimeElapsed + timeElapsed supply.TimeElapsed = supply.TimeElapsed + timeElapsed
k.SetAssetSupply(ctx, supply, asset.Denom)
continue
} }
} else { // rate limiting is active, the rate-limiting period has expired, and is now reset
supply.CurrentSupply = sdk.NewCoin(asset.Denom, sdk.ZeroInt())
supply.TimeElapsed = time.Duration(0) supply.TimeElapsed = time.Duration(0)
} supply.CurrentSupply = sdk.NewCoin(asset.Denom, sdk.ZeroInt())
k.SetAssetSupply(ctx, supply, asset.Denom) k.SetAssetSupply(ctx, supply, asset.Denom)
} }
k.SetPreviousBlockTime(ctx, ctx.BlockTime()) k.SetPreviousBlockTime(ctx, ctx.BlockTime())

View File

@ -114,7 +114,7 @@ func (a Asset) String() string {
a.Owner, a.Paused, a.Denom, a.BlockedAddresses, a.RateLimit) a.Owner, a.Paused, a.Denom, a.BlockedAddresses, a.RateLimit)
} }
// Assets array of Asset // Assets slice of Asset
type Assets []Asset type Assets []Asset
// Validate checks if all assets are valid and there are no duplicate entries // Validate checks if all assets are valid and there are no duplicate entries