Skip to content

Commit

Permalink
fixed CheckNftUserExists() in endblocker
Browse files Browse the repository at this point in the history
  • Loading branch information
avendauz committed Aug 12, 2021
1 parent b8fa45c commit c3c0be1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ func NewCRUDApp(
staking.NewAppModule(app.stakingKeeper, app.accountKeeper, app.supplyKeeper),
oracle.NewAppModule(app.oracleKeeper),
aggregator.NewAppModule(app.aggKeeper),
nft.NewAppModule(*app.nftKeeper, nftFileDir, nftP2PPort),
nft.NewAppModule(*app.nftKeeper, app.accountKeeper, nftFileDir, nftP2PPort),
curium.NewAppModule(*app.curiumKeeper),
)

Expand Down
19 changes: 16 additions & 3 deletions x/nft/keeper/keeper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
"errors"
"fmt"
"github.com/bluzelle/curium/x/curium"
"github.com/bluzelle/curium/x/curium/keeper"
Expand All @@ -10,6 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/tendermint/tendermint/libs/log"
"os"
)
Expand Down Expand Up @@ -67,9 +69,20 @@ func (k Keeper) GetCdc() *codec.Codec {
return k.Cdc
}

func (k Keeper) CheckNftUserExists(reader *curium.KeyringReader) error {
_, err := reader.GetAddress("nft")
return err
func (k Keeper) CheckNftUserExists(ctx sdk.Context, reader *curium.KeyringReader, accKeeper auth.AccountKeeper) error {
address, err := reader.GetAddress("nft")

if err != nil {
return err
}

account := accKeeper.GetAccount(ctx, address)

if account == nil {
return errors.New("Nft account does not exist yet")
}

return nil
}

func (k Keeper) Logger(ctx sdk.Context) log.Logger {
Expand Down
7 changes: 5 additions & 2 deletions x/nft/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
nft "github.com/bluzelle/curium/x/nft/keeper"
nftTypes "github.com/bluzelle/curium/x/nft/types"
"github.com/bluzelle/curium/x/torrentClient"
"github.com/cosmos/cosmos-sdk/x/auth"
"sync"

"github.com/gorilla/mux"
Expand Down Expand Up @@ -78,16 +79,18 @@ func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
type AppModule struct {
AppModuleBasic
keeper nft.Keeper
accKeeper auth.AccountKeeper
btDirectory string
btPort int
// TODO: Add keepers that your application depends on
}

// NewAppModule creates a new AppModule object
func NewAppModule(k nft.Keeper, btDirectory string, btPort int /*TODO: Add Keepers that your application depends on*/) AppModule {
func NewAppModule(k nft.Keeper, accKeeper auth.AccountKeeper, btDirectory string, btPort int /*TODO: Add Keepers that your application depends on*/) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{},
keeper: k,
accKeeper: accKeeper,
btDirectory: btDirectory,
btPort: btPort,
// TODO: Add keepers that your application depends on
Expand Down Expand Up @@ -158,7 +161,7 @@ func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Val
am.keeper.SetBtClient(btClient)
})

err := am.keeper.CheckNftUserExists(am.keeper.KeyringReader)
err := am.keeper.CheckNftUserExists(ctx, am.keeper.KeyringReader, am.accKeeper)
fmt.Println("Checking nft user exists", err)
if err != nil {
am.keeper.Logger(ctx).Error("nft user does not exist in keyring", "nft", err)
Expand Down

0 comments on commit c3c0be1

Please sign in to comment.