go-bitsong icon indicating copy to clipboard operation
go-bitsong copied to clipboard

SetNFT for existing NFT

Open giorgionocera opened this issue 3 years ago • 3 comments

In the nft module, the method which allows to save a new NFT (the SetNFT method), performs a search to find any existing NFT with the same ID. If the search produces positive results (find the NFT), the method proceeds by deleting the old one and adding the new one

https://github.com/bitsongofficial/go-bitsong/blob/84691c819214a1f9b9dd844ea2b49b7ccc8ece1b/x/nft/keeper/nft.go#L60-L64

Why do we follow this pattern? In the fantoken module, during a new FanToken saving procedure, if an existing FanTokein is found, the insertion returns an error

https://github.com/bitsongofficial/go-bitsong/blob/84691c819214a1f9b9dd844ea2b49b7ccc8ece1b/x/fantoken/keeper/fantoken.go#L57-L60

Why do we follow different patterns? Is there any advantage in deleting the old NFT and providing the new one?

giorgionocera avatar Sep 29 '22 07:09 giorgionocera

Moreover, if we do not need the DeleteNFT method, we can also remove it, since it is only used inside the SetNFT method

https://github.com/bitsongofficial/go-bitsong/blob/84691c819214a1f9b9dd844ea2b49b7ccc8ece1b/x/nft/keeper/nft.go#L78-L88

giorgionocera avatar Sep 29 '22 14:09 giorgionocera

We delete previous NFT because, it has NFT information as well as NFT by owner keys. When set NFT is called on transfer NFT, only owner field will need to be updated. But if it's used on NFT update, only nft data itself should be updated. To make things put on a single place and can be used multiple times, this is introduced.

ryusmo avatar Sep 30 '22 17:09 ryusmo

What do you mean by NFT update? An NFT is made up of:

type NFT struct {
	CollId // Which should never change
	MetadataId // Which should never change
	Seq // Which should never change
	Owner // Which could change
}

IMHO, only the Owner should be able to change for an NFT. If we want to change part of Metadata, this is related to metadata, not NFT directly. WRT the TransferNFT (which is related to changing the Owner), this would only require deleting the old element from NFTByOwner and adding the new one. If DeleteNFT is not so used, we could implement the Delete and Set operations on the TransferNFT method.

giorgionocera avatar Sep 30 '22 18:09 giorgionocera