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

Use key if possible

Open giorgionocera opened this issue 3 years ago • 5 comments

In the nft module, for the Metadata object we used the keys structures which increase the readability of the code in the interaction with store (save/delete)

https://github.com/bitsongofficial/go-bitsong/blob/84691c819214a1f9b9dd844ea2b49b7ccc8ece1b/x/nft/types/keys.go#L28-L34

Similarly, we could create keys structures also for the other objects.

For example (not only): for the NFTByID https://github.com/bitsongofficial/go-bitsong/blob/84691c819214a1f9b9dd844ea2b49b7ccc8ece1b/x/nft/keeper/nft.go#L69

or NFTByOwner https://github.com/bitsongofficial/go-bitsong/blob/84691c819214a1f9b9dd844ea2b49b7ccc8ece1b/x/nft/keeper/nft.go#L75

This could be useful also because, we increase the reusability of the code and, as a consequence the coherence. It could need a refactor among different files. What do you think?

giorgionocera avatar Sep 29 '22 08:09 giorgionocera

Another example is the one in the nft/keeper/collection.go file. Here the methods GetCollectionById and the SetCollection could make use of the key. More specifically, we could make uniform the usage in lines 36 and 39 in SetCollection https://github.com/bitsongofficial/go-bitsong/blob/84691c819214a1f9b9dd844ea2b49b7ccc8ece1b/x/nft/keeper/collection.go#L35-L40

And similarly in line 26 for GetCollectionById https://github.com/bitsongofficial/go-bitsong/blob/84691c819214a1f9b9dd844ea2b49b7ccc8ece1b/x/nft/keeper/collection.go#L24-L33

giorgionocera avatar Sep 29 '22 09:09 giorgionocera

Agree with that! This will reduce potential unexpected bug caused by one more developer

angelorc avatar Sep 29 '22 10:09 angelorc

The same could also be used in nft.go file at lines:

  • 14 https://github.com/bitsongofficial/go-bitsong/blob/84691c819214a1f9b9dd844ea2b49b7ccc8ece1b/x/nft/keeper/nft.go#L14

  • 33 https://github.com/bitsongofficial/go-bitsong/blob/84691c819214a1f9b9dd844ea2b49b7ccc8ece1b/x/nft/keeper/nft.go#L33

  • 51 https://github.com/bitsongofficial/go-bitsong/blob/84691c819214a1f9b9dd844ea2b49b7ccc8ece1b/x/nft/keeper/nft.go#L51

  • 69 https://github.com/bitsongofficial/go-bitsong/blob/84691c819214a1f9b9dd844ea2b49b7ccc8ece1b/x/nft/keeper/nft.go#L69

  • 75 https://github.com/bitsongofficial/go-bitsong/blob/84691c819214a1f9b9dd844ea2b49b7ccc8ece1b/x/nft/keeper/nft.go#L75

  • 81 https://github.com/bitsongofficial/go-bitsong/blob/84691c819214a1f9b9dd844ea2b49b7ccc8ece1b/x/nft/keeper/nft.go#L81

  • 87 https://github.com/bitsongofficial/go-bitsong/blob/84691c819214a1f9b9dd844ea2b49b7ccc8ece1b/x/nft/keeper/nft.go#L87

giorgionocera avatar Sep 29 '22 11:09 giorgionocera

Okay, will make the suggested changes

ryusmo avatar Sep 30 '22 17:09 ryusmo

This is done on this commit. https://github.com/bitsongofficial/go-bitsong/pull/153/commits/afcba32b4f1dfc1a6db7140b01d17eec347daf99

ryusmo avatar Oct 03 '22 12:10 ryusmo