From ab21faf0a8d515c8582d0cf51e0b55e2df11cf25 Mon Sep 17 00:00:00 2001 From: Harish Marri Date: Fri, 27 Oct 2023 15:10:04 +0530 Subject: [PATCH] update nft builder file --- x/onft/types/builder.go | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/x/onft/types/builder.go b/x/onft/types/builder.go index cccbecb4..11020a70 100644 --- a/x/onft/types/builder.go +++ b/x/onft/types/builder.go @@ -30,10 +30,7 @@ var ( nftKeyName = fmt.Sprintf("%s%s", Namespace, "name") nftKeyURIHash = fmt.Sprintf("%s%s", Namespace, "uri_hash") nftKeyPreviewURI = fmt.Sprintf("%s%s", Namespace, "preview_uri") - nftKeyTransferable = fmt.Sprintf("%s%s", Namespace, "transferable") - nftKeyExtensible = fmt.Sprintf("%s%s", Namespace, "extensible") - nftKeyNSFW = fmt.Sprintf("%s%s", Namespace, "nsfw") - nftKeyRoyaltyShare = fmt.Sprintf("%s%s", Namespace, "royalty_share") + nftKeyDescription = fmt.Sprintf("%s%s", Namespace, "description") ) type ClassBuilder struct { @@ -121,7 +118,7 @@ func (cb ClassBuilder) Build(classID, classURI, classData string) (nft.Class, er dataMap := make(map[string]interface{}) if err := json.Unmarshal(classDataBz, &dataMap); err != nil { - any, err := codectypes.NewAnyWithValue(&DenomMetadata{ + denomMeta, err := codectypes.NewAnyWithValue(&DenomMetadata{ Creator: creator, Schema: schema, Description: description, @@ -138,7 +135,7 @@ func (cb ClassBuilder) Build(classID, classURI, classData string) (nft.Class, er Symbol: symbol, Description: description, UriHash: uriHash, - Data: any, + Data: denomMeta, }, nil } if v, ok := dataMap[ClassKeyName]; ok { @@ -244,20 +241,20 @@ func NewNFTBuilder(cdc codec.Codec) NFTBuilder { } // BuildMetadata encode nft into the metadata format defined by ics721 -func (nb NFTBuilder) BuildMetadata(token nft.NFT) (string, error) { +func (nb NFTBuilder) BuildMetadata(_nft nft.NFT) (string, error) { var message proto.Message - if err := nb.cdc.UnpackAny(token.Data, &message); err != nil { + if err := nb.cdc.UnpackAny(_nft.Data, &message); err != nil { return "", err } nftMetadata, ok := message.(*ONFTMetadata) if !ok { - return "", errors.New("unsupport classMetadata") + return "", errors.New("unsupported classMetadata") } kvals := make(map[string]interface{}) if len(nftMetadata.Data) > 0 { err := json.Unmarshal([]byte(nftMetadata.Data), &kvals) - if err != nil && IsIBCDenom(token.ClassId) { + if err != nil && IsIBCDenom(_nft.ClassId) { // when nftMetadata is not a legal json, there is no need to parse the data return base64.RawStdEncoding.EncodeToString([]byte(nftMetadata.Data)), nil } @@ -267,7 +264,9 @@ func (nb NFTBuilder) BuildMetadata(token nft.NFT) (string, error) { } } kvals[nftKeyName] = MediaField{Value: nftMetadata.Name} - kvals[nftKeyURIHash] = MediaField{Value: token.UriHash} + kvals[nftKeyURIHash] = MediaField{Value: _nft.UriHash} + kvals[nftKeyPreviewURI] = MediaField{Value: nftMetadata.PreviewURI} + kvals[nftKeyDescription] = MediaField{Value: nftMetadata.Description} data, err := json.Marshal(kvals) if err != nil { return "", err @@ -276,7 +275,7 @@ func (nb NFTBuilder) BuildMetadata(token nft.NFT) (string, error) { } // Build create a nft from ics721 packet data -func (nb NFTBuilder) Build(classId, nftID, tokenURI, nftData string) (nft.NFT, error) { +func (nb NFTBuilder) Build(classId, nftID, nftURI, nftData string) (nft.NFT, error) { nftDataBz, err := base64.RawStdEncoding.DecodeString(nftData) if err != nil { return nft.NFT{}, err @@ -294,7 +293,7 @@ func (nb NFTBuilder) Build(classId, nftID, tokenURI, nftData string) (nft.NFT, e return nft.NFT{ ClassId: classId, Id: nftID, - Uri: tokenURI, + Uri: nftURI, Data: metadata, }, nil } @@ -341,7 +340,7 @@ func (nb NFTBuilder) Build(classId, nftID, tokenURI, nftData string) (nft.NFT, e return nft.NFT{ ClassId: classId, Id: nftID, - Uri: tokenURI, + Uri: nftURI, UriHash: uriHash, Data: metadata, }, nil