diff --git a/modules/nft/types/builder.go b/modules/nft/types/builder.go index 5de913075..5c160e3e1 100644 --- a/modules/nft/types/builder.go +++ b/modules/nft/types/builder.go @@ -30,6 +30,8 @@ var ( ClassKeySchema = fmt.Sprintf("%s%s", Namespace, "schema") TokenKeyName = fmt.Sprintf("%s%s", Namespace, "name") TokenKeyURIhash = fmt.Sprintf("%s%s", Namespace, "uri_hash") + + Base64 = base64.StdEncoding ) type ( @@ -70,7 +72,7 @@ func (cb ClassBuilder) BuildMetadata(class nft.Class) (string, error) { err := json.Unmarshal([]byte(metadata.Data), &kvals) if err != nil && IsIBCDenom(class.Id) { //when classData is not a legal json, there is no need to parse the data - return base64.RawStdEncoding.EncodeToString([]byte(metadata.Data)), nil + return Base64.EncodeToString([]byte(metadata.Data)), nil } //note: if metadata.Data is null, it may cause map to be redefined as nil if kvals == nil { @@ -95,12 +97,12 @@ func (cb ClassBuilder) BuildMetadata(class nft.Class) (string, error) { if err != nil { return "", err } - return base64.RawStdEncoding.EncodeToString(data), nil + return Base64.EncodeToString(data), nil } // Build create a class from ics721 packetData func (cb ClassBuilder) Build(classID, classURI, classData string) (nft.Class, error) { - classDataBz, err := base64.RawStdEncoding.DecodeString(classData) + classDataBz, err := Base64.DecodeString(classData) if err != nil { return nft.Class{}, err } @@ -267,7 +269,7 @@ func (tb TokenBuilder) BuildMetadata(token nft.NFT) (string, error) { err := json.Unmarshal([]byte(nftMetadata.Data), &kvals) if err != nil && IsIBCDenom(token.ClassId) { //when nftMetadata is not a legal json, there is no need to parse the data - return base64.RawStdEncoding.EncodeToString([]byte(nftMetadata.Data)), nil + return Base64.EncodeToString([]byte(nftMetadata.Data)), nil } //note: if nftMetadata.Data is null, it may cause map to be redefined as nil if kvals == nil { @@ -280,12 +282,12 @@ func (tb TokenBuilder) BuildMetadata(token nft.NFT) (string, error) { if err != nil { return "", err } - return base64.RawStdEncoding.EncodeToString(data), nil + return Base64.EncodeToString(data), nil } // Build create a nft from ics721 packet data func (tb TokenBuilder) Build(classId, tokenId, tokenURI, tokenData string) (nft.NFT, error) { - tokenDataBz, err := base64.RawStdEncoding.DecodeString(tokenData) + tokenDataBz, err := Base64.DecodeString(tokenData) if err != nil { return nft.NFT{}, err } diff --git a/modules/nft/types/builder_test.go b/modules/nft/types/builder_test.go index d8052a909..fa4db91fc 100644 --- a/modules/nft/types/builder_test.go +++ b/modules/nft/types/builder_test.go @@ -1,7 +1,6 @@ package types import ( - "encoding/base64" "encoding/json" "testing" @@ -166,7 +165,7 @@ func TestClassBuilder_BuildMetadata(t *testing.T) { class.Data = any got, err := cb.BuildMetadata(class) - want := base64.RawStdEncoding.EncodeToString([]byte(tt.want)) + want := Base64.EncodeToString([]byte(tt.want)) if (err != nil) != tt.wantErr { t.Errorf("ClassBuilder.BuildMetadata() error = %v, wantErr %v", err, tt.wantErr) return @@ -229,7 +228,7 @@ func TestClassBuilder_Build(t *testing.T) { cdc: cdc, getModuleAddress: getModuleAddress, } - classDataRaw := base64.RawStdEncoding.EncodeToString([]byte(tt.args.classData)) + classDataRaw := Base64.EncodeToString([]byte(tt.args.classData)) result, err := cb.Build(classID, classURI, classDataRaw) if (err != nil) != tt.wantErr { t.Errorf("ClassBuilder.BuildMetadata() error = %v, wantErr %v", err, tt.wantErr)