Skip to content

Commit

Permalink
fixing the notorious gremlin of nil pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
dekm committed May 30, 2024
1 parent 9f711a1 commit 5bd30c5
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions x/ugdmint/module/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"cosmossdk.io/log"
"cosmossdk.io/math"

"runtime/debug"

"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand All @@ -35,6 +37,7 @@ func BeginBlocker(goCtx context.Context, k keeper.Keeper) {
defer func() {
if r := recover(); r != nil {
fmt.Printf("recovered from panic in BeginBlocker: %v\n", r)
debug.PrintStack() // Print the stack trace
}
}()

Expand Down Expand Up @@ -75,11 +78,6 @@ func BeginBlocker(goCtx context.Context, k keeper.Keeper) {
return
}

ok, mintedCoin := mintedCoins.Find("uugd")
if !ok {
_, mintedCoin = mintedCoins.Find("fermi")
}

err2 := k.MintCoins(goCtx, mintedCoins)
if err2 != nil {
fmt.Println("BeginBlocker: Error minting coins:", err2)
Expand All @@ -92,8 +90,13 @@ func BeginBlocker(goCtx context.Context, k keeper.Keeper) {
return
}

if mintedCoin.Amount.IsInt64() {
defer telemetry.ModuleSetGauge(types.ModuleName, float32(mintedCoin.Amount.Int64()), "minted_tokens")
fmt.Println("MintedCoins:", mintedCoins)
for _, coin := range mintedCoins {
if coin.Amount.BigInt() != nil && coin.Amount.IsInt64() {
defer telemetry.ModuleSetGauge(types.ModuleName, float32(coin.Amount.Int64()), "minted_tokens")
} else {
fmt.Println("BeginBlocker: coin.Amount is nil or not an int64 for coin", coin.Denom)
}
}

ctx.EventManager().EmitEvent(
Expand Down

0 comments on commit 5bd30c5

Please sign in to comment.