From d342b27cbb71288931337d37ff997d1ed12c0dd4 Mon Sep 17 00:00:00 2001 From: Jude Zhu Date: Fri, 28 Jun 2024 13:37:10 -0700 Subject: [PATCH] remove unused util method --- common/utils.go | 53 -------------------------------------------- common/utils_test.go | 32 -------------------------- 2 files changed, 85 deletions(-) delete mode 100644 common/utils.go delete mode 100644 common/utils_test.go diff --git a/common/utils.go b/common/utils.go deleted file mode 100644 index d7db527..0000000 --- a/common/utils.go +++ /dev/null @@ -1,53 +0,0 @@ -package common - -import ( - "fmt" - "reflect" - "regexp" -) - -var ( - placeholderNonFungibleToken = regexp.MustCompile(`"[^"\s]?.*NonFungibleToken(\.cdc)?"`) - placeholderExampleNFT = regexp.MustCompile(`"[^"\s].*ExampleNFT.cdc"`) - placeholderMetadataViews = regexp.MustCompile(`"[^"\s].*MetadataViews.cdc"`) - placeholderFungibleToken = regexp.MustCompile(`"[^"\s].*FungibleToken.cdc"`) -) - -type Replacer map[AddressName]*regexp.Regexp - -type AddressName string - -const ( - NonFungibleTokenAddr AddressName = "NonFungibleToken" -) - -func NewReplacer() Replacer { - xxx := map[AddressName]*regexp.Regexp{ - NonFungibleTokenAddr: placeholderNonFungibleToken, - } - return xxx -} - -func (r Replacer) ReplaceAddresses(code string, data interface{}) (string, error) { - - val := reflect.ValueOf(data) - if val.Kind() != reflect.Struct { - return "", fmt.Errorf("data must be a struct") - } - - var code1 = code - for i := 0; i < val.NumField(); i++ { - field := val.Type().Field(i) - fieldName := field.Name - fieldValue := val.Field(i).String() - - placeholder := AddressName(fieldName) - if r[placeholder] == nil { - return "", fmt.Errorf("no placeholder found for %s", placeholder) - } - - code1 = r[placeholder].ReplaceAllString(code1, "0x"+fieldValue) - fmt.Printf(`"%s %s"\n`, fieldName, fieldValue) - } - return code1, nil -} diff --git a/common/utils_test.go b/common/utils_test.go deleted file mode 100644 index 9816da7..0000000 --- a/common/utils_test.go +++ /dev/null @@ -1,32 +0,0 @@ -package common - -import ( - "github.com/dapperlabs/studio-platform-smart-contracts/pds" - "testing" -) - -func TestGetUserOwnedEditionToMomentMap_Transaction(t *testing.T) { - script, err := pds.Transaction.ReadFile("transactions/deploy/deploy-packNFT-with-auth.cdc") - if err != nil { - t.Fatal(err) - } - t.Log(string(script)) -} - -func TestGetUserOwnedEditionToMomentMap_Script(t *testing.T) { - script, err := pds.Scripts.ReadFile("scripts/packNFT/balance_packNFT.cdc") - if err != nil { - t.Fatal(err) - } - t.Log(string(script)) - dddd := NewReplacer() - aaa, err := dddd.ReplaceAddresses(string(script), struct { - NonFungibleToken string - }{ - "0x1", - }) - if err != nil { - t.Fatal(err) - } - t.Log(aaa) -}