Skip to content

Commit

Permalink
add generic setup and transfer transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuahannan committed Feb 9, 2024
1 parent 86ee8c3 commit e3b2202
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 12 deletions.
46 changes: 46 additions & 0 deletions lib/go/templates/internal/assets/assets.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 21 additions & 6 deletions lib/go/templates/templates.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package templates

import (
"fmt"
"regexp"

"github.com/onflow/flow-go-sdk"
Expand All @@ -9,12 +10,14 @@ import (
//go:generate go run github.com/kevinburke/go-bindata/go-bindata -prefix ../../../ -o internal/assets/assets.go -pkg assets -nometadata -nomemcopy ../../../scripts/... ../../../transactions/...

var (
placeholderNonFungibleToken = regexp.MustCompile(`"NonFungibleToken"`)
placeholderExampleNFT = regexp.MustCompile(`"ExampleNFT"`)
placeholderMetadataViews = regexp.MustCompile(`"MetadataViews"`)
placeholderFungibleToken = regexp.MustCompile(`"FungibleToken"`)
placeholderViewResolver = regexp.MustCompile(`"ViewResolver"`)
placeholderFlowToken = regexp.MustCompile(`"FlowToken"`)
placeholderNonFungibleTokenString = "\"NonFungibleToken\""
placeholderNonFungibleToken = regexp.MustCompile(`"NonFungibleToken"`)
placeholderExampleNFT = regexp.MustCompile(`"ExampleNFT"`)
placeholderMetadataViews = regexp.MustCompile(`"MetadataViews"`)
placeholderMetadataViewsString = "\"MetadataViews\""
placeholderFungibleToken = regexp.MustCompile(`"FungibleToken"`)
placeholderViewResolver = regexp.MustCompile(`"ViewResolver"`)
placeholderFlowToken = regexp.MustCompile(`"FlowToken"`)
)

func replaceAddresses(code string, nftAddress, exampleNFTAddress, metadataAddress, ftAddress, viewResolverAddress flow.Address) []byte {
Expand All @@ -25,3 +28,15 @@ func replaceAddresses(code string, nftAddress, exampleNFTAddress, metadataAddres
code = placeholderViewResolver.ReplaceAllString(code, "0x"+viewResolverAddress.String())
return []byte(code)
}

func withHexPrefix(address string) string {
if address == "" {
return ""
}

if address[0:2] == "0x" {
return address
}

return fmt.Sprintf("0x%s", address)
}
Loading

0 comments on commit e3b2202

Please sign in to comment.