From 04c7a255b2d711299fae6b6dc63521aaea989281 Mon Sep 17 00:00:00 2001 From: Harish Marri Date: Fri, 27 Oct 2023 17:09:02 +0530 Subject: [PATCH] fix event issues --- x/itc/keeper/keeper_test.go | 9 +++++++++ x/onft/keeper/denom.go | 17 ++++++++++++++--- x/onft/keeper/msg_server.go | 8 -------- x/onft/keeper/onft.go | 21 ++++++++++++++++++--- 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/x/itc/keeper/keeper_test.go b/x/itc/keeper/keeper_test.go index 15c614b2..60444cde 100644 --- a/x/itc/keeper/keeper_test.go +++ b/x/itc/keeper/keeper_test.go @@ -135,7 +135,10 @@ func (suite *KeeperTestSuite) createDefaultNftDenom() { "test11", "{}", "test description", + "ipfs://testuri", + "ipfs://testUriHash", "ipfs://testpreviewuri", + "", suite.TestAccs[0].String(), onfttypes.DefaultDenomCreationFee, ) @@ -153,7 +156,10 @@ func (suite *KeeperTestSuite) createSecondaryNftDenom() { "test12", "{}", "test description", + "ipfs://testuri", + "ipfs://testUriHash", "ipfs://testpreviewuri", + "", suite.TestAccs[0].String(), onfttypes.DefaultDenomCreationFee, ) @@ -171,7 +177,10 @@ func (suite *KeeperTestSuite) createDefaultMintNftDenom() { "test22", "{}", "test description", + "ipfs://testuri", + "ipfs://testUriHash", "ipfs://testpreviewuri", + "", suite.TestAccs[0].String(), onfttypes.DefaultDenomCreationFee, ) diff --git a/x/onft/keeper/denom.go b/x/onft/keeper/denom.go index f18d585f..6334f332 100644 --- a/x/onft/keeper/denom.go +++ b/x/onft/keeper/denom.go @@ -34,7 +34,7 @@ func (k Keeper) SaveDenom( if err != nil { return err } - return k.nk.SaveClass(ctx, nft.Class{ + err = k.nk.SaveClass(ctx, nft.Class{ Id: id, Name: name, Symbol: symbol, @@ -43,6 +43,13 @@ func (k Keeper) SaveDenom( UriHash: uriHash, Data: metadata, }) + if err != nil { + return err + } + // emit events + k.emitCreateONFTDenomEvent(ctx, id, symbol, name, creator.String()) + + return nil } // TransferDenomOwner transfers the ownership to new address @@ -87,9 +94,13 @@ func (k Keeper) TransferDenomOwner( UriHash: denom.UriHash, Data: data, } - k.emitTransferONFTDenomEvent(ctx, denomID, denom.Symbol, sender, recipient) - return k.nk.UpdateClass(ctx, class) + err = k.nk.UpdateClass(ctx, class) + if err != nil { + return err + } + k.emitTransferONFTDenomEvent(ctx, denomID, denom.Symbol, sender, recipient) + return nil } func (k Keeper) HasDenom(ctx sdk.Context, id string) bool { diff --git a/x/onft/keeper/msg_server.go b/x/onft/keeper/msg_server.go index d4a4a5bc..93c9cfe5 100644 --- a/x/onft/keeper/msg_server.go +++ b/x/onft/keeper/msg_server.go @@ -82,9 +82,6 @@ func (m msgServer) CreateDenom(goCtx context.Context, msg *types.MsgCreateDenom) return nil, err } - // emit events - m.Keeper.emitCreateONFTDenomEvent(ctx, msg.Id, msg.Symbol, msg.Name, msg.Sender) - return &types.MsgCreateDenomResponse{}, nil } @@ -166,7 +163,6 @@ func (m msgServer) MintONFT(goCtx context.Context, msg *types.MsgMintONFT) (*typ return nil, err } - m.Keeper.emitMintONFTEvent(ctx, msg.Id, msg.DenomId, msg.Metadata.MediaURI, msg.Recipient) return &types.MsgMintONFTResponse{}, nil } @@ -191,8 +187,6 @@ func (m msgServer) TransferONFT(goCtx context.Context, return nil, err } - m.Keeper.emitTransferONFTEvent(ctx, msg.Id, msg.DenomId, msg.Sender, msg.Recipient) - return &types.MsgTransferONFTResponse{}, nil } @@ -209,7 +203,5 @@ func (m msgServer) BurnONFT(goCtx context.Context, return nil, err } - m.Keeper.emitBurnONFTEvent(ctx, msg.Id, msg.DenomId, msg.Sender) - return &types.MsgBurnONFTResponse{}, nil } diff --git a/x/onft/keeper/onft.go b/x/onft/keeper/onft.go index 9f2e2848..c5573a52 100644 --- a/x/onft/keeper/onft.go +++ b/x/onft/keeper/onft.go @@ -44,13 +44,18 @@ func (k Keeper) MintONFT( if err != nil { return err } - return k.nk.Mint(ctx, nft.NFT{ + err = k.nk.Mint(ctx, nft.NFT{ ClassId: denomID, Id: nftID, Uri: mediaURI, UriHash: uriHash, Data: data, }, receiver) + if err != nil { + return err + } + k.emitMintONFTEvent(ctx, nftID, denomID, mediaURI, receiver.String()) + return nil } func (k Keeper) TransferOwnership(ctx sdk.Context, denomID, onftID string, srcOwner, dstOwner sdk.AccAddress) error { @@ -74,7 +79,12 @@ func (k Keeper) TransferOwnership(ctx sdk.Context, denomID, onftID string, srcOw if !onftMetadata.Transferable { return errorsmod.Wrap(types.ErrNotTransferable, onft.GetId()) } - return k.nk.Transfer(ctx, denomID, onftID, dstOwner) + err = k.nk.Transfer(ctx, denomID, onftID, dstOwner) + if err != nil { + return err + } + k.emitTransferONFTEvent(ctx, onftID, denomID, srcOwner.String(), dstOwner.String()) + return nil } func (k Keeper) BurnONFT( @@ -96,7 +106,12 @@ func (k Keeper) BurnONFT( return err } - return k.nk.Burn(ctx, denomID, onftID) + err = k.nk.Burn(ctx, denomID, onftID) + if err != nil { + return err + } + k.emitBurnONFTEvent(ctx, onftID, denomID, owner.String()) + return nil } func (k Keeper) GetONFT(ctx sdk.Context, denomID, onftID string) (nft exported.ONFTI, err error) {