Skip to content

Commit

Permalink
Simplifying usage of GetInflation(...) (return value)
Browse files Browse the repository at this point in the history
  • Loading branch information
pbukva committed Sep 5, 2023
1 parent fd3ebbd commit 64f2fd0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions x/mint/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ func HandleMunicipalInflation(minter *types.Minter, params *types.Params, ctx *s
// gather supply value & calculate number of new tokens created from relevant inflation
totalDenomSupply := k.BankKeeper.GetSupply(*ctx, pair.Denom)

cacheItem, exists := cache.GMunicipalInflationCache.GetInflation(pair.Denom)
cacheItem := cache.GMunicipalInflationCache.GetInflation(pair.Denom)

if !exists {
if cacheItem == nil {
panic(fmt.Errorf("numicipal inflation: missing cache item for the \"%s\" denomination", pair.Denom))
}

Expand Down
11 changes: 8 additions & 3 deletions x/mint/cache/municipal_inflation_cahe.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,19 @@ func (cache *MunicipalInflationCache) RefreshIfNecessary(inflations *[]*types.Mu
}
}

func (cache *MunicipalInflationCache) GetInflation(denom string) (*MunicipalInflationCacheItem, bool) {
func (cache *MunicipalInflationCache) GetInflation(denom string) *MunicipalInflationCacheItem {
val := cache.internal.Load()
if val == nil {
return nil, false
return nil
}

infl, exists := val.(*MunicipalInflationCacheInternal).inflations[denom]
return infl, exists

if exists && infl != nil {
return infl
}

return nil
}

func (cache *MunicipalInflationCache) GetOriginal() *[]*types.MunicipalInflationPair {
Expand Down
4 changes: 2 additions & 2 deletions x/mint/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func (k Keeper) MunicipalInflation(c context.Context, req *types.QueryMunicipalI
return &types.QueryMunicipalInflationResponse{Inflations: *cache.GMunicipalInflationCache.GetOriginal()}, nil
}

infl, exists := cache.GMunicipalInflationCache.GetInflation(denom)
if !exists {
infl := cache.GMunicipalInflationCache.GetInflation(denom)
if infl == nil {
return nil, fmt.Errorf("there is no municipal inflation defined for requested \"%s\" denomination", denom)
}

Expand Down

0 comments on commit 64f2fd0

Please sign in to comment.