diff --git a/lib/go/templates/script_templates.go b/lib/go/templates/script_templates.go index 79cb785..f786a25 100644 --- a/lib/go/templates/script_templates.go +++ b/lib/go/templates/script_templates.go @@ -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) } diff --git a/lib/go/templates/templates.go b/lib/go/templates/templates.go index c4ef0ed..98ae272 100644 --- a/lib/go/templates/templates.go +++ b/lib/go/templates/templates.go @@ -2,6 +2,7 @@ package templates import ( "fmt" + "regexp" "github.com/onflow/flow-go-sdk" ) @@ -9,11 +10,11 @@ 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 ( - 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) } diff --git a/lib/go/templates/transaction_templates.go b/lib/go/templates/transaction_templates.go index ba9fc55..8f7a7b4 100644 --- a/lib/go/templates/transaction_templates.go +++ b/lib/go/templates/transaction_templates.go @@ -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) }