Skip to content

Commit

Permalink
update: edit nft msg handler
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaghettiOverload committed Sep 20, 2023
1 parent 9a549a3 commit 9cfa93b
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions modules/nft/handle_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,36 +91,27 @@ func (m *Module) handleMsgEditNFT(msg *nftTypes.MsgEditNFT) error {
denomID := msg.DenomId
log.Debug().Str("module", "nft").Str("denomId", denomID).Str("tokenId", nftID).Msg("handling message edit nft")

// Parse newly proposed changes
newDataJSON, newDataText := utils.GetData(msg.Data)
newNftData := dbtypes.EditNftQuery{
Name: msg.Name,
URI: msg.URI,
DataText: newDataText,
DataJSON: newDataJSON,
}

// Getting previous DB records
var currentNftData dbtypes.EditNftQuery
err := m.db.SQL.Select(&currentNftData, `SELECT name, uri, data_text, data_json FROM nft_nft WHERE id = $1 AND denom_id = $2`, nftID, denomID)
var nftData dbtypes.EditNftQuery
err := m.db.SQL.Select(&nftData, `SELECT name, uri, data_text, data_json 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
if msg.Data != nftTypes.DoNotModify {
dataJSON, dataText := utils.GetData(msg.Data)
nftData.DataJSON = dataJSON
nftData.DataText = dataText
}

if newNftData.URI == nftTypes.DoNotModify {
newNftData.URI = currentNftData.URI
if msg.URI != nftTypes.DoNotModify {
nftData.URI = msg.URI
}

if msg.Data == nftTypes.DoNotModify {
newNftData.DataText = currentNftData.DataText
newNftData.DataJSON = currentNftData.DataJSON
if msg.Name != nftTypes.DoNotModify {
nftData.Name = msg.Name
}

return m.db.UpdateNFT(nftID, denomID, newNftData.Name, newNftData.URI, newNftData.DataJSON, newNftData.DataText)
return m.db.UpdateNFT(nftID, denomID, nftData.Name, nftData.URI, nftData.DataJSON, nftData.DataText)
}

func (m *Module) handleMsgTransferNFT(tx *juno.Tx, msg *nftTypes.MsgTransferNft) error {
Expand Down

0 comments on commit 9cfa93b

Please sign in to comment.