diff --git a/database/types/nft.go b/database/types/nft.go new file mode 100644 index 000000000..6aa3b474f --- /dev/null +++ b/database/types/nft.go @@ -0,0 +1,7 @@ +package types + +type EditNftQuery struct { + Name string `json:"name"` + Uri string `json:"uri"` + DataText string `json:"data_text"` +} diff --git a/modules/nft/handle_msg.go b/modules/nft/handle_msg.go index 756614159..02cdc0d19 100644 --- a/modules/nft/handle_msg.go +++ b/modules/nft/handle_msg.go @@ -8,6 +8,7 @@ import ( nftTypes "github.com/CudoVentures/cudos-node/x/nft/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/forbole/bdjuno/v4/database" + dbtypes "github.com/forbole/bdjuno/v4/database/types" utils "github.com/forbole/bdjuno/v4/utils" juno "github.com/forbole/juno/v5/types" "github.com/rs/zerolog/log" @@ -88,9 +89,34 @@ func (m *Module) handleMsgMintNFT(index int, tx *juno.Tx, msg *nftTypes.MsgMintN func (m *Module) handleMsgEditNFT(msg *nftTypes.MsgEditNFT) error { log.Debug().Str("module", "nft").Str("denomId", msg.DenomId).Str("tokenId", msg.Id).Msg("handling message edit nft") + nftID := msg.Id + denomID := msg.DenomId dataJSON, dataText := utils.GetData(msg.Data) + newNftData := dbtypes.EditNftQuery{ + Name: msg.Name, + Uri: msg.URI, + DataText: msg.Data, + } + + var currentNftData dbtypes.EditNftQuery + err := m.db.SQL.Select(¤tNftData, `SELECT name, uri, data_text FROM nft_nft WHERE id = $1 AND denom_id =$2`, nftID, denomID) + if err != nil { + return err + } + + if newNftData.Name == nftTypes.DoNotModify || newNftData.Name == currentNftData.Name { + newNftData.Name = currentNftData.Name + } + + if newNftData.Uri == nftTypes.DoNotModify || newNftData.Uri == currentNftData.Uri { + newNftData.Uri = currentNftData.Uri + } + + if newNftData.DataText == nftTypes.DoNotModify || newNftData.DataText == currentNftData.DataText { + dataJSON, dataText = utils.GetData(currentNftData.DataText) + } - return m.db.UpdateNFT(msg.Id, msg.DenomId, msg.Name, msg.URI, utils.SanitizeUTF8(dataJSON), dataText) + return m.db.UpdateNFT(nftID, denomID, newNftData.Name, newNftData.Uri, utils.SanitizeUTF8(dataJSON), dataText) } func (m *Module) handleMsgTransferNFT(tx *juno.Tx, msg *nftTypes.MsgTransferNft) error {