Skip to content

Commit

Permalink
update script & transaction go template generation
Browse files Browse the repository at this point in the history
  • Loading branch information
sisyphusSmiling committed Feb 13, 2024
1 parent 6cbefcd commit a329aea
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
18 changes: 9 additions & 9 deletions lib/go/templates/script_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,45 @@ const (

func GenerateGetAllStagedContractCodeForAddressScript(migrationContractStagingAddress flow.Address) []byte {
code := assets.MustAssetString(filenameGetAllStagedContractCodeForAddress)
return replaceAddresses(code, migrationContractStagingAddress)
return replaceMigrationContractStagingImports(code, migrationContractStagingAddress)
}

func GenerateGetAllStagedContractHostsScript(migrationContractStagingAddress flow.Address) []byte {
code := assets.MustAssetString(filenameGetAllStagedContractHosts)
return replaceAddresses(code, migrationContractStagingAddress)
return replaceMigrationContractStagingImports(code, migrationContractStagingAddress)
}

func GenerateGetAllStagedContractsScript(migrationContractStagingAddress flow.Address) []byte {
code := assets.MustAssetString(filenameGetAllStagedContracts)
return replaceAddresses(code, migrationContractStagingAddress)
return replaceMigrationContractStagingImports(code, migrationContractStagingAddress)
}

func GenerateGetStagedContractCodeScript(migrationContractStagingAddress flow.Address) []byte {
code := assets.MustAssetString(filenameGetStagedContractCode)
return replaceAddresses(code, migrationContractStagingAddress)
return replaceMigrationContractStagingImports(code, migrationContractStagingAddress)
}

func GenerateGetStagedContractNamesForAddressScript(migrationContractStagingAddress flow.Address) []byte {
code := assets.MustAssetString(filenameGetStagedContractNamesForAddress)
return replaceAddresses(code, migrationContractStagingAddress)
return replaceMigrationContractStagingImports(code, migrationContractStagingAddress)
}

func GenerateGetStagedContractUpdateScript(migrationContractStagingAddress flow.Address) []byte {
code := assets.MustAssetString(filenameGetStagedContractUpdate)
return replaceAddresses(code, migrationContractStagingAddress)
return replaceMigrationContractStagingImports(code, migrationContractStagingAddress)
}

func GenerateGetStagingCutoffScript(migrationContractStagingAddress flow.Address) []byte {
code := assets.MustAssetString(filenameGetStagingCutoff)
return replaceAddresses(code, migrationContractStagingAddress)
return replaceMigrationContractStagingImports(code, migrationContractStagingAddress)
}

func GenerateIsStagedScript(migrationContractStagingAddress flow.Address) []byte {
code := assets.MustAssetString(filenameIsStaged)
return replaceAddresses(code, migrationContractStagingAddress)
return replaceMigrationContractStagingImports(code, migrationContractStagingAddress)
}

func GenerateIsValidatedScript(migrationContractStagingAddress flow.Address) []byte {
code := assets.MustAssetString(filenameIsValidated)
return replaceAddresses(code, migrationContractStagingAddress)
return replaceMigrationContractStagingImports(code, migrationContractStagingAddress)
}
7 changes: 4 additions & 3 deletions lib/go/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ package templates

import (
"fmt"
"regexp"

"github.com/onflow/flow-go-sdk"
)

//go:generate go run github.com/kevinburke/go-bindata/go-bindata -prefix ../../../ -o internal/assets/assets.go -pkg assets -nometadata -nomemcopy ../../../scripts/... ../../../transactions/...

var (
placeholderMigrationContractStagingString = "\"MigrationContractStaging\""
placeholderMigrationContractStaging = regexp.MustCompile(`"MigrationContractStaging"`)
)

func replaceAddresses(code string, migrationContractStagingAddress flow.Address) []byte {
code = placeholderMigrationContractStagingString.ReplaceAllString(code, "0x"+migrationContractStagingAddress.String())
func replaceMigrationContractStagingImports(code string, migrationContractStagingAddress flow.Address) []byte {
code = placeholderMigrationContractStaging.ReplaceAllString(code, "0x"+migrationContractStagingAddress.String())
return []byte(code)
}

Expand Down
8 changes: 4 additions & 4 deletions lib/go/templates/transaction_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ const (

func GenerateStageContractScript(migrationContractStagingAddress flow.Address) []byte {
code := assets.MustAssetString(filenameStageContract)
return replaceAddresses(code, migrationContractStagingAddress)
return replaceMigrationContractStagingImports(code, migrationContractStagingAddress)
}

func GenerateUnstageContractScript(migrationContractStagingAddress flow.Address) []byte {
code := assets.MustAssetString(filenameUnstageContract)
return replaceAddresses(code, migrationContractStagingAddress)
return replaceMigrationContractStagingImports(code, migrationContractStagingAddress)
}

func GenerateCommitMigrationResultsScript(migrationContractStagingAddress flow.Address) []byte {
code := assets.MustAssetString(filenameCommitMigrationResults)
return replaceAddresses(code, migrationContractStagingAddress)
return replaceMigrationContractStagingImports(code, migrationContractStagingAddress)
}

func GenerateSetStagingCutoffScript(migrationContractStagingAddress flow.Address) []byte {
code := assets.MustAssetString(filenameSetStagingCutoff)
return replaceAddresses(code, migrationContractStagingAddress)
return replaceMigrationContractStagingImports(code, migrationContractStagingAddress)
}

0 comments on commit a329aea

Please sign in to comment.