Skip to content

Commit

Permalink
Merge pull request #333 from irisnet/fix/gon
Browse files Browse the repository at this point in the history
replace base64.RawStdEncoding with base64.StdEncoding
  • Loading branch information
aofengli authored Feb 7, 2023
2 parents a61dbef + 360645b commit e22c383
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
14 changes: 8 additions & 6 deletions modules/nft/types/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions modules/nft/types/builder_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package types

import (
"encoding/base64"
"encoding/json"
"testing"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e22c383

Please sign in to comment.