Skip to content

Commit

Permalink
fix event issues
Browse files Browse the repository at this point in the history
  • Loading branch information
harish551 committed Oct 27, 2023
1 parent ab21faf commit 04c7a25
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 14 deletions.
9 changes: 9 additions & 0 deletions x/itc/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ func (suite *KeeperTestSuite) createDefaultNftDenom() {
"test11",
"{}",
"test description",
"ipfs://testuri",
"ipfs://testUriHash",
"ipfs://testpreviewuri",
"",
suite.TestAccs[0].String(),
onfttypes.DefaultDenomCreationFee,
)
Expand All @@ -153,7 +156,10 @@ func (suite *KeeperTestSuite) createSecondaryNftDenom() {
"test12",
"{}",
"test description",
"ipfs://testuri",
"ipfs://testUriHash",
"ipfs://testpreviewuri",
"",
suite.TestAccs[0].String(),
onfttypes.DefaultDenomCreationFee,
)
Expand All @@ -171,7 +177,10 @@ func (suite *KeeperTestSuite) createDefaultMintNftDenom() {
"test22",
"{}",
"test description",
"ipfs://testuri",
"ipfs://testUriHash",
"ipfs://testpreviewuri",
"",
suite.TestAccs[0].String(),
onfttypes.DefaultDenomCreationFee,
)
Expand Down
17 changes: 14 additions & 3 deletions x/onft/keeper/denom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 0 additions & 8 deletions x/onft/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}
21 changes: 18 additions & 3 deletions x/onft/keeper/onft.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(
Expand All @@ -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) {
Expand Down

0 comments on commit 04c7a25

Please sign in to comment.