Skip to content

Commit

Permalink
added replacer
Browse files Browse the repository at this point in the history
  • Loading branch information
judezhu committed May 23, 2024
1 parent 9ddc421 commit 8988f94
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions common/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package common

import "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"
)

var replacer Replacer

func init() {
replacer = map[AddressName]*regexp.Regexp{
"placeholderNonFungibleToken": placeholderNonFungibleToken,
"placeholderExampleNFT": placeholderExampleNFT,
"placeholderMetadataViews": placeholderMetadataViews,
"placeholderFungibleToken": placeholderFungibleToken,
}
}

func (r Replacer) replaceAddresses(code string, addr map[AddressName]string) string {
for key, value := range addr {
code = r[key].ReplaceAllString(code, "0x"+value)
}
return code
}

0 comments on commit 8988f94

Please sign in to comment.