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 7771f98 commit 9a549a3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions database/types/nft.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ type EditNftQuery struct {
Name string `json:"name"`
URI string `json:"uri"`
DataText string `json:"data_text"`
DataJSON string `json:"data_json"`
}
24 changes: 14 additions & 10 deletions modules/nft/handle_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,36 +87,40 @@ 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)
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: msg.Data,
DataText: newDataText,
DataJSON: newDataJSON,
}

// Getting previous DB records
var currentNftData dbtypes.EditNftQuery
err := m.db.SQL.Select(&currentNftData, `SELECT name, uri, data_text FROM nft_nft WHERE id = $1 AND denom_id =$2`, nftID, denomID)
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)
if err != nil {
return err
}

if newNftData.Name == nftTypes.DoNotModify || newNftData.Name == currentNftData.Name {
if newNftData.Name == nftTypes.DoNotModify {
newNftData.Name = currentNftData.Name
}

if newNftData.URI == nftTypes.DoNotModify || newNftData.URI == currentNftData.URI {
if newNftData.URI == nftTypes.DoNotModify {
newNftData.URI = currentNftData.URI
}

if newNftData.DataText == nftTypes.DoNotModify || newNftData.DataText == currentNftData.DataText {
dataJSON, dataText = utils.GetData(currentNftData.DataText)
if msg.Data == nftTypes.DoNotModify {
newNftData.DataText = currentNftData.DataText
newNftData.DataJSON = currentNftData.DataJSON
}

return m.db.UpdateNFT(nftID, denomID, newNftData.Name, newNftData.URI, utils.SanitizeUTF8(dataJSON), dataText)
return m.db.UpdateNFT(nftID, denomID, newNftData.Name, newNftData.URI, newNftData.DataJSON, newNftData.DataText)
}

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

0 comments on commit 9a549a3

Please sign in to comment.